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 N = 7e5 + 113;
  struct fenw {
    vector<long long> t;
    void init() { t.assign(N, 0); }
    long long getsum(int r) {
      long long result = 0;
      for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
      return result;
    }
    void inc(int i, long long delta) {
      for (; i < N; i = (i | (i + 1))) t[i] += delta;
    }
    long long sum_pos(int pos) {
      if (pos == 0) return getsum(pos);
      return getsum(pos);
    }
    void inc_segment(int l, int r, long long val) {
      inc(l, val);
      inc(r + 1, -val);
    }
    long long sum_segment(int l, int r) { return getsum(r) - getsum(l - 1); }
  };
  signed main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    fenw f1, f2, f3;
    f1.init(), f2.init(), f3.init();
    long long res = 0;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      long long pr = 0;
      res += f3.sum_pos(a) + (long long)a * i;
      for (int j = a - 1; j < N; j += a) {
        res += f1.sum_segment(j - a + 1, j) - f2.sum_segment(j - a + 1, j) * pr;
        f3.inc_segment(j - a + 1, j, -pr);
        pr += a;
      }
      f1.inc(a, a);
      f2.inc(a, 1);
      cout << res << ' ';
    }
  }
  