N = int(input()) A = list(map(int,input().split())) B = [list(map(int,input().split())) for _ in range(N)] ans_point = 0 ans_waon = [] for i in range(2**N): point = 0 waon = [] pattern = bin(i)[2:].zfill(N) for j in range(N): if pattern[j] == "1": point += A[j] waon.append(j+1) len_w = len(waon) for k in range(len_w): for l in range(k+1,len_w): point += B[waon[k]-1][waon[l]-1] if ans_point < point: ans_point = point ans_waon = waon print(ans_point) print(*ans_waon)