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;
long long Q, tt, ans, fa[300100 << 1], sz[300100 << 1];
pair<long long, long long> cnt[300100 << 1];
struct Node {
  long long ls, rs;
  vector<pair<long long, long long> > dn;
} node[300100 << 1];
map<pair<long long, long long>, long long> pos;
map<pair<long long, long long>, long long>::iterator it;
vector<pair<long long, long long> > gg;
long long ff(long long u) { return u == fa[u] ? u : ff(fa[u]); }
inline long long calc(long long u) { return cnt[u].first * cnt[u].second; }
pair<long long, long long> operator+(const pair<long long, long long> &u,
                                     const pair<long long, long long> &v) {
  return make_pair(u.first + v.first, u.second + v.second);
}
pair<long long, long long> operator-(const pair<long long, long long> &u,
                                     const pair<long long, long long> &v) {
  return make_pair(u.first - v.first, u.second - v.second);
}
void build(long long now, long long l, long long r) {
  if (l == r) return;
  long long mid = ((l + r) >> 1);
  node[now].ls = ++tt;
  build(tt, l, mid);
  node[now].rs = ++tt;
  build(tt, mid + 1, r);
}
void add(long long now, long long l, long long r, long long u, long long v,
         pair<long long, long long> w) {
  if (u <= l && r <= v) {
    node[now].dn.push_back(w);
    return;
  }
  long long mid = ((l + r) >> 1);
  if (u <= mid) add(node[now].ls, l, mid, u, v, w);
  if (mid < v) add(node[now].rs, mid + 1, r, u, v, w);
}
void dfs(long long now, long long l, long long r) {
  long long i, j, p, q, st = gg.size();
  for (i = 0; i < node[now].dn.size(); i++) {
    p = node[now].dn[i].first;
    q = node[now].dn[i].second;
    p = ff(p), q = ff(q);
    if (p == q) continue;
    if (sz[p] < sz[q]) swap(p, q);
    ans -= calc(p) + calc(q);
    sz[p] += sz[q];
    cnt[p] = cnt[p] + cnt[q];
    fa[q] = p;
    gg.push_back(make_pair(p, q));
    ans += calc(p);
  }
  if (l == r)
    printf("%lld ", ans);
  else {
    long long mid = ((l + r) >> 1);
    dfs(node[now].ls, l, mid);
    dfs(node[now].rs, mid + 1, r);
  }
  for (; gg.size() > st; gg.pop_back()) {
    p = gg.back().first;
    q = gg.back().second;
    ans -= calc(p);
    sz[p] -= sz[q];
    cnt[p] = cnt[p] - cnt[q];
    fa[q] = q;
    ans += calc(p) + calc(q);
  }
}
int main() {
  long long i, j;
  for (i = 1; i <= 300000; i++) fa[i] = i, cnt[i] = make_pair(1, 0), sz[i] = 1;
  for (i = 300000 + 1; i <= 300000 * 2; i++)
    fa[i] = i, cnt[i] = make_pair(0, 1), sz[i] = 1;
  cin >> Q;
  build(tt = 1, 1, Q);
  for (i = 1; i <= Q; i++) {
    pair<long long, long long> tmp;
    scanf("%lld%lld", &tmp.first, &tmp.second);
    tmp.second += 300000;
    if (pos.count(tmp))
      add(1, 1, Q, pos[tmp], i - 1, tmp), pos.erase(tmp);
    else
      pos[tmp] = i;
  }
  for (it = pos.begin(); it != pos.end(); it++)
    add(1, 1, Q, (*it).second, Q, (*it).first);
  dfs(1, 1, Q);
}