import sys import math import bisect from heapq import heapify, heappop, heappush from collections import deque, defaultdict, Counter from functools import lru_cache from itertools import accumulate, combinations, permutations, product sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 MOD99 = 998244353 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() SMI = lambda: input().split() SLI = lambda: list(SMI()) EI = lambda m: [NLI() for _ in range(m)] def score(a, b, x): v1 = abs(5 * 10**17 - a) v2 = abs(5 * 10**17 - b) if max(v1, v2) > 0: return int(2000000 - 100000 * math.log10(max(v1, v2)+1)) else: return 2000050 - x def answer(ans): print(len(ans)) for i, j in ans: print(i+1, j+1) def greedy(): N = NI() AB = EI(N) ans = [] # 0と何かだけで貪欲 for qi in range(50): a0, b0 = AB[0] s = score(a0, b0, qi) best_s = s best_v = 1 for v in range(1, N): av, bv = AB[v] na, nb = (a0+av) // 2, (b0+bv) // 2 ns = score(na, nb, qi+1) if ns > best_s: best_s = ns best_v = v if best_s > s: av, bv = AB[best_v] na, nb = (a0 + av) // 2, (b0 + bv) // 2 AB[0] = [na, nb] AB[best_v] = [na, nb] ans.append([0, best_v]) else: break answer(ans) def means(AB, i, j): ai, bi = AB[i] aj, bj = AB[j] na, nb = (ai + aj) // 2, (bi + bj) // 2 return na, nb def query(AB, i, j): na, nb = means(AB, i, j) AB[i] = [na, nb] AB[j] = [na, nb] def total_score(AB): res = 0 for a, b in AB: res += score(a, b, 0) return res def calc_gap(AB, i, j): # ABについてi, jを操作したときのスコアの差分 na, nb = means(AB, i, j) after = score(na, nb, 0) * 2 before = score(AB[i][0], AB[i][1], 0) + score(AB[j][0], AB[j][1], 0) return after - before def main(): N = NI() AB = EI(N) total = total_score(AB) ans = [] # totalが改善するように山登り for qi in range(50): max_gap = 0 best_ij = [0, 1] for i in range(N): for j in range(i+1, N): gap = calc_gap(AB, i, j) if gap > max_gap: max_gap = gap best_ij = [i, j] if max_gap > 0: query(AB, *best_ij) ans.append(best_ij) else: break answer(ans) if __name__ == "__main__": main()