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 q, n = 300000;
struct Edg {
  int x, y;
} a[600005], b[600005];
int c[600005], last[600005];
struct Option {
  int l, r, x, y;
} opt[600005];
bool operator<(Edg A, Edg B) {
  if (A.x == B.x) return A.y < B.y;
  return A.x < B.x;
}
bool operator==(Edg A, Edg B) { return (A.x == B.x && A.y == B.y); }
int fa[600005], sz1[600005], sz2[600005], size[600005];
int find(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
vector<pair<int, int> > ve[600005 << 2];
void add(int rt, int l, int r, int ql, int qr, pair<int, int> x) {
  if (ql <= l && r <= qr) {
    ve[rt].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) add(rt << 1, l, mid, ql, qr, x);
  if (qr > mid) add(rt << 1 | 1, mid + 1, r, ql, qr, x);
}
int s1[600005], s2[600005], top;
long long Ans[600005], res = 0;
void dfs(int rt, int l, int r) {
  if (l > r) return;
  int bot = top;
  for (int i = 0; i < ve[rt].size(); ++i) {
    int u = ve[rt][i].first, v = ve[rt][i].second;
    if (find(u) == find(v)) continue;
    u = find(u), v = find(v);
    if (size[u] < size[v]) swap(u, v);
    res -= 1ll * sz1[u] * sz2[u] + 1ll * sz1[v] * sz2[v];
    fa[v] = u;
    size[u] += size[v];
    sz1[u] += sz1[v], sz2[u] += sz2[v];
    s1[++top] = v;
    s2[top] = u;
    res += 1ll * sz1[u] * sz2[u];
  }
  if (l == r) {
    Ans[l] = res;
  }
  int mid = (l + r) >> 1;
  if (l != r) {
    dfs(rt << 1, l, mid);
    dfs(rt << 1 | 1, mid + 1, r);
  }
  while (top > bot) {
    int u = s1[top], v = s2[top];
    res -= 1ll * sz1[v] * sz2[v];
    fa[u] = u;
    size[v] -= size[u];
    sz1[v] -= sz1[u];
    sz2[v] -= sz2[u];
    res += 1ll * sz1[u] * sz2[u] + 1ll * sz1[v] * sz2[v];
    top--;
  }
}
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &a[i].x, &a[i].y);
    a[i].y += n;
    b[i] = a[i];
  }
  sort(a + 1, a + q + 1);
  int d = unique(a + 1, a + q + 1) - a - 1;
  for (int i = 1; i <= q; ++i) c[i] = lower_bound(a + 1, a + d + 1, b[i]) - a;
  int cnt = 0;
  for (int i = 1; i <= q; ++i) {
    if (!last[c[i]])
      last[c[i]] = i;
    else {
      ++cnt;
      opt[cnt].l = last[c[i]], opt[cnt].r = i - 1, opt[cnt].x = a[c[i]].x,
      opt[cnt].y = a[c[i]].y;
      last[c[i]] = 0;
    }
  }
  for (int i = 1; i <= d; ++i)
    if (last[i]) {
      ++cnt;
      opt[cnt].l = last[i], opt[cnt].r = q, opt[cnt].x = a[i].x,
      opt[cnt].y = a[i].y;
      last[i] = 0;
    }
  for (int i = 1; i <= cnt; ++i)
    add(1, 1, q, opt[i].l, opt[i].r, make_pair(opt[i].x, opt[i].y));
  for (int i = 1; i <= n; ++i) fa[i] = i, sz1[i] = 1, size[i] = 1;
  for (int i = 1; i <= n; ++i)
    fa[i + n] = i + n, sz2[i + n] = 1, size[i + n] = 1;
  dfs(1, 1, q);
  for (int i = 1; i <= q; ++i) printf("%I64d ", Ans[i]);
  return 0;
}
