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 long long read() {
  long long x = 0, y = 0, c = getchar();
  while (!isdigit(c)) y = c, c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
  return y == '-' ? -x : x;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
long long s1 = 19260817, s2 = 23333333, s3 = 998244853, srd;
inline long long rd() { return srd = (srd * s1 + s2 + rand()) % s3; }
void file() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int n, cnt;
struct node {
  int x, y, l, r;
} a[300010];
map<pair<int, int>, int> m;
long long as[300010], nwas;
int f[600010], sz1[600010], sz2[600010];
inline int getf(int q) { return f[q] == q ? q : getf(f[q]); }
vector<pair<int, int> > t[1200010];
inline void ins(int q, int l, int r, node x) {
  if (l >= x.l && r <= x.r) {
    t[q].push_back(make_pair(x.x, x.y));
    return;
  }
  int mid = l + r >> 1;
  if (mid >= x.l) ins(q << 1, l, mid, x);
  if (mid < x.r) ins(q << 1 | 1, mid + 1, r, x);
}
int st[10000010][4], ft;
inline void wk(int q, int l, int r) {
  int ff = ft;
  for (int i = 0; i < t[q].size(); ++i) {
    int x = t[q][i].first, y = t[q][i].second + 300000;
    x = getf(x);
    y = getf(y);
    if (x == y) continue;
    if (sz1[x] + sz2[x] < sz1[y] + sz2[y]) swap(x, y);
    nwas += 1ll * sz1[x] * sz2[y] + 1ll * sz1[y] * sz2[x];
    st[++ft][0] = x;
    st[ft][1] = y;
    st[ft][2] = sz1[x];
    st[ft][3] = sz2[x];
    f[y] = x;
    sz1[x] += sz1[y];
    sz2[x] += sz2[y];
  }
  if (l == r)
    as[l] = nwas;
  else {
    int mid = l + r >> 1;
    wk(q << 1, l, mid);
    wk(q << 1 | 1, mid + 1, r);
  }
  while (ft != ff) {
    int x = st[ft][0], y = st[ft][1];
    sz1[x] = st[ft][2];
    sz2[x] = st[ft][3];
    f[y] = y;
    nwas -= 1ll * sz1[x] * sz2[y] + 1ll * sz1[y] * sz2[x];
    --ft;
  }
}
int main() {
  srand(time(0));
  rd();
  int i, j, x, y;
  n = read();
  for (i = 1; i <= n; ++i) {
    x = read();
    y = read();
    if (m.find(make_pair(x, y)) != m.end()) {
      a[m[make_pair(x, y)]].r = i - 1;
      m.erase(make_pair(x, y));
    } else {
      m[make_pair(x, y)] = ++cnt;
      a[cnt].x = x;
      a[cnt].y = y;
      a[cnt].l = i;
    }
  }
  for (i = 1; i <= cnt; ++i)
    if (!a[i].r) a[i].r = n;
  for (i = 1; i <= 600000; ++i) f[i] = i;
  for (i = 1; i <= 300000; ++i) sz1[i] = 1, sz2[i + 300000] = 1;
  for (i = 1; i <= cnt; ++i) ins(1, 1, n, a[i]);
  wk(1, 1, n);
  for (i = 1; i <= n; ++i) print(as[i]), putchar(' ');
  return 0;
}