n = int(input())
maxVol = []
currentVol = []
diff = []
for i in range(n):
x = [int(x) for x in input().split()]
currentVol.append(x[0])
maxVol.append(x[1])
diff.append(abs(x[0] - x[1]))
allDiffs = sum(diff)
cached = []
for i in range(n):
glass = currentVol[i]
for j in range(n):
if diff[j] > 0 and j != i and j not in cached:
if glass <= diff[j]:
diff[j] -= glass
currentVol[i] = 0
currentVol[j] += glass
break
else:
glass -= diff[j]
currentVol[i] -= diff[j]
diff[j] = 0
currentVol[j] = maxVol[j]
cached.append(i)
print(currentVol.count(0))
for i in currentVol:
print(i, end = ' ')