from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) T,R=map(int,input().split()) t=0 N=5400 uf=UnionFind(N+1) p=[-1]*(N+1) s=set() # スキル値, プレイヤーi, 出現チック s.add((-10000000,-1,-1)) s.add((100000000,-1,-1)) pi=1 import bisect while T<3600: L=list(map(int,input().split())) # nows=set() # nows.add((-10000000,-1,-1)) # nows.add((100000000,-1,-1)) t_ans=[] for i in range(L[0]): nowi=(L[i+1],pi,t) pi+=1 sorteds=sorted(list(s)) t=bisect.bisect_left(sorteds,nowi) used=False if abs(sorteds[t-1][0] - L[i+1])<5: sz=len(uf.members(pi)) if sz<4: uf.union(pi,sorteds[t-1][1]) t_ans.append(pi) used = True s.discard(sorteds[t-1]) if abs(sorteds[t][0] - L[i+1])<5: sz=len(uf.members(pi)) if sz<4: uf.union(pi,sorteds[t][1]) t_ans.append(pi) used = True s.discard(sorteds[t]) if used == False: s.add(nowi) ans4print=[] ans4print_num=0 for ans in t_ans: m=uf.members(ans) mls=[] for i in range(1,len(m)) : mls.append([m[0],m[i]]) ans4print_num+=1 ans4print.append(mls) print(ans4print_num) for i in range (len(ans4print)): for e in ans4print[i]: print(*e) # for e in sorted[1:-2]: # t=bisect.bisect_left(sortednows,e) # ts,tp,tt = sortednows[t] # if abs(sortednows[t-1][0] - ts) < 5: # m.append()