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 inf = 1e9;
  const long long INF = 1e18;
  int n, sz = 600;
  long long a[200010];
  long long ans[200010];
  long long s, cnt;
  long long num[666];
  long long dp[666][666];
  struct BIT {
    long long tree[600010];
    BIT() { memset(tree, 0, sizeof(tree)); }
    void update(int i, int x) {
      while (i <= 600000) {
        tree[i] += x;
        i += i & -i;
      }
    }
    long long sum(int i) {
      long long ret = 0;
      while (i) {
        ret += tree[i];
        i -= i & -i;
      }
      return ret;
    }
  } t1, t2;
  int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (a[i] > sz) {
        ans[i] += t1.sum(a[i]) + cnt * a[i];
        ans[i] += s;
        for (int j = a[i]; j <= 300000; j += a[i]) {
          t1.update(j, -a[i]);
          ans[i] -= (j / a[i]) * (t2.sum(j + a[i] - 1) - t2.sum(j - 1)) * a[i];
        }
        cnt++;
        for (int j = 2; j <= sz; j++) {
          ans[i] += num[j] * (a[i] % j);
        }
      } else {
        for (int j = 1; j < a[i]; j++) {
          ans[i] += j * dp[a[i]][j];
        }
        for (int j = 2; j < a[i]; j++) {
          ans[i] += num[j] * (a[i] % j);
        }
        ans[i] += (i - t2.sum(a[i]) - 1) * a[i];
        num[a[i]]++;
      }
      s += a[i];
      t2.update(a[i], 1);
      for (int j = 2; j <= sz; j++) {
        dp[j][a[i] % j]++;
      }
    }
    for (int i = 1; i <= n; i++) {
      ans[i] += ans[i - 1];
      cout << ans[i] << " ";
    }
  }
  