#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const double PI = acos(-1);
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 3e5 + 7;
int n, m;
int a[N], p[N];
long long res;
template <typename T>
struct SegmentTree {
  int sz;
  T tr[N << 2], lazy[N << 2], cnt[N << 2];
  SegmentTree() {}
  void build(const int &n, const T &k = 0) {
    sz = n;
    _build(1, n, k);
  }
  void modify(const int &x, const T &k) { _modify(x, k, 1, sz); }
  void add(const int &x, const T &k) { _add(x, x, k, 1, sz); }
  void add(int l, int r, const T &k) {
    if (l > r) swap(l, r);
    _add(l, r, k, 1, sz);
  }
  void mark(const int &x) { mark(x, 1, sz, 1); }
  T query(const int &x) { return _query(x, x, 1, sz); }
  T query(int l, int r) {
    if (l > r) swap(l, r);
    return _query(l, r, 1, sz);
  }

 private:
  void mark(int x, int l, int r, int i = 1) {
    if (l == r) {
      ++cnt[i];
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      mark(x, l, mid, i << 1);
    else
      mark(x, mid + 1, r, i << 1 | 1);
    push_up(i);
  }
  void push_up(const int &i) {
    tr[i] = tr[i << 1] + tr[i << 1 | 1];
    cnt[i] = cnt[i << 1] + cnt[i << 1 | 1];
  }
  void push_down(const int &i, const int &len) {
    if (!lazy[i]) return;
    tr[i << 1] += lazy[i] * (len - len / 2);
    tr[i << 1 | 1] += lazy[i] * (len / 2);
    lazy[i << 1] += lazy[i];
    lazy[i << 1 | 1] += lazy[i];
    lazy[i] = 0;
  }
  void _build(const int &l, const int &r, const T &k = 0, const int &i = 1) {
    lazy[i] = 0;
    cnt[i] = 0;
    if (l == r) {
      tr[i] = k;
      return;
    }
    int mid = (l + r) >> 1;
    _build(l, mid, k, i << 1);
    _build(mid + 1, r, k, i << 1 | 1);
    push_up(i);
  }
  void _modify(const int &x, const T &k, const int &trl, const int &trr,
               const int &i = 1) {
    if (trl == x && trr == x) {
      tr[i] = k;
      lazy[i] = 0;
      return;
    }
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    if (x <= mid)
      _modify(x, k, trl, mid, i << 1);
    else
      _modify(x, k, mid + 1, trr, i << 1 | 1);
    push_up(i);
  }
  void _add(const int &l, const int &r, const T &k, const int &trl,
            const int &trr, const int &i = 1) {
    if (trl >= l && trr <= r) {
      tr[i] += k * (trr - trl + 1);
      lazy[i] += k;
      res -= k * cnt[i];
      return;
    }
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    if (l <= mid) _add(l, r, k, trl, mid, i << 1);
    if (r > mid) _add(l, r, k, mid + 1, trr, i << 1 | 1);
    push_up(i);
  }
  T _query(const int &l, const int &r, const int &trl, const int &trr,
           const int &i = 1) {
    if (trl >= l && trr <= r) return tr[i];
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    T res = 0;
    if (l <= mid) res += _query(l, r, trl, mid, i << 1);
    if (r > mid) res += _query(l, r, mid + 1, trr, i << 1 | 1);
    return res;
  }
};
SegmentTree<long long> tree;
inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    m = max(a[i], m);
  }
  tree.build(m);
  res = 0;
  long long presum = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = a[i]; j <= m; j += a[i]) {
      tree.add(j, min(m, j + a[i] - 1), j);
    }
    res += 1ll * i * a[i] + presum - tree.query(a[i]);
    presum += a[i];
    tree.mark(a[i]);
    cout << res << " \n"[i == n];
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

### Prompt

Create a solution in CPP for the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const double PI = acos(-1);
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 3e5 + 7;
int n, m;
int a[N], p[N];
long long res;
template <typename T>
struct SegmentTree {
  int sz;
  T tr[N << 2], lazy[N << 2], cnt[N << 2];
  SegmentTree() {}
  void build(const int &n, const T &k = 0) {
    sz = n;
    _build(1, n, k);
  }
  void modify(const int &x, const T &k) { _modify(x, k, 1, sz); }
  void add(const int &x, const T &k) { _add(x, x, k, 1, sz); }
  void add(int l, int r, const T &k) {
    if (l > r) swap(l, r);
    _add(l, r, k, 1, sz);
  }
  void mark(const int &x) { mark(x, 1, sz, 1); }
  T query(const int &x) { return _query(x, x, 1, sz); }
  T query(int l, int r) {
    if (l > r) swap(l, r);
    return _query(l, r, 1, sz);
  }

 private:
  void mark(int x, int l, int r, int i = 1) {
    if (l == r) {
      ++cnt[i];
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      mark(x, l, mid, i << 1);
    else
      mark(x, mid + 1, r, i << 1 | 1);
    push_up(i);
  }
  void push_up(const int &i) {
    tr[i] = tr[i << 1] + tr[i << 1 | 1];
    cnt[i] = cnt[i << 1] + cnt[i << 1 | 1];
  }
  void push_down(const int &i, const int &len) {
    if (!lazy[i]) return;
    tr[i << 1] += lazy[i] * (len - len / 2);
    tr[i << 1 | 1] += lazy[i] * (len / 2);
    lazy[i << 1] += lazy[i];
    lazy[i << 1 | 1] += lazy[i];
    lazy[i] = 0;
  }
  void _build(const int &l, const int &r, const T &k = 0, const int &i = 1) {
    lazy[i] = 0;
    cnt[i] = 0;
    if (l == r) {
      tr[i] = k;
      return;
    }
    int mid = (l + r) >> 1;
    _build(l, mid, k, i << 1);
    _build(mid + 1, r, k, i << 1 | 1);
    push_up(i);
  }
  void _modify(const int &x, const T &k, const int &trl, const int &trr,
               const int &i = 1) {
    if (trl == x && trr == x) {
      tr[i] = k;
      lazy[i] = 0;
      return;
    }
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    if (x <= mid)
      _modify(x, k, trl, mid, i << 1);
    else
      _modify(x, k, mid + 1, trr, i << 1 | 1);
    push_up(i);
  }
  void _add(const int &l, const int &r, const T &k, const int &trl,
            const int &trr, const int &i = 1) {
    if (trl >= l && trr <= r) {
      tr[i] += k * (trr - trl + 1);
      lazy[i] += k;
      res -= k * cnt[i];
      return;
    }
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    if (l <= mid) _add(l, r, k, trl, mid, i << 1);
    if (r > mid) _add(l, r, k, mid + 1, trr, i << 1 | 1);
    push_up(i);
  }
  T _query(const int &l, const int &r, const int &trl, const int &trr,
           const int &i = 1) {
    if (trl >= l && trr <= r) return tr[i];
    push_down(i, trr - trl + 1);
    int mid = (trl + trr) >> 1;
    T res = 0;
    if (l <= mid) res += _query(l, r, trl, mid, i << 1);
    if (r > mid) res += _query(l, r, mid + 1, trr, i << 1 | 1);
    return res;
  }
};
SegmentTree<long long> tree;
inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    m = max(a[i], m);
  }
  tree.build(m);
  res = 0;
  long long presum = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = a[i]; j <= m; j += a[i]) {
      tree.add(j, min(m, j + a[i] - 1), j);
    }
    res += 1ll * i * a[i] + presum - tree.query(a[i]);
    presum += a[i];
    tree.mark(a[i]);
    cout << res << " \n"[i == n];
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

```