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>
#pragma GCC optimize(2)
using namespace std;
int rd() {
  int k = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
  return k;
}
const int N = 300000, M = 600001;
int T, x, y, f[M], sx[M], sy[M];
long long ans;
vector<pair<int, int> > v[M << 1];
map<pair<int, int>, int> mp;
pair<int, int> p;
int F(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
void Add(int x, int l, int r, int s, int t, pair<int, int> p) {
  if (s <= l && r <= t) {
    v[x].push_back(p);
    return;
  }
  if (s <= ((l + r) >> 1)) Add((x << 1), l, ((l + r) >> 1), s, t, p);
  if (((l + r) >> 1) < t) Add((x << 1 | 1), ((l + r) >> 1) + 1, r, s, t, p);
}
void Solve(int x, int l, int r) {
  long long pre = ans;
  stack<int> S;
  for (int i = 0; i < v[x].size(); ++i) {
    int a = F(v[x][i].first), b = F(v[x][i].second + N);
    if (a == b) continue;
    if (sx[a] + sy[a] > sx[b] + sy[b]) {
      int t = a;
      a = b, b = t;
    }
    ans -= (long long)sx[a] * sy[a] + (long long)sx[b] * sy[b],
        f[a] = b, sx[b] += sx[a], sy[b] += sy[a];
    ans += (long long)sx[b] * sy[b], S.push(a);
  }
  if (l == r)
    printf("%lld ", ans);
  else
    Solve((x << 1), l, ((l + r) >> 1)),
        Solve((x << 1 | 1), ((l + r) >> 1) + 1, r);
  while (!S.empty()) {
    int t = S.top(), z = f[t];
    S.pop(), f[t] = t, sx[z] -= sx[t], sy[z] -= sy[t];
  }
  ans = pre;
}
int main() {
  T = rd();
  for (int i = 1; i <= T; ++i) {
    x = rd(), y = rd(), p = make_pair(x, y);
    if (mp.count(p))
      Add(1, 1, T, mp[p], i - 1, p), mp.erase(p);
    else
      mp[p] = i;
  }
  for (auto t : mp) Add(1, 1, T, t.second, T, t.first);
  for (int i = 1; i <= N; ++i) sx[f[i] = i] = 1;
  for (int i = N + 1; i < M; ++i) sy[f[i] = i] = 1;
  Solve(1, 1, T);
  return 0;
}