Under construction

Still being built. Things may change

NOI Carnival

Time limit1sMemory limit512 MB

Summary
Place each event at venue A, venue B, or skip it, with no overlapping events split across venues. Maximize the smaller venue's count, with each event forced in turn.
Level

Hard9 of 10

Topics
Intervals, Dynamic programming, Sorting, Graph
Solved
No attempts yet

Problem

NOI 2011 has started at Jilin University. To welcome outstanding informatics competitors from across the country, the university will host two carnivals at two different venues. Each venue hosts many events, and each event can be held at only one of the venues.

Andy, the carnival event organizer, has received a total of nn event applications. The ii-th event starts at SiS_i and lasts TiT_i units of time. Each event may be scheduled at one venue, or it may not be scheduled at all.

If both venues host events at the same time (not counting the instant when an event starts or ends), competitors will be torn between the two venues. To prevent this, no two events may run at both venues simultaneously. Several events may run at the same venue.

A venue with few events will attract few visitors. Andy wants a schedule that maximizes the number of events at the venue with the fewest events.

Some events are especially interesting, and Andy wants to be sure they are held. For each event ii, find the maximum number of events at the venue with the fewest events, given that event ii must be held at one of the two venues.

Input

The first line contains an integer nn, the number of events. Each of the next nn lines contains two integers SiS_i and TiT_i, meaning that event ii starts at time SiS_i and lasts TiT_i units of time.

Output

The first line prints the maximum number of events at the venue with the fewest events, with no extra restrictions. Each of the next nn lines prints, for event ii, the maximum number of events at the venue with the fewest events, given that event ii must be held.

Constraints

1≤n≤2001 \le n \le 200

0≤Si≤1090 \le S_i \le 10^9

1≤Ti≤1091 \le T_i \le 10^9

Examples1

  1. Example 1

    Input
    5
    8 2
    1 5
    5 3
    3 2
    5 3
    
    Expected output
    2
    2
    1
    2
    2
    2