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;
map<pair<int, int>, int> ocr;
map<pair<int, int>, int>::iterator it;
vector<pair<int, int> > v[4 * 300005];
long long ans[300005], now;
int sx[2 * 300000 + 5], sy[2 * 300000 + 5], p[2 * 300000 + 5];
int* where[3 * 300005];
int value[3 * 300005], cnt;
int q, x, y;
void add(int s, int l, int r, int ql, int qr, pair<int, int> p) {
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    v[s].push_back(p);
    return;
  }
  add(s * 2, l, (l + r) / 2, ql, qr, p);
  add(s * 2 + 1, (l + r) / 2 + 1, r, ql, qr, p);
}
int find(int x) {
  while (x != p[x]) x = p[x];
  return x;
}
void change(int& a, int b) {
  where[++cnt] = &a;
  value[cnt] = a;
  a = b;
}
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (sx[x] + sy[x] < sx[y] + sy[y]) swap(x, y);
  long long dec = (long long)sx[x] * sy[x] + (long long)sx[y] * sy[y];
  long long inc = (long long)(sx[x] + sx[y]) * (sy[x] + sy[y]);
  now = now - dec + inc;
  change(p[y], x);
  change(sx[x], sx[x] + sx[y]);
  change(sy[x], sy[x] + sy[y]);
}
void dfs(int s, int l, int r) {
  long long l_now = now;
  int l_top = cnt;
  int n = v[s].size();
  for (int i = 0; i < n; i++) merge(v[s][i].first, v[s][i].second + 300000);
  if (l == r)
    ans[l] = now;
  else
    dfs(s * 2, l, (l + r) / 2), dfs(s * 2 + 1, (l + r) / 2 + 1, r);
  while (cnt != l_top) *(where[cnt]) = value[cnt], cnt--;
  now = l_now;
}
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    pair<int, int> tmp = make_pair(x, y);
    if (ocr.count(tmp)) {
      add(1, 1, q, ocr[tmp], i - 1, tmp);
      ocr.erase(tmp);
    } else
      ocr[tmp] = i;
  }
  it = ocr.begin();
  while (it != ocr.end()) {
    add(1, 1, q, it->second, q, it->first);
    it++;
  }
  now = cnt = 0;
  for (int i = 1; i <= 300000; i++) {
    p[i] = i;
    p[i + 300000] = i + 300000;
    sx[i] = 1;
    sy[i + 300000] = 1;
  }
  dfs(1, 1, q);
  for (int i = 1; i <= q; i++) printf("%I64d\n", ans[i]);
  return 0;
}