import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # 10進数aをdigitケタのn進数のリストに変換 def ton(a,n,digit): res=[0]*digit for i in range(digit): if a==0:break a,r=divmod(a,n) res[i]=r return res inf=10**16 n=II() cc=LLI(n) dp=[[inf]*n for _ in range(3**n)] bit=1 for i in range(n): dp[bit][i]=0 bit*=3 def chmin(i,j,val): if val