#!/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

def bipartite(cur):
    for nxt in all_neigh[cur]:
        if color[nxt] is None:
            color[nxt] = different({color[cur]})
            bipartite(nxt)
        if color[cur] == color[nxt]:
            return False
    return True

bip = True
for i in range(n):
    if color[i] is None:
        color[i] = 1
        S = [i]
        while S and bip:
            cur = S.pop()
            for nxt in all_neigh[cur]:
                if color[nxt] is None:
                    color[nxt] = different({color[cur]})
                    S.append(nxt)
                if color[cur] == color[nxt]:
                    bip = False
                    break

if not bip:
    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)))

