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>
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
using namespace std;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 300000 + 5;
int pre[maxn << 1], siz[maxn << 1], xcnt[maxn << 1], ycnt[maxn << 1];
int find(int x) {
  while (x != pre[x]) x = pre[x];
  return x;
}
long long sum = 0;
vector<pair<int, int> > sta;
bool join(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return 0;
  sum -= 1ll * xcnt[x] * ycnt[x];
  sum -= 1ll * xcnt[y] * ycnt[y];
  if (siz[x] > siz[y]) swap(x, y);
  pre[x] = y;
  siz[y] += siz[x];
  xcnt[y] += xcnt[x];
  ycnt[y] += ycnt[x];
  sum += 1ll * xcnt[y] * ycnt[y];
  sta.push_back({x, y});
  return 1;
}
void undo() {
  pair<int, int> tp = sta.back();
  sta.pop_back();
  int x = tp.first, y = tp.second;
  pre[x] = x;
  siz[y] -= siz[x];
  sum -= 1ll * xcnt[y] * ycnt[y];
  xcnt[y] -= xcnt[x];
  ycnt[y] -= ycnt[x];
  sum += 1ll * xcnt[x] * ycnt[x];
  sum += 1ll * xcnt[y] * ycnt[y];
}
vector<pair<int, int> > nodes[maxn << 2];
void update(int L, int R, pair<int, int> x, int l, int r, int rt) {
  if (L <= l && r <= R) {
    nodes[rt].push_back(x);
    return;
  }
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, x, l, m, rt << 1);
  if (R > m) update(L, R, x, m + 1, r, rt << 1 | 1);
}
long long ans[maxn];
void solve(int l, int r, int rt) {
  int cnt = 0;
  for (auto& x : nodes[rt])
    if (join(x.first, x.second)) cnt++;
  if (l == r) {
    ans[l] = sum;
    for (int i = 0; i < cnt; i++) undo();
    return;
  }
  int m = (l + r) >> 1;
  solve(l, m, rt << 1);
  solve(m + 1, r, rt << 1 | 1);
  for (int i = 0; i < cnt; i++) undo();
}
int n, x[maxn], y[maxn];
map<pair<int, int>, int> mp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++) {
    pre[i] = i;
    siz[i] = 1;
    xcnt[i] = (i <= n);
    ycnt[i] = (i > n);
  }
  vector<int> xx, yy;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", x + i, y + i);
    xx.push_back(x[i]);
    yy.push_back(y[i]);
  }
  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());
  xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
  yy.resize(unique(yy.begin(), yy.end()) - yy.begin());
  for (int i = 1; i <= n; i++) {
    x[i] = lower_bound(xx.begin(), xx.end(), x[i]) - xx.begin() + 1;
    y[i] = lower_bound(yy.begin(), yy.end(), y[i]) - yy.begin() + 1 + n;
  }
  for (int i = 1; i <= n; i++) {
    if (!mp.count({x[i], y[i]}) || mp[{x[i], y[i]}] <= 0)
      mp[{x[i], y[i]}] = i;
    else {
      update(mp[{x[i], y[i]}], i - 1, {x[i], y[i]}, 1, n, 1);
      mp[{x[i], y[i]}] = -1;
    }
  }
  for (auto& x : mp)
    if (x.second > 0) update(x.second, n, x.first, 1, n, 1);
  solve(1, n, 1);
  for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
  return 0;
}