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 SZ = 6e5 + 10;
const int mod = 998244353;
const int INF = 1e9 + 10;
const long double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a <= '9' && a >= '0') {
    n = n * 10 + a - '0', a = getchar();
  }
  if (flag) n = -n;
  return n;
}
struct segment {
  int l, r;
  vector<pair<int, int> > v;
  vector<bool> b;
} tree[SZ * 4];
void build(int p, int l, int r) {
  tree[p].l = l;
  tree[p].r = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
}
void add(int p, int l, int r, pair<int, int> x) {
  if (l <= tree[p].l && tree[p].r <= r) {
    tree[p].v.push_back(x);
    return;
  }
  int mid = tree[p].l + tree[p].r >> 1;
  if (l <= mid) add(p << 1, l, r, x);
  if (mid < r) add(p << 1 | 1, l, r, x);
}
long long fa[SZ], sz[SZ][2];
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
long long get_sz(int x) { return sz[x][0] + sz[x][1]; }
long long get_ans(int x) { return sz[x][0] * sz[x][1]; }
stack<pair<int, int> > S;
long long ans = 0;
bool add(pair<int, int> v) {
  int x = find(v.first), y = find(v.second);
  if (x == y) return false;
  if (get_sz(x) < get_sz(y)) swap(x, y);
  ans -= get_ans(x);
  ans -= get_ans(y);
  fa[y] = x;
  sz[x][0] += sz[y][0];
  sz[x][1] += sz[y][1];
  ans += get_ans(x);
  S.push(make_pair(x, y));
  return true;
}
void del() {
  if (!S.size()) return;
  pair<int, int> p = S.top();
  S.pop();
  int x = p.first, y = p.second;
  ans -= get_ans(x);
  sz[x][0] -= sz[y][0];
  sz[x][1] -= sz[y][1];
  ans += get_ans(x);
  ans += get_ans(y);
  fa[x] = x;
  fa[y] = y;
}
long long Ans[SZ];
void dfs(int p) {
  tree[p].b.resize(tree[p].v.size());
  for (int i = 0; i < tree[p].v.size(); i++) tree[p].b[i] = add(tree[p].v[i]);
  if (tree[p].l == tree[p].r)
    Ans[tree[p].l] = ans;
  else
    dfs(p << 1), dfs(p << 1 | 1);
  for (int i = tree[p].v.size() - 1; i >= 0; i--)
    if (tree[p].b[i]) del();
}
pair<int, int> a[SZ];
map<pair<int, int>, int> mp;
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[i] = make_pair(x, y + 3e5);
  }
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    pair<int, int> p = a[i];
    if (mp.count(p))
      add(1, mp[p], i - 1, p), mp.erase(p);
    else
      mp[p] = i;
  }
  for (auto it = mp.begin(); it != mp.end(); it++)
    add(1, it->second, n, it->first);
  for (int i = 1; i <= 6e5; i++) fa[i] = i, sz[i][i <= 3e5] = 1;
  dfs(1);
  for (int i = 1; i <= n; i++) printf("%I64d ", Ans[i]);
  return 0;
}