mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N = int(input()) A = list(map(int, input().split())) nxt = [[0] * N for _ in range(41)] for i in range(N): nxt[0][i] = A[i] for lv in range(1, 41): for i in range(N): tmp = nxt[lv-1][i] j = (i + tmp)%N nxt[lv][i] = tmp + nxt[lv-1][j] for _ in range(int(input())): k = int(input()) i = 0 ans = 0 for lv in range(41): if k >> lv & 1: tmp = nxt[lv][i] ans += tmp i = (i + tmp)%N print(ans) if __name__ == '__main__': main()