#!/usr/bin/env python3
import sys
import subprocess
sys.setrecursionlimit(500000)

n = int(sys.stdin.readline())

es = []
neigh = [[] for i in range(n)]
all_neigh = [[] for i in range(n)]
term = [None]*n
stack = []
for i in range(n):
    fire, hire = map(int, sys.stdin.readline().split())
    while fire > 0:
        other, other_hire = stack.pop()
        mn = min(fire, other_hire)
        assert mn > 0
        term[i] = other
        es.append((other, i))
        neigh[other].append(i)
        all_neigh[other].append(i)
        all_neigh[i].append(other)
        other_hire -= mn
        fire -= mn
        if other_hire > 0:
            stack.append((other, other_hire))
    if hire > 0:
        stack.append((i, hire))

def different(S):
    c = 1
    while c in S:
        c += 1
    return c

color = [None]*n
color[0] = 1
S = [(0,3)]

while S:
    (l, above_color) = S.pop()

    if l == n:
        continue

    if not neigh[l]:
        if l + 1 < n and term[l+1] is None:
            color[l+1] = different({above_color})
            S.append((l+1, above_color))
        continue

    r = neigh[l].pop()
    if term[r] == l:
        color[r] = different({color[l], above_color})
    else:
        assert color[r] is not None
    if term[r] == l:
        S.append((r, above_color))
    S.append((l, color[r]))

sys.stdout.write('%d\n' % max(color))
sys.stdout.write('%s\n' % ' '.join(map(str, color)))

