import random import time def isvalid(tree): return e[tree[3]]maxi: maxi=now maxi_pos=cnt cnt+=1 return maxi-mini def score(trees): wa=0 use=[] for i in trees: use.append(high(i)) wa+=use[-1] ret=0 for i in use: ret+=((i*N)-wa)**2 return ret st=time.time() N,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) d=list(map(int,input().split())) e=list(map(int,input().split())) f=list(map(int,input().split())) tip=list(zip(a,b,range(N))) center=list(zip(c,d,range(N*2))) stem=list(zip(e,f,range(N))) tip.sort(reverse=True) center.sort(reverse=True) stem.sort(reverse=True) tip_stock=set(range(N)) center_stock=set(range(N*2)) stem_stock=set(range(N*2)) tree=[] for i in range(M): while stem[-1][0]>=tip[-1][0]: tip.pop() while tip[-1][0]>=center[-1][0]: center.pop() tree.append([tip[-1][2],center[-1][2],center[-2][2],stem[-1][2]]) tip_stock.discard(tip[-1][2]) center_stock.discard(center[-1][2]) center_stock.discard(center[-2][2]) stem_stock.discard(stem[-1][2]) center.pop() center.pop() tip.pop() stem.pop() tip_stock=list(tip_stock) center_stock=list(center_stock) stem_stock=list(stem_stock) mini_pos=-1 maxi_pos=-1 now=row_score(tree) while time.time()-st<1.1: befmi=mini_pos befma=maxi_pos if random.random()<1: if random.random()<0.5: lf=mini_pos else: lf=maxi_pos ri=random.randint(0,M-1) if lf==ri: ri=(ri+1)%M if random.random()<0.25: tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0] if not(isvalid(tree[lf]) and isvalid(tree[ri])): tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0] else: now=sc elif random.random()<0.3333: tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2] if not(isvalid(tree[lf]) and isvalid(tree[ri])): tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2] else: now=sc else: if random.random()<0.5: tree[lf][1],tree[lf][2]=tree[lf][2],tree[lf][1] if random.random()<0.5: tree[ri][1],tree[ri][2]=tree[ri][2],tree[ri][1] tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1] if not(isvalid(tree[lf]) and isvalid(tree[ri])): tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1] else: now=sc else: if random.random()<0.5: lf=mini_pos else: lf=maxi_pos if random.random()<0.25: pos=random.randint(0,len(tip_stock)) tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0] if not(isvalid(tree[lf])): tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0] else: now=sc elif random.random()<0.33333: pos=random.randint(0,len(stem_stock)) tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3] if not(isvalid(tree[lf])): tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3] else: now=sc else: if random.random()<0.5: tree[lf][1],tree[lf][2]=tree[lf][2],tree[lf][1] pos=random.randint(0,len(center_stock)) tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2] if not(isvalid(tree[lf])): tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2] else: sc=row_score(tree) if sc>now: maxi_pos=befma mini_pos=befmi tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2] else: now=sc #print(row_score(tree)) for i in tree: print(*(map(lambda x:x+1,i)))