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 = 300010;
map<pair<int, int>, int> mp;
struct point {
  int first, second;
  int l, r;
  point() {}
  point(int first, int second, int l, int r)
      : first(first), second(second), l(l), r(r) {}
};
long long ans[N << 1];
long long sum;
int cnt;
int cx[N << 1], cy[N << 1];
int pre[N << 1];
int sz[N << 1];
int find(int first) {
  if (!pre[first]) return first;
  return find(pre[first]);
}
struct store {
  int first;
  int cx, cy;
  int sz;
  int pre;
  store() {}
  store(int first, int cx, int cy, int sz, int pre)
      : first(first), cx(cx), cy(cy), sz(sz), pre(pre) {}
};
stack<store> stk;
void recovery(store a) {
  sz[a.first] = a.sz;
  cx[a.first] = a.cx;
  cy[a.first] = a.cy;
  pre[a.first] = a.pre;
  sum += 1LL * a.cx * a.cy;
}
void unions(int first, int second) {
  first = find(first);
  second = find(second);
  if (first == second) return;
  if (sz[first] > sz[second]) swap(first, second);
  cnt += 2;
  stk.push(store(first, cx[first], cy[first], sz[first], pre[first]));
  stk.push(store(second, cx[second], cy[second], sz[second], pre[second]));
  sum -= 1LL * cx[first] * cy[first];
  sum -= 1LL * cx[second] * cy[second];
  sz[second] += sz[first];
  cx[second] += cx[first];
  cy[second] += cy[first];
  sz[second] += sz[first];
  pre[first] = second;
  sum += 1LL * cx[second] * cy[second];
}
void rollback() {
  cnt -= 2;
  store second = stk.top();
  stk.pop();
  store first = stk.top();
  stk.pop();
  sum -= 1LL * cx[second.first] * cy[second.first];
  recovery(second);
  recovery(first);
}
void solve(int l, int r, vector<point> &v) {
  if (l == r) {
    int tmp = cnt;
    for (int i = 0; i < v.size(); i++) {
      int first = v[i].first, second = v[i].second;
      unions(first, second);
    }
    ans[l] = sum;
    while (cnt > tmp) rollback();
    return;
  }
  int tmp = cnt;
  vector<point> vl, vr;
  int mid = (l + r) >> 1;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].l == l && v[i].r == r) {
      int first = v[i].first, second = v[i].second;
      unions(first, second);
    } else if (v[i].r <= mid)
      vl.push_back(v[i]);
    else if (v[i].l > mid)
      vr.push_back(v[i]);
    else {
      vl.push_back(point(v[i].first, v[i].second, v[i].l, mid));
      vr.push_back(point(v[i].first, v[i].second, mid + 1, v[i].r));
    }
  }
  solve(l, mid, vl);
  solve(mid + 1, r, vr);
  while (cnt > tmp) {
    rollback();
  }
}
int main() {
  ios::sync_with_stdio(false);
  vector<point> v;
  int n;
  cin >> n;
  for (int i = 1; i <= 300000; i++) {
    cx[i] = 1;
    cy[i + 300000] = 1;
  }
  for (int i = 1; i <= 600000; i++) sz[i] = 1;
  for (int i = 1; i <= n; i++) {
    int first, second;
    cin >> first >> second;
    second += 300000;
    if (mp.count(make_pair(first, second))) {
      int st = mp[make_pair(first, second)];
      int ed = i - 1;
      v.push_back(point(first, second, st, ed));
      mp.erase(make_pair(first, second));
    } else {
      mp[make_pair(first, second)] = i;
    }
  }
  for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();
       it++) {
    int first = it->first.first;
    int second = it->first.second;
    int st = it->second;
    int ed = n;
    v.push_back(point(first, second, st, ed));
  }
  solve(1, n, v);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}