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;
int n, fa[600005], size1[600005], size2[600005], d[600005], top;
long long res;
map<pair<int, int>, int> mp;
vector<pair<int, int> > e[600005 << 1];
int find(int x) {
  while (x ^ fa[x]) x = fa[x];
  return x;
}
struct nade {
  int x, y, s1, s2, d;
  long long rs;
} st[600005];
void change(int x, int l, int r, int L, int R, pair<int, int> p) {
  if (l >= L && r <= R) {
    e[x].push_back(p);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= L) change(x << 1, l, mid, L, R, p);
  if (mid + 1 <= R) change(x << 1 | 1, mid + 1, r, L, R, p);
}
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (d[x] > d[y]) swap(x, y);
  st[++top] = nade{x, y, size1[y], size2[y], d[y], res};
  res -= 1ll * size1[x] * size2[x] + 1ll * size1[y] * size2[y];
  d[y] += d[x] == d[y];
  fa[x] = y;
  size1[y] += size1[x];
  size2[y] += size2[x];
  res += 1ll * size1[y] * size2[y];
}
void solve(int x, int l, int r) {
  int wh = top;
  for (auto i : e[x]) merge(i.first, i.second);
  if (l == r)
    printf("%lld ", res);
  else {
    int mid = (l + r) >> 1;
    solve(x << 1, l, mid);
    solve(x << 1 | 1, mid + 1, r);
  }
  while (top > wh) {
    int x = st[top].x, y = st[top].y;
    fa[x] = x;
    d[y] = st[top].d;
    size1[y] = st[top].s1;
    size2[y] = st[top].s2;
    res = st[top].rs;
    top--;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i <= n; i++) {
    scanf("%d%d", &u, &v);
    pair<int, int> p = pair<int, int>{u, v + 3e5};
    if (mp[p]) {
      change(1, 1, n, mp[p], i - 1, p);
      mp.erase(p);
    } else
      mp[p] = i;
  }
  for (int i = 1; i <= 6e5; i++) {
    fa[i] = i;
    if (i <= 3e5)
      size1[i] = 1;
    else
      size2[i] = 1;
  }
  for (auto i : mp) change(1, 1, n, i.second, n, i.first);
  solve(1, 1, n);
}