Suppose you are given a sequence S of k pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_k, b_k).

You can perform the following operations on it:

  1. Choose some position i and increase a_i by 1. That can be performed only if there exists at least one such position j that i ≠ j and a_i = a_j. The cost of this operation is b_i; 
  2. Choose some position i and decrease a_i by 1. That can be performed only if there exists at least one such position j that a_i = a_j + 1. The cost of this operation is -b_i. 



Each operation can be performed arbitrary number of times (possibly zero).

Let f(S) be minimum possible x such that there exists a sequence of operations with total cost x, after which all a_i from S are pairwise distinct. 

Now for the task itself ...

You are given a sequence P consisting of n pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n). All b_i are pairwise distinct. Let P_i be the sequence consisting of the first i pairs of P. Your task is to calculate the values of f(P_1), f(P_2), ..., f(P_n).

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of pairs in sequence P.

Next n lines contain the elements of P: i-th of the next n lines contains two integers a_i and b_i (1 ≤ a_i ≤ 2 ⋅ 10^5, 1 ≤ b_i ≤ n). It is guaranteed that all values of b_i are pairwise distinct.

Output

Print n integers — the i-th number should be equal to f(P_i).

Examples

Input

5
1 1
3 3
5 5
4 2
2 4


Output

0
0
0
-5
-16


Input

4
2 4
2 3
2 2
1 1


Output

0
3
7
1
#include <bits/stdc++.h>
long long ans, sum[4000005];
int son[4000005][2], cnt, root[400005], s[4000005], f[400005], n, r[400005];
void update(int k) {
  sum[k] += sum[son[k][0]] + sum[son[k][1]];
  s[k] += s[son[k][0]] + s[son[k][1]];
  return;
}
void insert(int &k, int l, int r, int x) {
  if (!k) k = ++cnt;
  if (l == r) return sum[k] = l, void(s[k] = 1);
  int mid = l + r >> 1;
  if (x <= mid)
    insert(son[k][0], l, mid, x);
  else
    insert(son[k][1], mid + 1, r, x);
  return update(k);
}
void merge(int &x, int y) {
  if (!x) return void(x = y);
  ans -= sum[son[x][0]] * s[son[x][1]] + sum[son[y][0]] * s[son[y][1]];
  if (son[y][0]) merge(son[x][0], son[y][0]);
  if (son[y][1]) merge(son[x][1], son[y][1]);
  return ans += sum[son[x][0]] * s[son[x][1]], s[x] += s[y],
         void(sum[x] += sum[y]);
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void solve(int x, int y) {
  x = find(x), y = find(y), f[y] = x;
  ans -= sum[root[x]] * x + sum[root[y]] * y;
  merge(root[x], root[y]);
  ans += sum[root[x]] * x;
  return void(r[x] = r[y]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 400000; i++) f[i] = r[i] = i;
  for (int a, b, i = 1; i <= n; i++) {
    scanf("%d%d", &a, &b);
    int p = root[a] ? r[find(a)] + 1 : a;
    ans -= 1ll * a * b;
    insert(root[p], 1, n, b);
    ans += 1ll * p * b;
    if (root[p - 1]) solve(p - 1, p);
    if (root[p + 1]) solve(p, p + 1);
    printf("%lld\n", ans);
  }
  return 0;
}
