#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef string::const_iterator State; #define Ma_PI 3.141592653589793 #define eps 1e-5 #define LONG_INF 1e18 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007LL #define MOD 998244353LL #define seg_size 262144*4 #define REP(a,b) for(long long a = 0;a < b;++a) long long ans[1000000] = {}; long long encoding(long long a, long long b) { return -a * 1e6 + b; } pair decoding(long long now) { long long hoge = -now; //a * 1e6 - b long long tmp = hoge / 1e6; tmp++; return make_pair(tmp, tmp * 1e6 - hoge); } int main(){ iostream::sync_with_stdio(false); cin.tie(0); int n; cin >> n; set queries; vector A; REP(i, n) { long long b; cin >> b; A.push_back(b); } int query; cin >> query; int back; cin >> back; queries.insert(encoding(back, 1)); REP(i, query - 1) { int a; cin >> a; if (back > a) { back = a; queries.insert(encoding(back,i+2)); } } for (int i = 0; i < n; ++i) { ans[0] += A[i]; long long now = A[i]; while (true) { auto q = queries.lower_bound(-(now) * (1e6)); if (q == queries.end()) break; pair geko = decoding(*q); long long next = now % geko.first; ans[geko.second] -= now - next; now = next; } } for (int i = 1; i <= query; ++i) { ans[i] += ans[i - 1]; cout << ans[i] << endl; } }