import sys import math import collections # sys.setrecursionlimit(10000001) INF = 10 ** 20 # MOD = 10 ** 9 + 7 MOD = 998244353 def ni(): return int(sys.stdin.buffer.readline()) def ns(): return map(int, sys.stdin.buffer.readline().split()) def na(): return list(map(int, sys.stdin.buffer.readline().split())) def na1(): return list(map(lambda x: int(x)-1, sys.stdin.buffer.readline().split())) # ===CODE=== def main(): n = ni() a = na() b = [na() for _ in range(n)] lim = pow(2, n) ans = -INF ansc = [] for i in range(lim): v = i res = 0 used = [] for j in range(n): if v >> j & 1: res += a[j] for ui in used: res += b[j][ui] used.append(j) if ans < res: ans = max(ans, res) ansc = used for i in range(len(ansc)): ansc[i] += 1 print(ans) print(*ansc) if __name__ == '__main__': main()