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;
const int N = 3e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
const double PI = acos(-1);
int n;
long long ans[N];
map<pair<int, int>, int> Map;
int fa[N << 1], cntx[N << 1], cnty[N << 1], sz[N << 1];
long long now = 0;
vector<pair<int, int> > vc[N << 2];
void Insert(int L, int R, pair<int, int> e, int l, int r, int rt) {
  if (l >= L && r <= R) {
    vc[rt].push_back(e);
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid) Insert(L, R, e, l, mid, rt << 1);
  if (R > mid) Insert(L, R, e, mid + 1, r, rt << 1 | 1);
}
int getRoot(int x) { return fa[x] == x ? x : getRoot(fa[x]); }
void Merge(int x, int y, stack<pair<int, int> >& stk) {
  int fax = getRoot(x);
  int fay = getRoot(y);
  if (fax != fay) {
    if (sz[fax] < sz[fay]) swap(fax, fay);
    stk.push(make_pair(fax, fay));
    now -= 1ll * cntx[fax] * cnty[fax];
    now -= 1ll * cntx[fay] * cnty[fay];
    sz[fax] += sz[fay];
    cntx[fax] += cntx[fay];
    cnty[fax] += cnty[fay];
    fa[fay] = fax;
    now += 1ll * cntx[fax] * cnty[fax];
  }
}
void Delete(stack<pair<int, int> >& stk) {
  while (!stk.empty()) {
    int fax = stk.top().first;
    int fay = stk.top().second;
    stk.pop();
    now -= 1ll * cntx[fax] * cnty[fax];
    sz[fax] -= sz[fay];
    cntx[fax] -= cntx[fay];
    cnty[fax] -= cnty[fay];
    fa[fay] = fay;
    now += 1ll * cntx[fax] * cnty[fax];
    now += 1ll * cntx[fay] * cnty[fay];
  }
}
void dfs(int l, int r, int rt) {
  stack<pair<int, int> > stk;
  for (auto& t : vc[rt]) Merge(t.first, t.second, stk);
  if (l == r)
    ans[l] = now;
  else {
    int mid = l + r >> 1;
    dfs(l, mid, rt << 1);
    dfs(mid + 1, r, rt << 1 | 1);
  }
  Delete(stk);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    pair<int, int> e;
    scanf("%d%d", &e.first, &e.second);
    e.second += 300000;
    if (Map.find(e) == Map.end()) {
      Map[e] = i;
    } else {
      Insert(Map[e], i - 1, e, 1, n, 1);
      Map.erase(e);
    }
  }
  for (auto& t : Map) Insert(t.second, n, t.first, 1, n, 1);
  for (int i = 1; i <= 300000; i++) fa[i] = i, cntx[i] = 1, sz[i] = 1;
  for (int i = 300001; i <= 600000; i++) fa[i] = i, cnty[i] = 1, sz[i] = 1;
  dfs(1, n, 1);
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
  puts("");
  return 0;
}