#bit全探索 from itertools import product n=int(input()) A = list(map(int, input().split())) B = [list(map(int, input().split())) for _ in range(n)] W=-(10**10) for bits in product([0,1],repeat=n): #全て0はダメ if sum(bits) == 0: continue w=0 for i in range(n): if bits[i] == 1: w+=A[i] for i in range(n): for j in range(i+1,n): if bits[i] & bits[j] == 1: w+=B[i][j] if w>W: W=W max_bits = bits print(W) print(*(i+1 for i in range(n) if max_bits[i] == 1))