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 = 6e5 + 10;
struct P1 {
  int x, fx, y, rky;
};
struct P {
  int x, y;
  bool operator<(P B) const {
    if (x != B.x) return x < B.x;
    return y < B.y;
  }
};
vector<P> v[N << 2];
map<P, int> mp;
long long ans[N], now = 0, szx[N], szy[N], rk[N], f[N];
int rt(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
void merg(int x, int y, stack<P1>& st) {
  x = rt(x);
  y = rt(y);
  if (x == y) return;
  if (rk[x] > rk[y]) swap(x, y);
  P1 t;
  t.x = x;
  t.fx = f[x];
  t.y = y;
  t.rky = rk[y];
  f[x] = y;
  if (rk[x] == rk[y]) rk[y]++;
  now -= szx[y] * szy[y];
  now -= szx[x] * szy[x];
  szx[y] += szx[x];
  szy[y] += szy[x];
  now += szx[y] * szy[y];
  st.push(t);
}
void del(stack<P1>& s) {
  while (!s.empty()) {
    P1 t = s.top();
    s.pop();
    int x = t.x, y = t.y;
    f[t.x] = t.fx;
    rk[t.y] = t.rky;
    now -= szx[y] * szy[y];
    szx[t.y] -= szx[t.x];
    szy[t.y] -= szy[t.x];
    now += szx[x] * szy[x] + szx[y] * szy[y];
  }
}
void up(int x, int l, int r, int L, int R, P z) {
  if (l >= L && r <= R) {
    v[x].push_back(z);
    return;
  }
  if (L <= (l + r) / 2) up(x << 1, l, (l + r) / 2, L, R, z);
  if (R > (l + r) / 2) up(x << 1 | 1, (l + r) / 2 + 1, r, L, R, z);
}
void dfs(int x, int l, int r) {
  stack<P1> s;
  for (P t : v[x]) {
    merg(t.x, t.y, s);
  }
  if (l == r)
    ans[l] = now;
  else {
    dfs(x << 1, l, (l + r) / 2);
    dfs(x << 1 | 1, (l + r) / 2 + 1, r);
  }
  del(s);
}
int main() {
  int n;
  P t;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &t.x, &t.y);
    t.y += 3e5;
    if (mp[t]) {
      up(1, 1, n, mp[t], i - 1, t);
      mp[t] = 0;
    } else
      mp[t] = i;
  }
  for (int i = 1; i <= 6e5; i++) {
    rk[i] = 1;
    f[i] = i;
    if (i <= 3e5)
      szx[i] = 1;
    else
      szy[i] = 1;
  }
  for (auto x : mp) {
    if (x.second) up(1, 1, n, x.second, n, x.first);
  }
  dfs(1, 1, n);
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%lld", ans[i]);
  }
  return 0;
}