n = int(input()) A = list(map(int, input().split())) B = [list(map(int, input().split())) for _ in range(n)] ans = -1 ind = -1 for bit in range(1, 1 << n): lst = [] for i in range(n): if bit >> i & 1: lst.append(i) l = len(lst) tmp = 0 for i in range(l): tmp += A[lst[i]] for j in range(i + 1, l): tmp += B[lst[i]][lst[j]] if tmp > ans: ans = tmp ind = lst print(ans) print(*[i + 1 for i in ind])