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 DsuBackup {
vector<pair<long long *, long long>> backups;
long long n;
long long ans = 0;
vector<long long> p;
vector<long long> rank;
vector<long long> cnt_f;
vector<long long> cnt_s;
void init(long long n_) {
  n = n_;
  p.resize(2 * n);
  rank.resize(2 * n);
  cnt_f.resize(2 * n);
  cnt_s.resize(2 * n);
  for (long long i = 0; i < 2 * n; i++) {
    p[i] = i;
    if (i < n) {
      cnt_f[i] = 1;
    } else {
      cnt_s[i] = 1;
    }
  }
}
long long get(long long v) {
  if (p[v] != v) {
    return get(p[v]);
  } else {
    return v;
  }
}
void merge(long long a, long long b) {
  a = get(a);
  b = get(b);
  if (a != b) {
    if (rank[a] < rank[b]) {
      swap(a, b);
    }
    backups.emplace_back(&p[b], p[b]);
    p[b] = a;
    long long new_ans = ans;
    new_ans -= cnt_f[a] * cnt_s[a];
    new_ans -= cnt_f[b] * cnt_s[b];
    backups.emplace_back(&cnt_f[a], cnt_f[a]);
    cnt_f[a] += cnt_f[b];
    backups.emplace_back(&cnt_s[a], cnt_s[a]);
    cnt_s[a] += cnt_s[b];
    backups.emplace_back(&cnt_f[b], cnt_f[b]);
    cnt_f[b] = 0;
    backups.emplace_back(&cnt_s[b], cnt_s[b]);
    cnt_s[b] = 0;
    new_ans += cnt_f[a] * cnt_s[a];
    backups.emplace_back(&ans, ans);
    ans = new_ans;
    if (rank[a] == rank[a]) {
      backups.emplace_back(&rank[a], rank[a]);
      rank[a]++;
    }
  }
}
void backup(long long to) {
  while ((long long)backups.size() > to) {
    *backups.back().first = backups.back().second;
    backups.pop_back();
  }
}
}  // namespace DsuBackup
namespace DcpOffline {
long long n;
vector<long long> answers;
vector<vector<pair<long long, long long>>> t;
void add_edge(long long v, long long l, long long r, long long ql, long long qr,
              pair<long long, long long> val) {
  if (r <= ql || qr <= l) {
    return;
  } else if (ql <= l && r <= qr) {
    t[v].push_back(val);
  } else {
    long long m = (r + l) >> 1;
    add_edge(2 * v + 1, l, m, ql, qr, val);
    add_edge(2 * v + 2, m, r, ql, qr, val);
  }
}
void add_edge(pair<long long, long long> ed, long long l, long long r) {
  add_edge(0, 0, n, l, r, ed);
}
void go_down(long long v, long long l, long long r) {
  long long was_backups = (long long)DsuBackup::backups.size();
  for (auto x : t[v]) {
    DsuBackup::merge(x.first, x.second);
  }
  if (l + 1 == r) {
    answers[l] = DsuBackup::ans;
  } else {
    long long m = (r + l) >> 1;
    go_down(2 * v + 1, l, m);
    go_down(2 * v + 2, m, r);
  }
  DsuBackup::backup(was_backups);
}
void run() {
  DsuBackup::init(n);
  go_down(0, 0, n);
}
void init(long long n_) {
  n = n_;
  answers.resize(n);
  t.resize(4 * n);
}
}  // namespace DcpOffline
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  const long long MAXN = 5e5 + 239;
  long long q;
  cin >> q;
  DcpOffline::init(MAXN);
  set<pair<long long, long long>> seen;
  map<pair<long long, long long>, long long> wh;
  for (long long i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    y += MAXN;
    if (seen.count({x, y})) {
      DcpOffline::add_edge({x, y}, wh[{x, y}], i);
      seen.erase({x, y});
    } else {
      seen.insert({x, y});
    }
    wh[{x, y}] = i;
  }
  for (auto t : seen) {
    DcpOffline::add_edge({t.first, t.second}, wh[{t.first, t.second}], q);
  }
  DcpOffline::run();
  for (long long i = 0; i < q; i++) {
    cout << DcpOffline::answers[i] << ' ';
  }
}