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>
namespace IOStream {
const int MAXR = 10000000;
char _READ_[MAXR], _PRINT_[MAXR];
int _READ_POS_, _PRINT_POS_, _READ_LEN_;
inline char readc() {
  if (!_READ_POS_) _READ_LEN_ = fread(_READ_, 1, MAXR, stdin);
  char c = _READ_[_READ_POS_++];
  if (_READ_POS_ == MAXR) _READ_POS_ = 0;
  if (_READ_POS_ > _READ_LEN_) return 0;
  return c;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  register int flag = 1, c;
  while (((c = readc()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    flag = -1;
  else
    x = c - '0';
  while ((c = readc()) >= '0' && c <= '9') x = x * 10 - '0' + c;
  x *= flag;
}
template <typename T1, typename... T2>
inline void read(T1 &a, T2 &...x) {
  read(a), read(x...);
}
inline int reads(char *s) {
  register int len = 0, c;
  while (isspace(c = readc()) || !c)
    ;
  s[len++] = c;
  while (!isspace(c = readc()) && c) s[len++] = c;
  s[len] = 0;
  return len;
}
inline void ioflush() {
  fwrite(_PRINT_, 1, _PRINT_POS_, stdout), _PRINT_POS_ = 0;
  fflush(stdout);
}
inline void printc(char c) {
  if (!c) return;
  _PRINT_[_PRINT_POS_++] = c;
  if (_PRINT_POS_ == MAXR) ioflush();
}
inline void prints(const char *s, char c) {
  for (int i = 0; s[i]; i++) printc(s[i]);
  printc(c);
}
template <typename T>
inline void print(T x, char c = '\n') {
  if (x < 0) printc('-'), x = -x;
  if (x) {
    static char sta[20];
    register int tp = 0;
    for (; x; x /= 10) sta[tp++] = x % 10 + '0';
    while (tp > 0) printc(sta[--tp]);
  } else
    printc('0');
  printc(c);
}
template <typename T1, typename... T2>
inline void print(T1 x, T2... y) {
  print(x, ' '), print(y...);
}
}  // namespace IOStream
using namespace IOStream;
using namespace std;
const int MAXN = 300005, MAXT = 1100000, MAXM = 600005;
vector<pair<int, int> > vec[MAXT];
map<pair<int, int>, int> mp;
int par[MAXM], fst[MAXM], sec[MAXM], tp, m;
pair<int, int> sta[MAXN];
long long res;
void add(int a, int b, pair<int, int> x, int l = 1, int r = m, int k = 1) {
  if (a > r || b < l) return;
  if (a <= l && b >= r) {
    vec[k].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  add(a, b, x, l, mid, k << 1);
  add(a, b, x, mid + 1, r, k << 1 | 1);
}
int find(int x) { return x == par[x] ? x : find(par[x]); }
void calc(int l, int r, int k = 1) {
  int bef = tp;
  for (pair<int, int> p : vec[k]) {
    int a = find(p.first), b = find(p.second);
    if (a == b) continue;
    if (fst[a] + sec[a] > fst[b] + sec[b]) swap(a, b);
    sta[++tp] = pair<int, int>(a, b), par[a] = b;
    res -= (long long)fst[a] * sec[a] + (long long)fst[b] * sec[b];
    fst[b] += fst[a], sec[b] += sec[a];
    res += (long long)fst[b] * sec[b];
  }
  if (l < r) {
    int mid = (l + r) >> 1;
    calc(l, mid, k << 1);
    calc(mid + 1, r, k << 1 | 1);
  } else
    print(res, ' ');
  while (tp > bef) {
    int a = sta[tp].first, b = sta[tp].second;
    --tp;
    par[a] = a, res -= (long long)fst[b] * sec[b];
    fst[b] -= fst[a], sec[b] -= sec[a];
    res += (long long)fst[a] * sec[a] + (long long)fst[b] * sec[b];
  }
}
int main() {
  read(m);
  for (int i = 1; i <= 300000; i++) par[i] = i, fst[i] = 1;
  for (int i = 300001; i <= 600000; i++) par[i] = i, sec[i] = 1;
  for (int i = 1; i <= m; i++) {
    int a, b;
    read(a, b);
    b += 300000;
    pair<int, int> x = pair<int, int>(a, b);
    if (mp[x])
      add(mp[x], i - 1, x), mp[x] = 0;
    else
      mp[x] = i;
  }
  for (auto t : mp)
    if (t.second) add(t.second, m, t.first);
  calc(1, m);
  ioflush();
  return 0;
}