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 = 3e5 + 1000;
map<pair<int, int>, int> lst;
long long tmpans;
struct dsu {
  int fa[2 * maxn], size[2 * maxn], rowsize[2 * maxn], colsize[2 * maxn];
  pair<int, int> his[maxn];
  int top;
  dsu() {
    top = 0;
    for (int i = (0), iend = (maxn * 2 - 1); i <= iend; i++)
      fa[i] = i, size[i] = 1;
    for (int i = (1), iend = (maxn); i <= iend; i++)
      rowsize[i] = 1, colsize[i + maxn] = 1;
  }
  int get(int x) { return (fa[x] == x) ? x : get(fa[x]); }
  void merge(int s, int f) {
    s = get(s), f = get(f);
    if (size[s] > size[f]) swap(s, f);
    tmpans -= 1ll * rowsize[f] * colsize[f] + 1ll * rowsize[s] * colsize[s];
    size[f] += size[s];
    rowsize[f] += rowsize[s];
    colsize[f] += colsize[s];
    tmpans += 1ll * rowsize[f] * colsize[f];
    fa[s] = f;
    his[++top] = make_pair(s, f);
  }
  void roll_back(int n) {
    for (int i = (1), iend = (n); i <= iend; i++) {
      int f = his[top].second, s = his[top].first;
      top--;
      tmpans -= 1ll * rowsize[f] * colsize[f];
      size[f] -= size[s];
      rowsize[f] -= rowsize[s];
      colsize[f] -= colsize[s];
      tmpans += 1ll * rowsize[f] * colsize[f] + 1ll * rowsize[s] * colsize[s];
      fa[s] = s;
    }
  }
} d;
long long ans[maxn];
struct segment_tree {
  vector<pair<int, int> > tag[maxn << 2];
  void add_op(int l, int r, int rt, int tl, int tr, pair<int, int> val) {
    if (tl <= l && r <= tr) {
      tag[rt].push_back(val);
      return;
    }
    int mid = (l + r) >> 1;
    if (tl <= mid) add_op(l, mid, (rt << 1), tl, tr, val);
    if (tr >= mid + 1) add_op(mid + 1, r, (rt << 1 | 1), tl, tr, val);
  }
  void vamos(int l, int r, int rt) {
    int cnt = 0;
    for (int i = 0; i < tag[rt].size(); i++) {
      pair<int, int> tmp = tag[rt][i];
      if (d.get(tmp.first) != d.get(tmp.second + maxn)) {
        d.merge(tmp.first, tmp.second + maxn);
        cnt++;
      }
    }
    if (l == r) {
      ans[l] = tmpans;
      d.roll_back(cnt);
      return;
    }
    int mid = (l + r) >> 1;
    vamos(l, mid, (rt << 1));
    vamos(mid + 1, r, (rt << 1 | 1));
    d.roll_back(cnt);
    int gg = 1;
  }
} t;
vector<pair<int, int> > res;
int main() {
  ios::sync_with_stdio(0);
  int q;
  cin >> q;
  for (int i = (1), iend = (q); i <= iend; i++) {
    pair<int, int> tmp;
    cin >> tmp.first >> tmp.second;
    res.push_back(tmp);
    if (lst[tmp]) {
      t.add_op(1, q, 1, lst[tmp], i - 1, tmp);
      lst[tmp] = 0;
    } else {
      lst[tmp] = i;
    }
  }
  for (int i = 0; i < res.size(); i++) {
    pair<int, int> tmp = res[i];
    if (lst[tmp]) {
      t.add_op(1, q, 1, lst[tmp], q, tmp);
      lst[tmp] = 0;
    }
  }
  t.vamos(1, q, 1);
  for (int i = (1), iend = (q); i <= iend; i++) cout << ans[i] << ' ';
  return 0;
}