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;
struct Dsu {
  int fa[600015];
  int siz[600015];
  long long cntx[600015];
  long long cnty[600015];
  long long cnt = 0;
  stack<pair<int, int> > ostack;
  void init() {
    cnt = 0;
    for (int i = 0; i < 600015; i++) fa[i] = i, siz[i] = 1;
    for (int i = 0; i < 300005; i++) cntx[i] = 1;
    for (int i = 300005 + 1; i < 600015; i++) cnty[i] = 1;
  }
  void rev_oper(int u, int v) {
    cnt -= cntx[v] * cnty[v];
    fa[u] = u;
    siz[v] -= siz[u];
    cntx[v] -= cntx[u];
    cnty[v] -= cnty[u];
    cnt += cntx[u] * cnty[u] + cntx[v] * cnty[v];
  }
  int find(int u) {
    while (fa[u] != u) u = fa[u];
    return u;
  }
  int same(int u, int v) { return find(u) == find(v); }
  int unin(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return 0;
    if (siz[u] > siz[v]) swap(u, v);
    cnt -= cntx[u] * cnty[u] + cntx[v] * cnty[v];
    fa[u] = v;
    siz[v] += siz[u];
    cntx[v] += cntx[u];
    cnty[v] += cnty[u];
    cnt += cntx[v] * cnty[v];
    ostack.push(make_pair(u, v));
    return 1;
  }
  void timeBack() {
    if (!ostack.empty()) {
      pair<int, int> p = ostack.top();
      ostack.pop();
      rev_oper(p.first, p.second);
    }
  }
};
map<pair<int, int>, int> mp;
Dsu dsu;
vector<pair<int, int> > tn[1048576];
void modify(int no, int l, int r, int lq, int rq, pair<int, int> val) {
  if (l >= lq && r <= rq) {
    tn[no].push_back(val);
    return;
  }
  if (l > rq || r < lq) return;
  int mid = (l + r) / 2;
  modify(no << 1, l, mid, lq, rq, val);
  modify((no << 1) + 1, mid + 1, r, lq, rq, val);
}
void process(int no, int l, int r) {
  int revCnt = 0;
  for (int i = 0; i < tn[no].size(); i++) {
    int u = tn[no][i].first;
    int v = tn[no][i].second;
    revCnt += dsu.unin(u, v);
  }
  if (l == r) {
    printf("%I64d ", dsu.cnt);
  } else {
    int mid = (l + r) / 2;
    process(no << 1, l, mid);
    process((no << 1) + 1, mid + 1, r);
  }
  for (int i = 0; i < revCnt; i++) {
    dsu.timeBack();
  }
}
int main() {
  int m;
  dsu.init();
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    v = v + 300005;
    pair<int, int> t = make_pair(u, v);
    if (mp[t] == 0) {
      mp[t] = i + 1;
    } else {
      modify(1, 1, m, mp[t], i, make_pair(u, v));
      mp[t] = 0;
    }
  }
  for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();
       it++) {
    if (it->second == 0) continue;
    int u = it->first.first;
    int v = it->first.second;
    modify(1, 1, m, it->second, m, make_pair(u, v));
  }
  process(1, 1, m);
  return 0;
}