N = int(input()) A = list(map(int, input().split())) B = [] for _ in range(N): B.append(list(map(int, input().split()))) Max = -float('inf') Max_comb = -1 for i in range(1 << N): point = 0 prev = [] for j in range(N): if (i & (1 << j)) != 0: point += A[j] for p in prev: point += B[p][j] prev.append(j) if Max < point: Max = point Max_comb = i J = [] for j in range(N): if (Max_comb & (1 << j)) != 0: J.append(str(j+1)) print(Max) print(' '.join(J))