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 MAXN = 3e5 + 7, mod = 4e5;
int n;
int dsu[MAXN * 4];
long long siz[MAXN * 4], nowans;
long long save[MAXN * 4][9], cnts;
int find(int A) { return dsu[A] == A ? A : find(dsu[A]); }
int getsiz(int A) { return siz[A] % mod + siz[A] / mod; }
void add_point(int x, int y) {
  int u1 = find(x), v1 = find(6e5 + y);
  int u2 = find(3e5 + y), v2 = find(9e5 + x);
  if (u1 != v1) {
    ++cnts;
    save[cnts][8] = nowans;
    nowans -= (siz[v1] % mod) * (siz[v1] / mod);
    nowans -= (siz[v2] % mod) * (siz[v2] / mod);
    if (getsiz(u1) > getsiz(v1)) swap(u1, v1);
    if (getsiz(u2) > getsiz(v2)) swap(u2, v2);
    save[cnts][0] = u1;
    save[cnts][1] = v1;
    save[cnts][2] = dsu[u1];
    save[cnts][3] = siz[v1];
    save[cnts][4] = u2;
    save[cnts][5] = v2;
    save[cnts][6] = dsu[u2];
    save[cnts][7] = siz[v2];
    dsu[u1] = v1;
    siz[v1] += siz[u1];
    dsu[u2] = v2;
    siz[v2] += siz[u2];
    nowans += (siz[v1] % mod) * (siz[v2] % mod);
  }
}
void del_point() {
  dsu[save[cnts][0]] = save[cnts][2];
  siz[save[cnts][1]] = save[cnts][3];
  dsu[save[cnts][4]] = save[cnts][6];
  siz[save[cnts][5]] = save[cnts][7];
  nowans = save[cnts][8];
  --cnts;
}
pair<int, int> dots[MAXN];
map<pair<int, int>, int> Map;
long long ans[MAXN];
vector<int> change[MAXN * 6];
void add(int L, int R, int X, int l = 1, int r = n, int now = 1) {
  if (L > r || R < l || L > R) return;
  if (L <= l && R >= r) {
    change[now].push_back(X);
    return;
  }
  int mid = (l + r) >> 1;
  add(L, R, X, l, mid, now << 1);
  add(L, R, X, mid + 1, r, now << 1 | 1);
}
void dfs(int l = 1, int r = n, int now = 1) {
  int in = cnts;
  for (auto i : change[now]) add_point(dots[i].first, dots[i].second);
  if (l == r)
    ans[l] = nowans;
  else {
    int mid = (l + r) >> 1;
    dfs(l, mid, now << 1);
    dfs(mid + 1, r, now << 1 | 1);
  }
  while (cnts != in) del_point();
}
int main() {
  for (int i = 1; i <= 6e5; i++) siz[i] = 1;
  for (int i = 1; i <= 6e5; i++) siz[600000 + i] = mod;
  for (int i = 1; i <= 1.2e6; i++) dsu[i] = i;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> dots[i].first >> dots[i].second;
    if (Map.find(dots[i]) != Map.end()) {
      add(Map[dots[i]], i - 1, Map[dots[i]]);
      Map.erase(dots[i]);
    } else
      Map[dots[i]] = i;
  }
  for (auto i : Map) add(i.second, n, i.second);
  dfs();
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}