#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int n; cin >> n; vector a(n); ll sum = 0; priority_queue > que; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; que.push(a[i]); } int q; cin >> q; while (q--) { int x; cin >> x; while (x <= que.top()) { int v = que.top(); que.pop(); sum -= v; v %= x; que.push(v); sum += v; } cout << sum << endl; } return 0; }