import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = [] for i in range(N): B.append(list(map(int, input().split()))) ma = -10 ** 18 n = 0 for s in range(1, 1 << N): v = 0 for i in range(N): if (s >> i) & 1: v += A[i] else: continue for j in range(i + 1, N): if (s >> j) & 1: v += B[i][j] if v > ma: ma = v n = s ans = [] for i in range(N): if (n >> i) & 1: ans.append(i + 1) print(ma) print(*ans)