n = int(input()) P = [list(map(int, input().split())) + [i + 1] for i in range(n)] P.sort(key=lambda x: (x[0], x[1])) print(n // 2) for i in range(0, n // 2): print(P[2 * i][2], P[2 * i + 1][2])