from itertools import combinations n = int(input()) A = list(map(int, input().split())) B = [list(map(int, input().split())) for _ in range(n)] ans = 0 for r in range(1, n + 1): for C in combinations(range(1, n + 1), r): res = 0 for i in range(r): res += A[C[i] - 1] for j in range(i + 1, r): res += B[C[i] - 1][C[j] - 1] if res > ans: ans = res ANS = C print(ans) print(*ANS)