from itertools import product n=int(input()) ns=list(map(int,input().split())) bs=[list(map(int,input().split())) for i in range(n)] ans=0 anss=[] for p in product([0,1],repeat=n): cnt=0 cntb=[] for i in range(len(p)): if p[i] == 1: cnt+= ns[i] cntb.append(i) if len(cntb) <= 1: if ans < cnt: ans = cnt anss = cntb continue for i in range(len(cntb)-1): for j in range(i+1,len(cntb)): cnt += bs[cntb[i]][cntb[j]] if ans < cnt: ans = cnt anss = cntb print(ans) anss=list(map(lambda x:x+1,anss)) print(*anss)