import sequtils,algorithm template times*(n:int,body) = (for _ in 0.." .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord # 隣接リスト([n->[m1,m2,m3], ... ])を トポロジカルソート proc topologicalSort(E:seq[seq[int]],deleteIsolated:bool = false) : seq[int] = var visited = newSeq[int](E.len) var answer = newSeq[int]() proc visit(src:int) = visited[src] += 1 if visited[src] > 1: return for dst in E[src]: visit(dst) answer &= src # 葉から順に追加される for src in 0.. 1 or E[it].len > 0) return answer let n = scan() let B = newSeqWith(n,(x:scan(),y:scan(),z:scan())) proc isSmall(a,b:tuple[x,y,z:int]): bool = var an = @[a.x,a.y,a.z].sorted(cmp) while true: if an[0] < b.x and an[1] < b.y and an[2] < b.z : return true if not an.nextPermutation() : return false var E = newSeqWith(n,newSeq[int]()) for i in 0..