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 
#include <bits/stdc++.h>
using namespace std;
int n, m, k, x[300039], y[300039], flag[300039], z, maxn;
long long now, ans;
struct ques {
  int x, y;
} tmp;
vector<ques> g[1200039];
map<long long, int> s;
inline void swap(int &x, int &y) { x ^= y ^= x ^= y; }
struct yyy {
  int x, y, flag;
};
struct dsu {
  int fa[600039], sx[600039], sy[600039], w[600039], sh;
  yyy st[600039], tmp;
  inline int find(int x) { return fa[x] == x ? x : find(fa[x]); }
  inline void merge(int x, int y) {
    int un = find(x), wn = find(y);
    if (un != wn) {
      if (w[un] < w[wn]) swap(un, wn);
      ans += (long long)sx[un] * sy[wn] + (long long)sx[wn] * sy[un];
      st[++sh] = (yyy){un, wn, w[un] == w[wn]};
      sx[un] += sx[wn];
      sy[un] += sy[wn];
      fa[wn] = un;
      w[un] += (w[un] == w[wn]);
    }
  }
  inline void del() {
    tmp = st[sh];
    sh--;
    fa[tmp.y] = tmp.y;
    w[tmp.x] -= tmp.flag;
    sx[tmp.x] -= sx[tmp.y];
    sy[tmp.x] -= sy[tmp.y];
    ans -= (long long)sx[tmp.x] * sy[tmp.y] + (long long)sx[tmp.y] * sy[tmp.x];
  }
} f;
inline void get(int x, int y, ques tmp, const int &l = 1, const int &r = n,
                const int &now = 1) {
  if (x <= l && r <= y) {
    g[now].push_back(tmp);
    return;
  }
  int m = l + r >> 1;
  if (x <= m) get(x, y, tmp, l, m, now << 1);
  if (y > m) get(x, y, tmp, m + 1, r, now << 1 | 1);
}
inline void find(const int &l = 1, const int &r = n, const int &now = 1) {
  int lasttop = f.sh, m;
  for (int i = 0; i < g[now].size(); i++)
    tmp = g[now][i], f.merge(tmp.x, tmp.y + maxn);
  if (l != r)
    m = l + r >> 1, find(l, m, now << 1), find(m + 1, r, now << 1 | 1);
  else
    printf("%lld ", ans);
  while (f.sh != lasttop) f.del();
}
int main() {
  register int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) flag[i] = n;
  for (i = 1; i <= n; i++)
    scanf("%d%d", &x[i], &y[i]),
        maxn = ((maxn) > (((x[i]) > (y[i]) ? (x[i]) : (y[i])))
                    ? (maxn)
                    : (((x[i]) > (y[i]) ? (x[i]) : (y[i]))));
  for (i = 1; i <= n; i++) {
    now = (long long)x[i] * maxn + y[i];
    if (s[now])
      flag[s[now]] = i - 1, s[now] = 0, flag[i] = 0;
    else
      s[now] = i;
  }
  for (i = 1; i <= 2 * maxn; i++) f.fa[i] = i, f.w[i] = 1;
  for (i = 1; i <= maxn; i++) f.sx[i] = f.sy[i + maxn] = 1;
  for (i = 1; i <= n; i++)
    if (flag[i]) get(i, flag[i], (ques){x[i], y[i]});
  find();
}
