using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ int M = 334; int P = 300; long[] A = new long[M * P]; for(int i=0;i=0;j--){ if(!Join[j]) break; if(j % P == P - 1 && pJoin[j / P]){ sum += pSum[j / P]; j -= P; } else { sum += A[j]; } } Console.WriteLine(sum); } break; } //Console.WriteLine("{0} : done",t); } } int N; int Q; long[] AA; int[][] Query; public Sol(){ var d = ria(); N = d[0]; Q = d[1]; AA = rla(); Query = new int[Q][]; for(int i=0;iint.Parse(e));} static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));} static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));} }