from time import time st=time() import sys input = lambda: sys.stdin.readline().rstrip() from math import log10,exp from copy import copy,deepcopy from random import randint,random,choice from bisect import bisect,bisect_left,insort MAX_OP=50 TIME_LIMIT=0.9 TARGET_NUM=5*10**17 # カード1のスコアだけ見ればいいのか # 奇数回目の操作でカード1以外を操作する # 偶数回目でカード1を操作する # カード1のスコアを計算 def calc_front(AB):return abs(AB[0][0]-TARGET_NUM) def calc_back(AB):return abs(AB[0][1]-TARGET_NUM) def calc_Score(cnt,AB): V1=calc_front(AB) V2=calc_front(AB) temp=max(V1,V2) if temp==0:return 2000050-cnt return int(2000000-100000*log10(temp+1)) def rewrite(u,v): tempf=(tempAB[u][0]+tempAB[v][0])//2 tempAB[u][0]=tempf tempAB[v][0]=tempf tempb=(tempAB[u][1]+tempAB[v][1])//2 tempAB[u][1]=tempb tempAB[v][1]=tempb N=int(input()) AB=[list(map(int, input().split())) for _ in range(N)] NowScore=calc_Score(0,AB) UV=[] premove=-1 preop=-1 while time()-st<=TIME_LIMIT: tempAB=deepcopy(AB) tempUV=[] pretempScore=0 opcnt=randint(0,MAX_OP) for cnt in range(1,opcnt+1): # 各カード表裏について値を記録する F_set=[] B_set=[] for i in range(1,N): a,b=tempAB[i] insort(F_set,(a,i)) insort(B_set,(b,i)) # カード1の表裏を適当に書き換える k=randint(0,1) if k: a=tempAB[0][0] bk=bisect_left(F_set,(2*TARGET_NUM-a,0)) if bk>=N-1:bk=N-2 b,v=F_set[bk] rewrite(0,v) else: c=tempAB[0][1] dk=bisect_left(B_set,(2*TARGET_NUM-c,0)) if dk>=N-1:dk=N-2 d,v=B_set[dk] rewrite(0,v) tempScore=calc_Score(cnt,tempAB) if pretempScore>tempScore:break pretempScore=tempScore tempUV.append((0,v)) if tempScore>NowScore: NowScore=tempScore UV=deepcopy(tempUV) else: T=(time()-st)/TIME_LIMIT if exp((tempScore-NowScore)/T)>=random(): NowScore=tempScore UV=deepcopy(tempUV) print(len(UV)) for u,v in UV:print(u,v) print(NowScore)