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;
const int MAXN = 301000;
class DisjointSet {
 public:
  DisjointSet(int n = MAXN * 2)
      : N(n),
        parents(n, 0),
        ranks(n, 0),
        cntsX(n, 0),
        cntsY(n, 0),
        clock(0),
        recSize(0) {
    iota(parents.begin(), parents.end(), 0);
    records.resize(N * 2);
  }
  void add(int x, int cx, int cy) {
    cntsX[x] += cx;
    cntsY[x] += cy;
    if (x != parents[x]) {
      cntsX[find(x)] += cx;
      cntsY[find(x)] += cy;
    }
  }
  int find(int x) { return x == parents[x] ? x : find(parents[x]); }
  long long calc(int x) {
    int p = find(x);
    return cntsX[p] * 1LL * cntsY[p];
  }
  int now() { return clock; }
  long long merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return 0;
    }
    long long res = 0;
    res -= calc(x);
    res -= calc(y);
    if (ranks[x] >= ranks[y]) {
      swap(x, y);
    }
    ++clock;
    backup(x);
    backup(y);
    parents[x] = y;
    if (ranks[x] == ranks[y]) {
      ++ranks[y];
    }
    cntsX[y] += cntsX[x];
    cntsY[y] += cntsY[x];
    res += calc(y);
    return res;
  }
  void backup(int x) {
    ++clock;
    if (recSize == records.size()) {
      records.resize(recSize * 2);
    }
    records[recSize++] =
        Datum(x, parents[x], cntsX[x], cntsY[x], clock, ranks[x]);
  }
  void revertTo(int time) {
    while (recSize > 0) {
      auto& rec = records[recSize - 1];
      if (rec.timeStamp > time) {
        int x = rec.x;
        int p = rec.p;
        parents[x] = p;
        cntsX[x] = rec.cx;
        cntsY[x] = rec.cy;
        --recSize;
      } else {
        break;
      }
    }
  }

 private:
  int N;
  vector<int> parents;
  vector<int> ranks;
  vector<int> cntsX;
  vector<int> cntsY;
  int clock;
  struct Datum {
    Datum(int _x = 0, int _p = 0, int _cx = 0, int _cy = 0, int _t = 0,
          int _r = 0)
        : x(_x), p(_p), cx(_cx), cy(_cy), timeStamp(_t), rk(_r) {}
    int x;
    int p;
    int cx;
    int cy;
    int rk;
    int timeStamp;
  };
  int recSize;
  vector<Datum> records;
};
class Solution {
 public:
  vector<long long> query(vector<pair<int, int>>& qv) {
    int q = qv.size();
    int maxX = 0;
    int maxY = 0;
    for (auto& p : qv) {
      maxX = max(maxX, p.first);
      maxY = max(maxY, p.second);
    }
    init(maxX, maxY, q);
    map<pair<int, int>, int> mp;
    int idx = 0;
    for (auto& p : qv) {
      if (mp.count(p) > 0) {
        int l = mp[p];
        int r = idx - 1;
        insert(rt, lo, hi, l, r, p);
        mp.erase(p);
      } else {
        mp[p] = idx;
      }
      ++idx;
    }
    for (auto& pi : mp) {
      auto p = pi.first;
      int l = pi.second;
      insert(rt, lo, hi, l, q - 1, p);
    }
    vector<long long> res(q, 0);
    long long cnt = 0;
    dfs(rt, lo, hi, cnt, res);
    return res;
  }

 private:
  DisjointSet ds;
  int K;
  int rt;
  int lo;
  int hi;
  vector<vector<pair<int, int>>> nodes;
  void init(int maxX, int maxY, int q) {
    K = max(maxX + 1, maxY + 1) + 10;
    nodes.clear();
    nodes.resize(q * 4 + 100);
    rt = 1;
    lo = 0;
    hi = q;
    for (int i = 0; i <= maxX; ++i) {
      ds.add(i, 1, 0);
    }
    for (int i = 0; i <= maxY; ++i) {
      ds.add(i + K, 0, 1);
    }
  }
  void insert(int x, int l, int r, int ll, int rr, pair<int, int>& v) {
    if (l > rr || r < ll) {
      return;
    }
    if (ll <= l && r <= rr) {
      nodes[x].push_back(v);
      return;
    }
    int m = (l + r) / 2;
    insert(x << 1, l, m, ll, rr, v);
    insert(x << 1 | 1, m + 1, r, ll, rr, v);
  }
  void dfs(int x, int l, int r, long long cnt, vector<long long>& res) {
    int time = ds.now();
    for (auto& p : nodes[x]) {
      int x = p.first;
      int y = p.second + K;
      cnt += ds.merge(x, y);
    }
    if (l == r) {
      res[l] = cnt;
    } else {
      int m = (l + r) / 2;
      dfs(x << 1, l, m, cnt, res);
      dfs(x << 1 | 1, m + 1, r, cnt, res);
    }
    ds.revertTo(time);
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int q;
  cin >> q;
  vector<pair<int, int>> qv;
  qv.reserve(q);
  for (int i = 0, x = 0, y = 0; i < q; ++i) {
    cin >> x >> y;
    qv.emplace_back(x - 1, y - 1);
  }
  auto res = sol.query(qv);
  for (auto r : res) {
    cout << r << " ";
  }
  cout << "\n";
  return 0;
}