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;
struct {
  template <typename T>
  inline operator T() {
    T x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c)) (c == '-') && (f = -1), c = getchar();
    while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f * x;
  }
} gi;
const int N = 3e5 + 5;
map<pair<int, int>, int> mp;
vector<pair<int, int> > v[N << 2];
void update(int o, int l, int r, int L, int R, pair<int, int> t) {
  if (l > R || L > r) return;
  if (L <= l && r <= R) return v[o].push_back(t);
  int mid = (l + r) >> 1;
  update(o << 1, l, mid, L, R, t), update(o << 1 | 1, mid + 1, r, L, R, t);
}
int dfa[N << 1], ds1[N << 1], ds2[N << 1], dst[N << 1];
int find(int x) { return dfa[x] == x ? x : find(dfa[x]); }
long long now;
int n;
struct Node {
  int x, y, s1, s2, ds;
  long long now;
};
stack<Node> s;
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (dst[x] > dst[y]) swap(x, y);
  dfa[x] = y;
  s.push({x, y, ds1[y], ds2[y], dst[y], now});
  now -= 1ll * ds1[x] * ds2[x] + 1ll * ds1[y] * ds2[y];
  ds1[y] += ds1[x], ds2[y] += ds2[x];
  if (dst[y] == dst[x]) ++dst[y];
  now += 1ll * ds1[y] * ds2[y];
}
void cancel() {
  auto t = s.top();
  int x = t.x, y = t.y;
  ds1[y] = t.s1, ds2[y] = t.s2, dst[y] = t.ds;
  dfa[x] = x, now = t.now;
  s.pop();
}
void insert(int o, int l, int r, int L, int R, pair<int, int> t) {
  if (L <= l && r <= R) return v[o].push_back(t);
  int mid = (l + r) >> 1;
  if (L <= mid) insert(o << 1, l, mid, L, R, t);
  if (R > mid) insert(o << 1 | 1, mid + 1, r, L, R, t);
}
void solve(int o, int l, int r) {
  int st = s.size();
  for (auto t : v[o]) merge(t.first, t.second);
  if (l == r) printf("%lld ", now);
  int mid = (l + r) >> 1;
  if (l != r) solve(o << 1, l, mid), solve(o << 1 | 1, mid + 1, r);
  while (s.size() > st) cancel();
}
int main() {
  n = gi;
  for (int i = 1, x, y; i <= n; ++i) {
    x = gi, y = gi;
    y += 3e5;
    if (mp[{x, y}]) {
      insert(1, 1, n, mp[{x, y}], i - 1, {x, y});
      mp.erase({x, y});
    } else
      mp[{x, y}] = i;
  }
  for (int i = 1; i <= 3e5; ++i) dfa[i] = i, ds1[i] = 1;
  for (int i = 3e5 + 1; i <= 6e5; ++i) dfa[i] = i, ds2[i] = 1;
  for (auto i : mp) insert(1, 1, n, i.second, n, i.first);
  solve(1, 1, n);
  return 0;
}