import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N = int(input()) A = list(map(int, input().split())) B = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = -1 pair = -1 for S in range(1, 1 << N): score = 0 for i, a in enumerate(A): if (S >> i) & 1: score += a for i in range(N): if (S >> i) & 1: for j in range(i + 1, N): if (S >> j) & 1: score += B[i][j] if score > ans: ans = score pair = S print(ans) print(*[i+1 for i in range(N) if (pair >> i) & 1])