Problem: For a given set of two-dimensional points S, let's denote its extension E(S) as the result of the following algorithm:

Create another set of two-dimensional points R, which is initially equal to S. Then, while there exist four numbers x_1, y_1, x_2 and y_2 such that (x_1, y_1) ∈ R, (x_1, y_2) ∈ R, (x_2, y_1) ∈ R and (x_2, y_2) ∉ R, add (x_2, y_2) to R. When it is impossible to find such four integers, let R be the result of the algorithm.

Now for the problem itself. You are given a set of two-dimensional points S, which is initially empty. You have to process two types of queries: add some point to S, or remove some point from it. After each query you have to compute the size of E(S).

Input

The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries.

Then q lines follow, each containing two integers x_i, y_i (1 ≤ x_i, y_i ≤ 3 ⋅ 10^5), denoting i-th query as follows: if (x_i, y_i) ∈ S, erase it from S, otherwise insert (x_i, y_i) into S.

Output

Print q integers. i-th integer should be equal to the size of E(S) after processing first i queries.

Example

Input


7
1 1
1 2
2 1
2 2
1 2
1 3
2 1


Output


1 2 4 4 4 6 3 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int X = 0;
  register char ch = 0;
  while (ch < 48 || ch > 57) ch = getchar();
  while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();
  return X;
}
int n, m;
struct Point {
  int l, r, x, y;
} b[600500];
int tn;
map<pair<int, int>, int> mmp;
int f[600500], xc[600500], yc[600500];
struct Data {
  int x, y;
} stk[600500];
int top;
long long ans;
int findf(int x) { return f[x] == x ? x : findf(f[x]); }
void marge(int x, int y) {
  x = findf(x);
  y = findf(y);
  if (x == y) return;
  ans -= 1ll * xc[x] * yc[x] + 1ll * xc[y] * yc[y];
  if (xc[x] + yc[x] > xc[y] + yc[y]) swap(x, y);
  stk[++top] = (Data){x, y};
  f[x] = y;
  xc[y] += xc[x];
  yc[y] += yc[x];
  ans += 1ll * xc[y] * yc[y];
}
void undo(int x, int y) {
  f[x] = x;
  xc[y] -= xc[x];
  yc[y] -= yc[x];
}
vector<int> s[600500 << 1];
void solve(int l, int r, int num) {
  long long sav = ans;
  int tim = top;
  Point *v;
  for (int i = 0; i < s[num].size(); i++) {
    v = &b[s[num][i]];
    if (v->l <= l && r <= v->r) marge(v->x, v->y);
  }
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = (l + r) >> 1;
    for (int i = 0; i < s[num].size(); i++) {
      v = &b[s[num][i]];
      if (!(v->l <= l && r <= v->r)) {
        if (v->l <= mid) s[num << 1].push_back(s[num][i]);
        if (v->r > mid) s[num << 1 | 1].push_back(s[num][i]);
      }
    }
    s[num].clear();
    solve(l, mid, num << 1);
    solve(mid + 1, r, num << 1 | 1);
  }
  while (tim < top) {
    undo(stk[top].x, stk[top].y);
    top--;
  }
  ans = sav;
}
int main() {
  m = read();
  n = 300005;
  pair<int, int> sav;
  for (int i = 1, x, y; i <= m; i++) {
    x = read();
    y = read() + n;
    sav = make_pair(x, y);
    if (mmp[sav]) {
      b[mmp[sav]].r = i - 1;
      mmp[sav] = 0;
    } else
      b[mmp[sav] = ++tn] = (Point){i, 0, x, y};
  }
  for (int i = 1; i <= tn; i++) {
    if (b[i].r == 0) b[i].r = m;
    s[1].push_back(i);
  }
  for (int i = 1; i <= n + n; i++) {
    f[i] = i;
    xc[i] = (i <= n);
    yc[i] = !xc[i];
  }
  solve(1, m, 1);
  return 0;
}