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 inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 3e5 + 100;
map<pair<int, int>, int> mp;
vector<pair<int, int> > vc[N << 2];
pair<int, int> t;
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 m = l + r >> 1;
  if (L <= m) Insert(L, R, e, l, m, rt << 1);
  if (m < R) Insert(L, R, e, m + 1, r, rt << 1 | 1);
}
long long ans[N], now, cntx[N << 1], cnty[N << 1], fa[N << 1], sz[N << 1];
int Find(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
void Merge(int x, int y, stack<pair<int, int> > &st) {
  x = Find(x);
  y = Find(y);
  if (x == y) return;
  if (sz[x] > sz[y]) swap(x, y);
  st.push(pair<int, int>(x, y));
  sz[y] += sz[x];
  fa[x] = y;
  now -= cntx[x] * cnty[x];
  now -= cntx[y] * cnty[y];
  cntx[y] += cntx[x];
  cnty[y] += cnty[x];
  now += cntx[y] * cnty[y];
}
void Delete(stack<pair<int, int> > &st) {
  while (!st.empty()) {
    int u = st.top().first;
    int o = st.top().second;
    st.pop();
    fa[u] = u;
    sz[o] -= sz[u];
    now -= cntx[o] * cnty[o];
    cntx[o] -= cntx[u];
    cnty[o] -= cnty[u];
    now += cntx[u] * cnty[u];
    now += cntx[o] * cnty[o];
  }
}
void dfs(int l, int r, int rt) {
  stack<pair<int, int> > st;
  for (pair<int, int> &t : vc[rt]) Merge(t.first, t.second, st);
  if (l == r)
    ans[l] = now;
  else {
    int m = l + r >> 1;
    dfs(l, m, rt << 1);
    dfs(m + 1, r, rt << 1 | 1);
  }
  Delete(st);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &t.first, &t.second);
    t.second += 3e5;
    if (mp.count(t)) {
      Insert(mp[t], i - 1, t, 1, n, 1);
      mp.erase(t);
    } else
      mp[t] = i;
  }
  for (auto &t : mp) 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%c", ans[i], " \n"[i == n]);
  }
  return 0;
}