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;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (f) x = -x;
}
template <typename T>
inline void Mx(T &x, T y) {
  x < y && (x = y);
}
template <typename T>
inline void Mn(T &x, T y) {
  x > y && (x = y);
}
map<pair<int, int>, int> mp;
const int N = 300050;
int f[N << 1], X[N << 1], Y[N << 1], n;
long long c[N << 1][2], cnt;
vector<pair<int, int> > v[N << 2];
void change(int l, int r, int p, int L, int R, pair<int, int> x) {
  if (L <= l && r <= R) return v[p].push_back(x), void();
  int mid = (l + r) >> 1;
  if (mid >= L) change(l, mid, p << 1, L, R, x);
  if (mid < R) change(mid + 1, r, p << 1 | 1, L, R, x);
}
const int lim = 300000;
int find(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
void solve(int l, int r, int p, long long ans) {
  int t = cnt;
  for (auto t : v[p]) {
    int x = find(t.first), y = find(t.second + lim);
    if (x == y) continue;
    if (c[x][0] + c[x][1] < c[y][0] + c[y][1]) swap(x, y);
    X[++cnt] = x, Y[cnt] = y;
    ans -= c[x][0] * c[x][1] + c[y][0] * c[y][1];
    f[y] = x, c[x][0] += c[y][0], c[x][1] += c[y][1];
    ans += c[x][0] * c[x][1];
  }
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = (l + r) >> 1;
    solve(l, mid, p << 1, ans), solve(mid + 1, r, p << 1 | 1, ans);
  }
  while (cnt > t) {
    int x = X[cnt], y = Y[cnt];
    c[x][0] -= c[y][0], c[x][1] -= c[y][1];
    f[y] = y, cnt--;
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    read(x), read(y);
    if (mp[make_pair(x, y)])
      change(1, n, 1, mp[make_pair(x, y)], i - 1, make_pair(x, y)),
          mp[make_pair(x, y)] = 0;
    else
      mp[make_pair(x, y)] = i;
  }
  for (auto j : mp) {
    pair<int, int> px = j.first;
    int st = j.second;
    if (!st) continue;
    change(1, n, 1, st, n, px);
  }
  for (int i = 1; i <= 600000; i++) f[i] = i, c[i][i > lim] = 1;
  solve(1, n, 1, 0);
  return 0;
}