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;
int q, first, second, p[600005], h[600005];
long long a[600005], b[600005], ans;
map<pair<int, int>, int> m;
vector<pair<pair<int, int>, pair<int, int>>> s;
vector<pair<int, int>> sg[1200005], rb[1200005];
int par(int nod) {
  if (p[nod] == nod)
    return nod;
  else
    return par(p[nod]);
}
void Upd(int nod, int l, int r, int lt, int rt, int first, int second) {
  if (l > rt || r < lt) return;
  if (l >= lt && r <= rt) {
    sg[nod].push_back({first, second});
    return;
  }
  int mid = (l + r) / 2;
  Upd(2 * nod, l, mid, lt, rt, first, second);
  Upd(2 * nod + 1, mid + 1, r, lt, rt, first, second);
}
void Print(int nod, int l, int r) {
  for (pair<int, int> i : sg[nod]) {
    int first = par(i.first), second = par(i.second);
    if (first == second) continue;
    if (h[first] > h[second]) swap(first, second);
    p[first] = second;
    rb[nod].push_back({first, second});
    ans -= a[first] * b[first] + a[second] * b[second];
    a[second] += a[first];
    b[second] += b[first];
    ans += a[second] * b[second];
    if (h[first] == h[second]) h[second]++;
  }
  if (l == r) {
    cout << ans << ' ';
  } else {
    int mid = (l + r) / 2;
    Print(2 * nod, l, mid);
    Print(2 * nod + 1, mid + 1, r);
  }
  reverse(rb[nod].begin(), rb[nod].end());
  for (pair<int, int> i : rb[nod]) {
    int first = i.first, second = i.second;
    p[first] = first;
    if (h[first] == h[second] - 1) h[second]--;
    ans -= a[second] * b[second];
    a[second] -= a[first];
    b[second] -= b[first];
    ans += a[first] * b[first] + a[second] * b[second];
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  for (int i = 1; i <= 600000; i++) p[i] = i;
  for (int i = 1; i <= 300000; i++) a[i] = 1;
  for (int i = 300001; i <= 600000; i++) b[i] = 1;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> first >> second;
    if (m[{first, second}]) {
      s.push_back({{first, second}, {m[{first, second}], i}});
      m[{first, second}] = 0;
    } else {
      m[{first, second}] = i;
    }
  }
  for (pair<pair<int, int>, int> i : m) {
    if (i.second) s.push_back({i.first, {i.second, q + 1}});
  }
  for (pair<pair<int, int>, pair<int, int>> i : s) {
    Upd(1, 1, q, i.second.first, i.second.second - 1, i.first.first,
        300000 + i.first.second);
  }
  Print(1, 1, q);
}