//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 #include #include using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //------------------------------------------ //------------------------------------------ int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; LL sum = accumulate(A.begin(), A.end(), 0LL); priority_queue Q(A.begin(), A.end()); int q; cin >> q; while (q--) { LL x; cin >> x; while (Q.top() >= x) { auto d = Q.top(); Q.pop(); sum -= d; d %= x; Q.push(d); sum += d; } cout << sum <