#include #include #include using namespace std; typedef long long LL; const int N = 100010; LL ans; int n, a[N], q; multiset ms; int main() { // freopen("remainder.in", "r", stdin); // freopen("remainder.out", "w", stdout); // clock_t bg = clock(); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); ans += a[i]; ms.insert(a[i]); } scanf("%d", &q); while (q--) { int x; scanf("%d", &x); auto l = ms.lower_bound(x); for (auto it = l; it != ms.end(); ) { int num = *it; ans -= num - (num % x); it = ms.erase(it); num %= x; ms.insert(num); } printf("%lld\n", ans); } // clock_t ed = clock(); // printf("%.3lf\n", 1.0 * (ed - bg) / CLOCKS_PER_SEC); return 0; }