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 maxn = 300010;
const int Base = 300000;
vector<pair<int, int> > tr[maxn * 4];
map<pair<int, int>, int> mp;
map<pair<int, int>, int>::iterator it;
long long res[maxn], cnt_x[maxn * 2], cnt_y[maxn * 2], sz[maxn * 2];
int f[maxn * 2];
long long ans;
pair<int, int> a[maxn];
int get(int x) {
  if (x == f[x]) return x;
  return get(f[x]);
}
void add(int o, int l, int r, int ql, int qr, pair<int, int> val) {
  if (l >= ql && r <= qr) {
    tr[o].push_back(val);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) add((o << 1), l, mid, ql, qr, val);
  if (qr > mid) add((o << 1 | 1), mid + 1, r, ql, qr, val);
}
void del(int x, int y) {
  int x1 = get(x), y1 = get(y);
  if (x1 != y1) return;
  ans -= cnt_x[x] * cnt_y[x];
  cnt_x[x] -= cnt_x[y], cnt_y[x] -= cnt_y[y];
  sz[x] -= sz[y];
  ans += cnt_x[x] * cnt_y[x];
  ans += cnt_x[y] * cnt_y[y];
  f[y] = y;
}
pair<int, int> merge(int x, int y) {
  int x1 = get(x), y1 = get(y);
  if (x1 == y1) return make_pair(-1, -1);
  if (sz[x1] < sz[y1]) swap(x1, y1);
  ans -= cnt_x[x1] * cnt_y[x1];
  ans -= cnt_x[y1] * cnt_y[y1];
  sz[x1] += sz[y1];
  cnt_x[x1] += cnt_x[y1], cnt_y[x1] += cnt_y[y1];
  ans += cnt_x[x1] * cnt_y[x1];
  f[y1] = x1;
  return make_pair(x1, y1);
}
void dfs(int o, int l, int r) {
  if (l == 12) {
    l++;
    l--;
  }
  stack<pair<int, int> > s;
  for (auto x : tr[o]) {
    pair<int, int> tmp = merge(x.first, x.second);
    if (tmp.first != -1) s.push(tmp);
  }
  if (l == r)
    res[l] = ans;
  else {
    int mid = (l + r) >> 1;
    dfs((o << 1), l, mid);
    dfs((o << 1 | 1), mid + 1, r);
  }
  while (!s.empty()) {
    del(s.top().first, s.top().second);
    s.pop();
  }
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    y += Base;
    a[i] = make_pair(x, y);
    if (mp.find(a[i]) == mp.end())
      mp[a[i]] = i;
    else {
      add(1, 1, n, mp[a[i]], i - 1, a[i]);
      mp.erase(a[i]);
    }
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    add(1, 1, n, it->second, n, it->first);
  }
  for (int i = 1; i <= Base; i++) {
    f[i] = i, cnt_x[i] = 1, cnt_y[i] = 0, sz[i] = 1;
  }
  for (int i = Base + 1; i <= Base * 2; i++) {
    f[i] = i, cnt_x[i] = 0, cnt_y[i] = 1, sz[i] = 1;
  }
  dfs(1, 1, n);
  for (int i = 1; i <= n; i++) printf("%lld ", res[i]);
}