#!/usr/bin/env python3
import random
import heapq

n = int(input())
E = [[] for _ in range(n)]
cur = []
for i in range(n):
    (f, h) = map(int, input().split())
    while f:
        if not cur[-1][0]:
            cur.pop()
            continue
        E[i].append(cur[-1][1])
        E[cur[-1][1]].append(i)
        x = min(f, cur[-1][0])
        cur[-1][0] -= x
        f -= x
    cur.append([h, i])

forb = [0]*n
forbc = [0]*n
col = [0]*n
Q = []
for i in range(n):
    heapq.heappush(Q, (0, i))
while Q:
    (_, v) = heapq.heappop(Q)
    if col[v]: continue
    col[v] = 1
    while forb[v] & (1<<col[v]): col[v] += 1
    for w in E[v]:
        if not col[w] and not (forb[w] & (1<<col[v])):
            forb[w] |= 1<<col[v]
            forbc[w] += 1
            heapq.heappush(Q, (-forbc[w], w))


print(max(col))
print(' '.join(map(str, col)))

