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;
  const int mxn = 3e5 + 5;
  const long long MOD = 1e9 + 7;
  const int BASE = 100000000;
  const int INF = 1e9 + 8;
  long long g[mxn], cnt[mxn], a[mxn];
  void up_g(int x, const long long &val) {
    while (x < mxn) {
      g[x] += val;
      x += x & (-x);
    }
  }
  void update_g(int l, int r, const long long &val) {
    up_g(l, val);
    up_g(r + 1, -val);
  }
  long long get_g(int x) {
    long long res = 0;
    while (x) {
      res += g[x];
      x -= x & (-x);
    }
    return res;
  }
  void update_cnt(int x) {
    while (x < mxn) {
      cnt[x] += 1LL;
      x += x & (-x);
    }
  }
  long long get(int x) {
    long long res = 0;
    while (x) {
      res += cnt[x];
      x -= x & (-x);
    }
    return res;
  }
  long long get_cnt(int l, int r) { return (get(r) - get(l - 1)); }
  signed main() {
    int n;
    cin >> n;
    for (int i = (1); i <= (n); ++i) cin >> a[i];
    long long cur = 0, sum = 0;
    for (int i = (1); i <= (n); ++i) {
      cur += (long long)(i - 1) * a[i] - get_g(a[i]);
      cur += sum;
      int x = (int)(a[i]);
      while (x < mxn) {
        long long k = min(x + (int)(a[i]) - 1, (int)(mxn - 5));
        cur -= (long long)(x)*get_cnt(x, k);
        update_g(x, k, x);
        x += a[i];
      }
      update_cnt(a[i]);
      sum += a[i];
      cout << cur << ' ';
    }
  }
  