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], siz1[600005], siz2[600005], height[600005];
struct node {
  int x, y, s1, s2, ds;
  long long rs;
} st[600005];
int tp;
long long res = 0;
map<pair<int, int>, int> mp;
vector<pair<int, int> > T[1200005];
inline int getf(int x) { return fa[x] == x ? x : getf(fa[x]); }
void merg(int x, int y) {
  x = getf(x), y = getf(y);
  if (x == y)
    return;
  else if (height[x] > height[y])
    swap(x, y);
  st[++tp] = (node){x, y, siz1[y], siz2[y], height[y], res},
  res -= 1ll * siz1[x] * siz2[x] + 1ll * siz1[y] * siz2[y];
  height[y] += height[x] == height[y], fa[x] = y, siz1[y] += siz1[x],
                                       siz2[y] += siz2[x],
                                       res += 1ll * siz1[y] * siz2[y];
}
void pop() {
  int x = st[tp].x;
  int y = st[tp].y;
  fa[x] = x;
  height[y] = st[tp].ds;
  siz1[y] = st[tp].s1;
  siz2[y] = st[tp].s2, res = st[tp].rs, tp--;
}
void back(int x) {
  while (tp > x) pop();
}
void modif(int x, int l, int r, int L, int R, pair<int, int> u) {
  if (l > R || L > r) return;
  if (L <= l && r <= R) {
    T[x].push_back(u);
    return;
  }
  modif(x << 1, l, (l + r) >> 1, L, R, u);
  modif(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, u);
}
void solve(int x, int l, int r) {
  int top = tp;
  for (int i = 0; i < (int)T[x].size(); i++) {
    int a = T[x][i].first;
    int b = T[x][i].second;
    merg(a, b);
  }
  if (l == r) {
    printf("%lld ", res);
    while (tp > top) pop();
    return;
  } else
    solve(x << 1, l, (l + r) >> 1), solve(x << 1 | 1, ((l + r) >> 1) + 1, r);
  while (tp > top) pop();
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y);
    pair<int, int> p = make_pair(x, y + 300000);
    if (mp[p])
      modif(1, 1, n, mp[p], i - 1, p), mp.erase(p);
    else
      mp[p] = i;
  }
  for (int i = 1; i <= 600000; i++)
    fa[i] = i, (i <= 300000 ? siz1[i] : siz2[i]) = 1;
  for (auto i : mp) modif(1, 1, n, i.second, n, i.first);
  solve(1, 1, n);
  return 0;
}