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 JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
 
import static java.lang.Math.*;
 
public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        
        public int read() {
            if (numChars==-1) 
                throw new InputMismatchException();
            
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                
                if(numChars <= 0)               
                    return -1;
            }
            return buf[curChar++];
        }
     
        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();
            
            while(isSpaceChar(c)) 
                c = read();
            
            int sgn = 1;
            
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            
            int res = 0;
            do {
                if(c<'0'||c>'9') 
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c)); 
            
            return res * sgn;
        }
        
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }
        
        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } 
            while (!isSpaceChar(c));
            
            return res.toString();
        }
     
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
     
        public String next() {
            return readString();
        }
        
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<27).start();
    } 
    class Move {
        int child, par, prevRank;
        Move(int a, int b, int c) {
            child = a;
            par = b;
            prevRank = c;
        }
    }
    class Edge {
        int u, v;
        Edge(int a, int b) {
            u = a;
            v = b;
        }
    }
    int find(int i) {
        if(par[i] == i)
            return i;
        return find(par[i]);
    }
    void rollback(LinkedList<Move> list) {
        while(list.size() > 0) {
            Move m = list.getLast();
            
            int child = m.child;
            int parent = m.par;

            cntX[parent] -= cntX[child];
            cntY[parent] -= cntY[child];

            cans -= cntX[parent] * cntY[child] + cntX[child] * cntY[parent];

            rank[parent] = m.prevRank;

            par[child] = child;

            list.removeLast();
        }
    }
    void combine(int u, int v, LinkedList<Move> list) {
        cans += cntX[u] * cntY[v] + cntX[v] * cntY[u];

        if(rank[u] > rank[v]) {
            list.add(new Move(v, u, rank[u]));

            cntX[u] += cntX[v];
            cntY[u] += cntY[v];

            par[v] = u;
        }
        else {
            list.add(new Move(u, v, rank[v]));
            
            cntX[v] += cntX[u];
            cntY[v] += cntY[u];
            
            if(rank[v] == rank[u])
                rank[v]++;

            par[u] = v;
        }
    }
    void solve(int low, int high, int pos) {
        LinkedList<Move> list = new LinkedList<>();

        for(Edge e : segTree[pos]) {
            int u = find(e.u);
            int v = find(e.v);

            if(u != v) {
                combine(u, v, list);
            }
        }

        if(low != high) {
            int mid = (low + high) >> 1;
            solve(low, mid, 2 * pos + 1);
            solve(mid + 1, high, 2 * pos + 2);
        }
        else
            ans[low] = cans;

        rollback(list);
    }
    void addEdge(int low, int high, int pos, int l, int r, Edge e) {
        if(low > r || high < l)
            return;

        if(low >= l && high <= r) {
            segTree[pos].add(e);
            return;
        }

        int mid = (low + high) >> 1;
        addEdge(low, mid, 2 * pos + 1, l, r, e);
        addEdge(mid + 1, high, 2 * pos + 2, l, r, e);
    }
    long cans = 0;
    ArrayList<Edge> segTree[];
    long ans[];
    long cntX[], cntY[];
    int par[], rank[];
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int q = sc.nextInt();

        segTree = new ArrayList[4 * q];
        for(int i = 0; i < 4 * q; ++i) {
            segTree[i] = new ArrayList<>();
        }

        TreeMap<Integer, Integer> map[] = new TreeMap[300000];
        for(int i = 0; i < 300000; ++i)
            map[i] = new TreeMap<>();

        for(int x = 0; x < q; ++x) {
            int indx = sc.nextInt() - 1;
            int indy = sc.nextInt() + 299999;

            if(map[indx].get(indy) != null) {
                addEdge(0, q - 1, 0, map[indx].get(indy), x - 1, new Edge(indx, indy));
                map[indx].remove(indy);
            }
            else
                map[indx].put(indy, x);
        }
        for(int i = 0; i < 300000; ++i) {
            for(int j : map[i].keySet()) 
                addEdge(0, q - 1, 0, map[i].get(j), q - 1, new Edge(i, j));
        }        

        ans = new long[q];
        cntX = new long[600000];
        cntY = new long[600000];
        par = new int[600000];
        rank = new int[600000];

        for(int i = 0; i < 600000; ++i) {
            rank[i] = 0;
            par[i] = i;
            if(i < 300000)
                cntX[i] = 1;
            else
                cntY[i] = 1;
        }

        solve(0, q - 1, 0);

        for(long i : ans)
            w.print(i + " ");

        w.close();
    }
}