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 = 3E5;
  const int inf = 1 << 30;
  long long read() {
    long long a = 0;
    char b = 1, c;
    do
      if ((c = getchar()) == 45) b = -1;
    while (c < 48 || c > 57);
    do a = (a << 3) + (a << 1) + (c & 15);
    while ((c = getchar()) > 47 && c < 58);
    return a * b;
  }
  void write(long long x, char c) {
    if (x < 0) putchar(45), x = -x;
    char a[20], s = 0;
    do a[++s] = x % 10 | 48;
    while (x /= 10);
    do putchar(a[s]);
    while (--s);
    putchar(c);
  }
  int a[N + 1];
  long long b[N + 1];
  int aska(int x) {
    int res = 0;
    for (; x; x -= x & -x) res += a[x];
    return res;
  }
  long long askb(int x) {
    long long res = 0;
    for (; x; x -= x & -x) res += b[x];
    return res;
  }
  int main() {
    int n = read();
    long long ans = 0, s = 0;
    for (int i = 0; i < n; ++i) {
      int x = read();
      ans += s + x * 1LL * i - askb(x);
      for (int j = x; j <= N; j += x) {
        ans -= j * 1LL * (aska(min(j + x - 1, N)) - aska(j - 1));
        for (int k = j; k <= N; k += k & -k) b[k] += x;
      }
      write(ans, ' ');
      for (int j = x; j <= N; j += j & -j) ++a[j];
      s += x;
    }
  }
  