description: You have an array a consisting of n distinct positive integers, numbered from 1 to n. Define p_k as $$$p_k = ∑_{1 ≤ i, j ≤ k} a_i mod a_j, where x \bmod y denotes the remainder when x is divided by y. You have to find and print p_1, p_2, \ldots, p_n$$$. 
  
  Input
  
  The first line contains n — the length of the array (2 ≤ n ≤ 2 ⋅ 10^5).
  
  The second line contains n space-separated distinct integers a_1, …, a_n (1 ≤ a_i ≤ 3 ⋅ 10^5, a_i ≠ a_j if i ≠ j). 
  
  Output
  
  Print n integers p_1, p_2, …, p_n. 
  
  Examples
  
  Input
  
  
  4
  6 2 7 3
  
  
  Output
  
  
  0 2 12 22
  
  
  Input
  
  
  3
  3 2 1
  
  
  Output
  
  
  0 3 5
solution: #include <bits/stdc++.h>
  using namespace std;
  using ll = long long;
  using ull = unsigned long long;
  using ld = long double;
  template <typename T1, typename T2>
  inline void chkmin(T1& x, const T2& y) {
    if (y < x) x = y;
  }
  template <typename T1, typename T2>
  inline void chkmax(T1& x, const T2& y) {
    if (x < y) x = y;
  }
  const ll N = 3e5 + 10;
  ll n;
  ll a[N];
  ll cnt[N];
  struct Fenwick {
    ll n;
    vector<ll> tree;
    Fenwick() {}
    Fenwick(ll _n) {
      n = _n;
      tree.assign(n, 0);
    }
    void upd(ll pos, ll val) {
      for (; pos < n; pos |= pos + 1) {
        tree[pos] += val;
      }
    }
    ll get(ll r) {
      ll ans = 0;
      for (; r >= 0; r = (r & (r + 1)) - 1) {
        ans += tree[r];
      }
      return ans;
    }
    ll get(ll l, ll r) {
      chkmax(l, 0);
      chkmin(r, n - 1);
      if (l > r) return 0;
      return get(r) - get(l - 1);
    }
  };
  struct Node {
    ll modSum;
    ll modAdd;
    ll sum;
    Node() : modSum(0), modAdd(0), sum(0) {}
    Node getVal(ll sz) const {
      Node ans;
      ans.sum = sum + modSum * sz + modAdd * ((ll)sz * (sz - 1) / 2);
      return ans;
    }
  };
  Node merge(const Node& a, const Node& b) {
    Node ans;
    ans.sum = a.sum + b.sum;
    return ans;
  }
  namespace SegmentTree {
  Node tree[4 * N];
  ll myTree[N];
  void init() {}
  void push(ll v, ll szL) {
    tree[v * 2].modSum += tree[v].modSum;
    tree[v * 2].modAdd += tree[v].modAdd;
    tree[v * 2 + 1].modSum += tree[v].modSum + tree[v].modAdd * szL;
    tree[v * 2 + 1].modAdd += tree[v].modAdd;
    tree[v].modSum = 0;
    tree[v].modAdd = 0;
  }
  ll upd(ll v, ll tl, ll tr, ll l, ll r, ll modSum) {
    if (tl >= r || tr <= l) return 0;
    if (tl >= l && tr <= r) {
      tree[v].modAdd++;
      tree[v].modSum += modSum;
      return tr - tl;
    }
    ll tm = (tl + tr) / 2;
    push(v, tm - tl);
    ll szL = upd(v * 2, tl, tm, l, r, modSum);
    szL += upd(v * 2 + 1, tm, tr, l, r, modSum + szL);
    tree[v] = merge(tree[v * 2].getVal(tm - tl), tree[v * 2 + 1].getVal(tr - tm));
    return szL;
  }
  void upd(ll l, ll r) {
    chkmax(l, 0);
    chkmin(r, N - 1);
    if (l > r) return;
    upd(1, 0, N, l, r + 1, 0);
  }
  ll get(ll v, ll tl, ll tr, ll pos) {
    if (tl >= pos + 1 || tr <= pos) return 0;
    if (tl == tr - 1) {
      return (tree[v].getVal(tr - tl)).sum;
    }
    ll tm = (tl + tr) / 2;
    push(v, tm - tl);
    ll ans = get(v * 2, tl, tm, pos) + get(v * 2 + 1, tm, tr, pos);
    tree[v] = merge(tree[v * 2].getVal(tm - tl), tree[v * 2 + 1].getVal(tr - tm));
    return ans;
  }
  ll get(ll pos) { return get(1, 0, N, pos); }
  };  // namespace SegmentTree
  signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout.precision(20), cout.setf(ios::fixed);
    Fenwick sum(N);
    Fenwick cnt(N);
    SegmentTree::init();
    cin >> n;
    for (ll i = 0; i < n; ++i) {
      cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
      ans += (ll)a[i] * cnt.get(a[i] + 1, N - 1);
      ans += sum.get(0, a[i] - 1);
      ans += SegmentTree::get(a[i]);
      for (ll l = a[i], step = 1; l < N; l += a[i], ++step) {
        ll r = l + a[i] - 1;
        chkmin(r, N - 1);
        ans += sum.get(l, r) - cnt.get(l, r) * a[i] * step;
      }
      cout << ans << ' ';
      cnt.upd(a[i], 1);
      sum.upd(a[i], a[i]);
      for (ll l = a[i]; l < N; l += a[i]) {
        SegmentTree::upd(l, l + a[i] - 1);
      }
    }
    cout << '\n';
    return 0;
  }
  