using System; using System.Collections.Generic; using System.Linq; namespace Problem1097 { class Program { static void Main(string[] args) { int N = GetInt(); var A = GetIntArray(); int Q = GetInt(); var K = new long[Q]; for(int i = 0; i < Q; i++) { K[i] = GetLong(); } int j = 1; var X = new List { 0 }; var XHash = new HashSet { 0 }; int cycle = 0; int ba = 0; long measure = 0; while(true) { int r = (int)X[j - 1] % N; long temp = X[j - 1] + A[r]; long tempmod = temp % N; if(XHash.Contains(tempmod)) { ba = X.FindIndex(x => x % N == tempmod); cycle = j - ba; measure = (int)(temp - X[ba]); break; } else { X.Add(temp); XHash.Add(tempmod); j++; } } for(int i = 0; i < Q; i++) { long laps = Math.Max((K[i] - ba) / cycle, 0); int index = ba + (int)((K[i] - ba) % cycle); Console.WriteLine(X[index] + laps * measure); } } public static int GetInt() => int.Parse(Console.ReadLine()); public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static double GetDouble() => double.Parse(Console.ReadLine()); public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static long GetLong() => long.Parse(Console.ReadLine()); public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray(); } }