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 long long N = 3e5;
  long long n, a[300005], ans, s;
  long long c1[300005], c2[300005];
  void fix1(long long x, long long v) {
    for (long long i = x; i <= N; i += (i & -i)) c1[i] += v;
  }
  long long ask1(long long x) {
    long long s = 0;
    for (long long i = x; i >= 1; i -= (i & -i)) s += c1[i];
    return s;
  }
  void fix2(long long x, long long v) {
    for (long long i = x; i <= N; i += (i & -i)) c2[i] += v;
  }
  long long ask2(long long x) {
    long long s = 0;
    for (long long i = x; i >= 1; i -= (i & -i)) s += c2[i];
    return s;
  }
  signed main() {
    cin >> n;
    for (long long i = 1; i <= n; cin >> a[i++])
      ;
    for (long long i = 1; i <= n; i++) {
      s += a[i];
      fix1(a[i], 1);
      ans = ans + s + (i - 1) * a[i] - ask2(a[i]);
      for (long long j = 1; j <= N / a[i]; j++) {
        ans -= a[i] * j * (ask1(min(N, a[i] * (j + 1) - 1)) - ask1(a[i] * j - 1));
        fix2(a[i] * j, a[i] * j), fix2(a[i] * (j + 1), -a[i] * j);
      }
      printf("%lld ", ans);
    }
    return puts(""), 0;
  }
  