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 MAXV = 3e5;
  void add(vector<long long> &h, int idx, long long v) {
    for (; idx < (int)h.size(); idx |= (idx + 1)) h[idx] += v;
  }
  long long get(vector<long long> &h, int idx) {
    long long res = 0;
    if (idx >= (int)h.size()) idx = h.size() - 1;
    for (; idx >= 0; idx = (idx & (idx + 1)) - 1) res += h[idx];
    return res;
  }
  long long get(vector<long long> &h, int idx1, int idx2) {
    return get(h, idx2) - get(h, idx1);
  }
  void solve() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    long long res = 0;
    long long p = 0;
    vector<long long> h(MAXV + 1);
    vector<long long> c(MAXV + 1);
    vector<char> have(MAXV + 1);
    for (int i = 0; i < n; ++i) {
      long long res1 = 0;
      long long res2 = 0;
      int v = a[i];
      res2 += get(c, v, MAXV) * v;
      for (int j = 1; j < MAXV + 1; ++j) {
        int aa = v / (j + 1);
        int bb = v / j;
        if (aa + 3 > bb) {
          for (int j = bb; j >= 0; --j)
            if (have[j]) res2 += v % j;
          break;
        } else {
          long long c1 = get(c, aa, bb);
          long long h1 = get(h, aa, bb);
          res2 += v * c1 - h1 * j;
        }
      }
      long long res4 = 0;
      {
        int j = 0;
        for (int z = 0; z < MAXV + 1; z += v) {
          long long c1 = get(c, z - 1, z - 1 + v);
          long long h1 = get(h, z - 1, z - 1 + v);
          res4 += h1 - v * c1 * j;
          j += 1;
        }
      }
      res += res2;
      res += res4;
      add(c, v, 1);
      add(h, v, v);
      have[v] = 1;
      printf("%I64d ", res);
    }
  }
  int main() {
    solve();
    return 0;
  }
  