Choose Interval

Time limit: 1.5s Memory limit: 256MB Input: Output:

You are given an infinite array of zeros with positions indexed by the integers and NN intervals of positions of the form [A,B][A, B]. For every given interval, you have to use one of the following two operations to execute on the array:

  • Normal: Add 11 to all positions in the array from AA to BB.
  • Flipped: Add 11 to all positions in the array except those from AA to BB.

Task

You want to choose a type of operation to execute for each interval so that the maximum value stored in the array after applying all operations is minimized.

Input data

The first line of the input contains the number of intervals NN. The next NN lines each contain two space-separated integers, AA and BB, representing the endpoints of an interval.

Output data

The first line of the output should contain the maximum value in the array after executing the NN operations optimally.

The second line should contain a binary string of length NN, with the iith character being 00 if the iith used operation was flipped and 11 if it was normal.

If there are multiple ways of choosing the operations optimally, any valid solution is accepted.

Constraints and clarifications

  • 1N200 0001 \leq N \leq 200 \ 000
  • 1AB2N1 \leq A \leq B \leq 2 N
# Points Restrictions
1 7 N20N \leq 20
2 24 N150N \leq 150
3 21 N1 000N \leq 1 \ 000
4 34 N50 000N \leq 50 \ 000
5 14 No further restrictions.

Example

stdin

5
10 10
6 6
1 7
2 5
2 7

stdout

2
11110

Explanations

Another valid answer would be

2
11011

Log in or sign up to be able to send submissions!