PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000051. Phân phòng khách sạn (Room Allocation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Phân phòng khách sạn (Room Allocation)

Room Allocation

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn hotel guests, each staying from arrival day aia_i through departure day bib_i, inclusive. Guests can reuse a room only if the first guest departs strictly before the next arrives. Find the minimum number of rooms and assign each original guest a room.

Input

The first line gives nn, followed by nn pairs ai,bia_i,b_i indicating arrival and departure days.

Output

Print the minimum room count kk, then one room number between 11 and kk for each guest in input order. Any valid optimal assignment is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9.

Examples

Input

3
1 2
2 4
4 4

Output

2
1 2 1

Explanation

Guests 1 and 2 both need rooms on day 2, so at least two rooms are necessary. Guest 3 arrives after guest 1 leaves and may reuse room 1.