import itertools import numpy as np N = int(input()) A = np.array(tuple(map(int, input().split())), dtype=np.int64) B = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64) w = -float('inf') it = itertools.product((0, 1), repeat=N) next(it) for t in it: comp = list(itertools.compress(range(N), t)) tmp = A[comp].sum() + B[np.ix_(comp, comp)].sum() // 2 if w < tmp: J = tuple(x + 1 for x in comp) w = tmp print(w) print(*J)