N = int(input()) A = list(map(int, input().split())) B = [list(map(int, input().split())) for i in range(N)] ans = -100000000000000000 bestids = [] for S in range(1 << N): ids = [] for i in range(N): if S >> i & 1: ids.append(i) point = 0 for i in range(len(ids)): point += A[ids[i]] for j in range(i + 1, len(ids)): point += B[ids[i]][ids[j]] if point > ans: ans = point bestids = ids print(ans) print(*map(lambda x: x + 1, bestids))