from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
N = int(input())
XY = [tuple(map(int,input().split())) for _ in range(N)]
pos = {y:i for i,y in enumerate(XY)}

XY.sort()
print(N//2)
for i in range(0,N-1,2):
    x = XY[i]
    y = XY[i+1]
    print(pos[x]+1,pos[y]+1)