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 N = 3e5 + 7;
int szx[N << 1], szy[N << 1], fa[N << 1];
long long ans = 0;
int Find(int x) { return x == fa[x] ? x : Find(fa[x]); }
void Union(int x, int y, stack<int> &S) {
  x = Find(x), y = Find(y);
  if (x == y) return;
  ans += szx[x] * szy[y] + szy[x] * szx[y];
  if (szx[x] + szy[x] < szx[y] + szy[y]) swap(x, y);
  fa[y] = x, szx[x] += szx[y], szy[x] += szy[y];
  S.push(y);
}
vector<pair<int, int> > E[N << 2];
void add(int rt, int l, int r, int L, int R, pair<int, int> y) {
  if (L <= l && r <= R) {
    E[rt].emplace_back(y);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= L) add(rt << 1, l, mid, L, R, y);
  if (mid < R) add(rt << 1 | 1, mid + 1, r, L, R, y);
}
void undo(stack<int> &S) {
  while (!S.empty()) {
    int x = S.top();
    S.pop();
    int y = fa[x];
    szx[y] -= szx[x], szy[y] -= szy[x];
    fa[x] = x;
  }
}
void work(int rt, int l, int r) {
  stack<int> S;
  long long temp = ans;
  for (pair<int, int> &e : E[rt]) Union(e.first, e.second + 300000, S);
  int mid = (l + r) >> 1;
  if (l == r)
    cout << ans << ' ';
  else
    work(rt << 1, l, mid), work(rt << 1 | 1, mid + 1, r);
  undo(S);
  ans = temp;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  map<pair<int, int>, int> mp;
  for (int i = 1; i <= 600000; i++) fa[i] = i;
  for (int i = 1; i <= 300000; i++) szx[i] = szy[i + 300000] = 1;
  int n;
  cin >> n;
  for (int i = 1, x, y; i <= n; i++) {
    cin >> x >> y;
    if (mp.count(pair<int, int>(x, y))) {
      add(1, 1, n, mp[pair<int, int>(x, y)], i - 1, pair<int, int>(x, y));
      mp.erase(pair<int, int>(x, y));
    } else
      mp[pair<int, int>(x, y)] = i;
  }
  for (auto &e : mp) add(1, 1, n, e.second, n, e.first);
  work(1, 1, n);
  return 0;
}