Under construction

Still being built. Things may change

Flippy MEX

Time limit2sMemory limit512 MB

Summary
After each double-sided card is added, count how many distinct mex values are possible over all ways to flip the cards placed so far.
Level

Medium7 of 10

Topics
Array, Greedy, Implementation
Solved
No attempts yet

Problem

mex\mathrm{mex} is the function that returns the smallest non-negative integer missing from a given sequence. Junseo made a game with NN cards for Siwoo, who likes mex\mathrm{mex}.

The rules are as follows. The steps run from 11 to NN in order.

  • In step ii, Junseo places card ii on the table. The front and back of the card have non-negative integers AiA_i and BiB_i written on them.
  • For each of the 2i2^i ways to flip the ii cards on the table, Siwoo treats the numbers facing up as a sequence and computes its mex\mathrm{mex}. Then Siwoo states how many distinct mex\mathrm{mex} values are possible.
  • Junseo checks Siwoo's answer and moves on to step i+1i+1.

Help Siwoo find the answer Siwoo should state at each step.

Input

The first line contains the number of cards NN. (1≤N≤106)(1 \le N \le 10^6)

From the second line onward, each of the next NN lines contains two integers AiA_i and BiB_i, separated by a space, which give the information for the ii-th card. (0≤Ai,Bi≤106)(0 \le A_i, B_i \le 10^6)

Output

On the ii-th line, print the answer Siwoo should state in step ii.

Examples1

  1. Example 1

    Input
    8
    7 7
    0 4
    1 3
    5 1
    2 2
    1 4
    4 5
    3 3
    
    Expected output
    1
    2
    3
    3
    4
    5
    6
    5