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 dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
  const int dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
            dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  const long long mod = 1000000007;
  const int base = 311;
  struct fenwick {
    vector<long long> fw;
    int n;
    void kc(int _n) {
      n = _n;
      fw.assign(n + 5, 0);
    }
    void upd(int i, int val) {
      i++;
      assert(i > 0);
      for (; i <= n; i += i & -i) fw[i] += val;
    }
    long long get(int i) {
      i++;
      if (i <= 0) return 0;
      assert(i > 0);
      long long ans = 0;
      for (; i > 0; i -= i & -i) ans += fw[i];
      return ans;
    }
    void upd_range(int l, int r, int val) {
      upd(l, val);
      upd(r + 1, -val);
    }
    long long get(int l, int r) { return get(r) - get(l - 1); }
  };
  const int N = 3e5 + 5;
  const int MAX = 6e5;
  int n;
  int a[N];
  void gogo() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    long long ans = 0;
    fenwick fw1, cnt1, fw2, cnt2;
    fw1.kc(MAX);
    cnt1.kc(MAX);
    fw2.kc(MAX);
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= 3e5; j += a[i]) {
        int l = j, r = j + a[i] - 1;
        ans += fw1.get(l, r) - cnt1.get(l, r) * j;
      }
      fw1.upd(a[i], a[i]);
      cnt1.upd(a[i], 1);
      ans += 1ll * a[i] * (i - 1) + fw2.get(a[i]);
      for (int j = 0; j <= 3e5; j += a[i]) {
        fw2.upd_range(j, j + a[i] - 1, -j);
      }
      cout << ans << ' ';
    }
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("sol"
              ".inp",
              "r")) {
      freopen(
          "sol"
          ".inp",
          "r", stdin);
      freopen(
          "sol"
          ".out",
          "w", stdout);
    }
    gogo();
  }
  