from itertools import product n=int(input()) a=list(map(int,input().split())) b=[list(map(int,input().split())) for _ in range(n)] ans=0 ans_l=[] for bit in product(range(2),repeat=n): tmp=0 ring=[] for i in range(n): if bit[i]: tmp+=a[i] ring.append(i+1) if len(ring)>=2: for i in range(len(ring)): for j in range(i+1,len(ring)): tmp+=b[ring[i]-1][ring[j]-1] if tmp>ans: ans=tmp ans_l=ring ans_l.sort() print(ans) print(*ans_l)