n = int(input()) a = list(map(int, input().split())) b = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(1 << n): t = 0 for j in range(n): if i >> j & 1: t += a[j] for j in range(n-1): for k in range(j+1, n): if i>>j & 1 and i>>k & 1: t += b[j][k] if ans <= t: ans = t anss = i print(ans) u = [] for i in range(n): if anss >> i & 1: u.append(i+1) if u: print(*u)