n = int(input()) n_w = list(map(int, input().split())) n_a = list(map(int, input().split())) f = [0] * n for i in range(n): f[i] = n_w[i] for i in range(0, n): for j in range(0, i): if((i - j) % n_a[j]) == 0: f[i] = max(f[i], (f[j] + n_w[i])) max_w = max(f) print(m...