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;
inline void open(const char *s) {}
inline int rd() {
  static int x, f;
  x = 0;
  f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return f > 0 ? x : -x;
}
const int N = 300010;
int m, rt;
long long ans = 0;
int ql[N], qr[N], tt = 0;
pair<int, int> a[N];
map<pair<int, int>, int> mp;
namespace UFS {
int fa[N << 1], siz[N << 1][2], st[N], top = 0;
inline int find(int x) {
  while (x ^ fa[x]) x = fa[x];
  return x;
}
inline long long link(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return 0;
  long long res = 1ll * siz[x][0] * siz[x][1] + 1ll * siz[y][0] * siz[y][1];
  if (siz[x][0] + siz[x][1] > siz[y][0] + siz[y][1]) swap(x, y);
  fa[st[++top] = x] = y;
  siz[y][0] += siz[x][0];
  siz[y][1] += siz[x][1];
  return 1ll * siz[y][0] * siz[y][1] - res;
}
inline long long del(int tt) {
  long long res = 0;
  while (tt--) {
    int x = st[top--], y = fa[x];
    res -= 1ll * siz[y][0] * siz[y][1];
    siz[y][0] -= siz[x][0];
    siz[y][1] -= siz[x][1];
    fa[x] = x;
    res += 1ll * siz[y][0] * siz[y][1];
    res += 1ll * siz[x][0] * siz[x][1];
  }
  return res;
}
}  // namespace UFS
namespace Seg {
struct tree {
  int ls, rs;
  vector<pair<int, int> > vec;
  tree() {
    ls = rs = 0;
    vec.clear();
  }
} tr[N << 1];
int cnt = 0;
void build(int &o, int l, int r) {
  o = ++cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(tr[o].ls, l, mid);
  build(tr[o].rs, mid + 1, r);
}
void insert(int o, int l, int r, int L, int R, pair<int, int> d) {
  if (l == L && r == R) return tr[o].vec.push_back(d), void();
  int mid = (l + r) >> 1;
  if (L <= mid) insert(tr[o].ls, l, mid, L, min(mid, R), d);
  if (R > mid) insert(tr[o].rs, mid + 1, r, max(mid + 1, L), R, d);
}
void solve(int o, int l, int r) {
  int tt = 0;
  for (auto hh : tr[o].vec) {
    long long x = UFS::link(hh.first, hh.second);
    if (x) ans += x, ++tt;
  }
  if (l != r) {
    int mid = (l + r) >> 1;
    solve(tr[o].ls, l, mid);
    solve(tr[o].rs, mid + 1, r);
  } else
    printf("%lld ", ans);
  ans += UFS::del(tt);
}
}  // namespace Seg
int main() {
  open("hh");
  m = rd();
  for (int i = 1; i <= 300000; i++) UFS::fa[i] = i, UFS::siz[i][0] = 1;
  for (int i = 300001; i <= 600000; i++) UFS::fa[i] = i, UFS::siz[i][1] = 1;
  for (int i = 1; i <= m; i++) {
    int x = rd(), y = rd();
    y += 300000;
    if (mp.count(pair<int, int>(x, y))) {
      qr[mp[pair<int, int>(x, y)]] = i - 1;
      mp.erase(pair<int, int>(x, y));
    } else
      ql[mp[pair<int, int>(x, y)] = ++tt] = i, a[tt] = pair<int, int>(x, y);
  }
  Seg::build(rt, 1, m);
  for (int i = 1; i <= tt; i++)
    if (!qr[i]) qr[i] = m;
  for (int i = 1; i <= tt; i++) Seg::insert(rt, 1, m, ql[i], qr[i], a[i]);
  Seg::solve(rt, 1, m);
  return 0;
}