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 int read() {
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) f ^= c == '-', c = getchar();
    while (isdigit(c)) r = (r << 1) + (r << 3) + (c & 15), c = getchar();
    return f ? r : -r;
  }
  const int N = 2e5 + 7, M = 3e5 + 7;
  int n, m, a[N];
  struct b1t {
    long long c[M];
    inline void add(int p, int x) {
      for (; p <= m; p += ((p) & -(p))) c[p] += x;
    }
    inline long long ask(int p) {
      long long res = 0;
      for (; p; p -= ((p) & -(p))) res += c[p];
      return res;
    }
  } T1, T2;
  int main() {
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read(), m = max(m, a[i]);
    long long ans = 0, sum = 0;
    for (int j = 1; j <= n; j++) {
      int x = a[j];
      ans += sum + 1ll * (j - 1) * x - T2.ask(x), sum += x;
      for (int i = x; i <= m; i += x) ans -= x * (j - 1 - T1.ask(i - 1));
      T1.add(x, 1);
      for (int i = x; i <= m; i += x) T2.add(i, x);
      printf("%lld ", ans);
    }
    return 0;
  }
  