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;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
const int base = 300000;
const int maxn = 3e5 + 5;
const int maxs = maxn << 2;
int q;
int siz[maxs], fa[maxs];
pair<long long, long long> s[maxs];
map<pair<long long, long long>, int> mp;
vector<pair<long long, long long> > p[maxs], del;
long long tot;
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
void insert(int u, int l, int r, int ql, int qr, pair<long long, long long> q) {
  if (ql <= l && r <= qr) return (void)(p[u].push_back(q));
  int mid = l + r >> 1;
  if (ql <= mid) insert(u << 1, l, mid, ql, qr, q);
  if (qr > mid) insert(u << 1 | 1, mid + 1, r, ql, qr, q);
}
void query(int u, int l, int r) {
  int sz = p[u].size();
  int top = 0;
  for (int i = (0); i <= (sz - 1); ++i) {
    int x = find(p[u][i].first);
    int y = find(p[u][i].second);
    if (x == y) continue;
    if (siz[x] > siz[y]) swap(x, y);
    tot -= s[x].first * s[x].second;
    tot -= s[y].first * s[y].second;
    fa[x] = y;
    siz[y] += siz[x];
    s[y].first += s[x].first;
    s[y].second += s[x].second;
    tot += s[y].first * s[y].second;
    del.push_back(pair<long long, long long>(x, y));
    ++top;
  }
  if (l == r)
    printf("%lld ", tot);
  else {
    int mid = l + r >> 1;
    query(u << 1, l, mid);
    query(u << 1 | 1, mid + 1, r);
  }
  while (top--) {
    int x = del.back().first;
    int y = del.back().second;
    tot -= s[y].first * s[y].second;
    s[y].first -= s[x].first;
    s[y].second -= s[x].second;
    siz[y] -= siz[x];
    fa[x] = x;
    tot += s[y].first * s[y].second;
    tot += s[x].first * s[x].second;
    del.pop_back();
  }
}
void init() {
  for (int i = (1); i <= (base * 2); ++i) {
    fa[i] = i;
    siz[i] = 1;
    if (i <= base)
      s[i].first = 1;
    else
      s[i].second = 1;
  }
}
int main() {
  rd(q);
  init();
  for (int i = (1); i <= (q); ++i) {
    int x, y;
    rd(x), rd(y);
    pair<long long, long long> t = pair<long long, long long>(x, y + base);
    if (mp.find(t) != mp.end()) {
      insert(1, 1, q, mp[t], i - 1, t);
      mp.erase(t);
    } else
      mp[t] = i;
  }
  for (map<pair<long long, long long>, int>::iterator it = mp.begin();
       it != mp.end(); ++it) {
    insert(1, 1, q, it->second, q, it->first);
  }
  query(1, 1, q);
  return 0;
}