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 
#include <bits/stdc++.h>
using namespace std;
template <class T>
int chkmax(T& a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
int chkmin(T& a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostream& out = cerr) {
  while (begin != end) {
    out << (*begin) << " ";
    begin++;
  }
  out << endl;
}
template <class T>
void output(T x, ostream& out = cerr) {
  output(x.begin(), x.end(), out);
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct dsu {
  vector<int> p, sz1, sz2;
  vector<pair<int, int> > st;
  int v;
  long long ans;
  void init(int n, int m) {
    v = n + m;
    sz1.resize(v);
    sz2.resize(v);
    p.resize(v);
    iota(p.begin(), p.end(), 0);
    for (int i = 0; i < n; ++i) {
      sz1[i] = 1;
    }
    for (int i = n; i < v; ++i) {
      sz2[i] = 1;
    }
  }
  int get_root(int v) {
    if (p[v] == v) {
      return v;
    } else {
      return get_root(p[v]);
    }
  }
  long long func(int v) { return (long long)sz1[v] * (long long)sz2[v]; }
  void hang(int u, int v) {
    st.push_back({u, v});
    p[u] = v;
    sz1[v] += sz1[u];
    sz2[v] += sz2[u];
    ans += func(v);
  }
  void join(int u, int v) {
    u = get_root(u);
    v = get_root(v);
    if (u == v) {
      st.push_back({u, u});
      return;
    }
    ans -= func(u);
    ans -= func(v);
    if (sz1[u] + sz2[u] < sz1[v] + sz2[v]) {
      hang(u, v);
    } else {
      hang(v, u);
    }
  }
  void roll_back(int cnt) {
    for (int i = 0; i < cnt; ++i) {
      int u = st.back().first, v = st.back().second;
      st.pop_back();
      if (u == v) {
        continue;
      }
      p[u] = u;
      ans -= func(v);
      sz1[v] -= sz1[u];
      sz2[v] -= sz2[u];
      ans += func(u);
      ans += func(v);
    }
  }
  long long S_size() { return ans; }
};
int n;
vector<pair<int, int> > a;
vector<int> cx, cy, p;
vector<long long> ans;
dsu T;
void apply(int q_id) { T.join(a[q_id].first, cx.size() + a[q_id].second); }
void go(int l, int r) {
  if (l == r) {
    if (p[l] > l) {
      apply(l);
    }
    ans.push_back(T.S_size());
    if (p[l] > l) {
      T.roll_back(1);
    }
  } else {
    int mid = (l + r) >> 1, cnt = 0;
    for (int i = mid + 1; i <= r; ++i) {
      if (p[i] < l) {
        apply(p[i]);
        cnt++;
      }
    }
    go(l, mid);
    T.roll_back(cnt);
    cnt = 0;
    for (int i = l; i <= mid; ++i) {
      if (p[i] > r) {
        apply(i);
        cnt++;
      }
    }
    go(mid + 1, r);
    T.roll_back(cnt);
  }
}
signed main() {
  fast_io();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back({x, y});
    cx.push_back(x);
    cy.push_back(y);
  }
  sort(cx.begin(), cx.end());
  sort(cy.begin(), cy.end());
  cx.erase(unique(cx.begin(), cx.end()), cx.end());
  cy.erase(unique(cy.begin(), cy.end()), cy.end());
  for (int i = 0; i < n; ++i) {
    a[i].first = lower_bound(cx.begin(), cx.end(), a[i].first) - cx.begin();
    a[i].second = lower_bound(cy.begin(), cy.end(), a[i].second) - cy.begin();
  }
  p.resize(n, n);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; ++i) {
    if (mp.find(a[i]) == mp.end()) {
      mp[a[i]] = i;
    } else {
      p[mp[a[i]]] = i;
      p[i] = mp[a[i]];
      mp.erase(a[i]);
    }
  }
  T.init(cx.size(), cy.size());
  go(0, n - 1);
  output(ans.begin(), ans.end(), cout);
}
