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;
  inline long long read() {
    char c = getchar();
    long long first = 0;
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
    for (; isdigit(c); c = getchar())
      first = (first << 1) + (first << 3) + (c ^ 48);
    if (f) first = -first;
    return first;
  }
  const long long M = 3e5 + 10;
  long long n, a[M];
  struct BIT {
    long long c[M];
    long long lowbit(long long first) { return first & (-first); }
    void add(long long k, long long first) {
      for (long long i = k; i < M; i += lowbit(i)) c[i] += first;
    }
    long long ask(long long first) {
      long long res = 0;
      for (long long i = first; i >= 1; i -= lowbit(i)) res += c[i];
      return res;
    }
    long long query(long long l, long long r) {
      return ask(min(r, M - 1)) - ask(l - 1);
    }
  } T1, T2;
  signed main() {
    n = read();
    long long res = 0, sum = 0;
    ;
    for (long long i = 1; i <= n; i++) a[i] = read();
    for (long long i = 1; i <= n; i++) {
      res += a[i] * (i - 1) - T2.ask(a[i]);
      long long s1 = 0;
      for (long long j = 1; j <= M / a[i] + 1; j++)
        s1 += (T1.query((j - 1) * a[i], a[i] * j - 1)) * (j - 1);
      res += sum - s1 * a[i];
      cout << res << ' ';
      sum += a[i];
      T1.add(a[i], 1);
      for (long long j = 2; j <= M / a[i] + 1; j++) T2.add((j - 1) * a[i], a[i]);
    }
    return 0;
  }
  