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;
namespace Sakurajima_Mai {
const int infi = 2e9;
const long long infl = 4e18;
inline int qi() {
  int f = 0, fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + c - 48;
    c = getchar();
  }
  return f * fu;
}
inline long long ql() {
  long long f = 0;
  int fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + c - 48;
    c = getchar();
  }
  return f * fu;
}
inline double qd() {
  char c = getchar();
  int flag = 1;
  double ans = 0;
  while ((!(c >= '0' && c <= '9')) && c != '-') c = getchar();
  if (c == '-') flag = -1, c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + (c ^ 48), c = getchar();
  if (c == '.') {
    c = getchar();
    for (register int Bit = 10; c >= '0' && c <= '9';
         Bit = (Bit << 3) + (Bit << 1))
      ans += (double)(c ^ 48) * 1.0 / Bit, c = getchar();
  }
  return ans * flag;
}
inline long long ceil_div(long long a, long long b) { return (a + b - 1) / b; }
}  // namespace Sakurajima_Mai
using namespace Sakurajima_Mai;
const int MAX_N = 6e5 + 5;
long long ans = 0;
struct node {
  int x, y, rnk, sizx, sizy;
};
struct Union_Find {
  int fa[MAX_N], sizx[MAX_N], sizy[MAX_N], rnk[MAX_N];
  node s[MAX_N];
  int top;
  void init(int n) {
    for (register int i = 1, bbb = n; i <= bbb; ++i)
      fa[i] = i, rnk[i] = 1, sizx[i] = 1, sizy[i] = 0;
    for (register int i = n + 1, bbb = 2 * n; i <= bbb; ++i)
      fa[i] = i, rnk[i] = 1, sizx[i] = 0, sizy[i] = 1;
    top = 0;
  }
  int find(int x) { return fa[x] == x ? x : find(fa[x]); }
  void unit_2(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return;
    if (rnk[x] < rnk[y]) swap(x, y);
    fa[y] = x;
    ans -= 1ll * sizx[x] * sizy[x], ans -= 1ll * sizx[y] * sizy[y];
    s[++top] = node{x, y, rnk[x], sizx[x], sizy[x]};
    if (rnk[x] == rnk[y]) rnk[x]++;
    sizx[x] += sizx[y], sizy[x] += sizy[y];
    ans += 1ll * sizx[x] * sizy[x];
  }
  void cancel() {
    node now = s[top--];
    ans -= 1ll * sizx[now.x] * sizy[now.x];
    fa[now.y] = now.y, rnk[now.x] = now.rnk, sizx[now.x] = now.sizx,
    sizy[now.x] = now.sizy;
    ans += 1ll * sizx[now.x] * sizy[now.x],
        ans += 1ll * sizx[now.y] * sizy[now.y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
} uf;
pair<int, int> e[MAX_N];
vector<int> tr[MAX_N << 2];
void update(int k, int l, int r, int L, int R, int id) {
  if (R < l || r < L) return;
  if (L <= l && r <= R) {
    tr[k].push_back(id);
    return;
  }
  int mid = (l + r) >> 1;
  update(k << 1, l, mid, L, R, id), update(k << 1 | 1, mid + 1, r, L, R, id);
}
void solve(int k, int l, int r) {
  int cntop = 0;
  for (auto x : tr[k]) {
    int u = e[x].first, v = e[x].second + 300000;
    if (uf.same(u, v)) continue;
    uf.unit_2(u, v), cntop++;
  }
  if (l == r)
    printf("%lld\n", ans);
  else {
    int mid = (l + r) >> 1;
    solve(k << 1, l, mid), solve(k << 1 | 1, mid + 1, r);
  }
  while (cntop--) uf.cancel();
}
map<pair<int, int>, int> mp;
int main() {
  int q = qi();
  for (register int i = 1, bbb = q; i <= bbb; ++i) {
    e[i].first = qi(), e[i].second = qi();
    if (!mp[e[i]])
      mp[e[i]] = i;
    else
      update(1, 1, q, mp[e[i]], i - 1, i), mp.erase(e[i]);
  }
  for (auto x : mp) update(1, 1, q, x.second, q, x.second);
  uf.init(300000);
  solve(1, 1, q);
}