import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) xs = [[] for i in range(8050)] for i in range(n): x,y = map(int,input().split()) xs[x].append((y,i)) ans = [] left = [] for x in range(8050): xs[x].sort() for y,i in xs[x]: if not left: left.append(i+1) else: ans.append([i+1,left.pop()]) print(len(ans)) for a,b in ans: print(a,b)