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 
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int f[N << 1], s[2][N << 1];
vector<pair<int, int>> vec[N << 2];
int find(int x) { return x == f[x] ? x : find(f[x]); }
stack<pair<int, int>> S;
long long ans;
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (s[0][x] + s[1][x] > s[0][y] + s[1][y]) swap(x, y);
  S.push({x, y});
  ans -= 1ll * s[0][x] * s[1][x] + 1ll * s[0][y] * s[1][y];
  f[x] = y;
  s[0][y] += s[0][x], s[1][y] += s[1][x];
  ans += 1ll * s[0][y] * s[1][y];
}
void undo(int x, int y) {
  ans -= 1ll * s[0][y] * s[1][y];
  s[0][y] -= s[0][x], s[1][y] -= s[1][x];
  ans += 1ll * s[0][x] * s[1][x] + 1ll * s[0][y] * s[1][y];
  f[x] = x;
}
void solve(int p, int l, int r) {
  int now = S.size();
  for (auto o : vec[p]) merge(o.first, o.second);
  int mid = (l + r) >> 1;
  if (l == r)
    cout << ans << " ";
  else
    solve(p << 1, l, mid), solve(p << 1 | 1, mid + 1, r);
  while (S.size() > now) {
    int u = S.top().first, v = S.top().second;
    S.pop();
    undo(u, v);
  }
}
void upt(int p, int l, int r, int ql, int qr, int x, int y) {
  if (ql <= l && r <= qr) return (void)(vec[p].push_back({x, y}));
  int mid = (l + r) >> 1;
  if (ql <= mid) upt(p << 1, l, mid, ql, qr, x, y);
  if (mid < qr) upt(p << 1 | 1, mid + 1, r, ql, qr, x, y);
}
int x[N], y[N], c[N << 1], tot;
map<pair<int, int>, int> mp;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    y[i] += 3e5;
  }
  for (int i = 1; i <= n; ++i) {
    if (mp[{x[i], y[i]}])
      upt(1, 1, n, mp[{x[i], y[i]}], i - 1, x[i], y[i]), mp[{x[i], y[i]}] = 0;
    else
      mp[{x[i], y[i]}] = i;
  }
  for (int i = 1; i <= 300000; ++i) f[i] = i, s[0][i] = 1;
  for (int i = 300001; i <= 600000; ++i) f[i] = i, s[1][i] = 1;
  for (int i = 1; i <= n; ++i)
    if (mp[{x[i], y[i]}])
      upt(1, 1, n, mp[{x[i], y[i]}], n, x[i], y[i]), mp[{x[i], y[i]}] = 0;
  solve(1, 1, n);
}
