import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N = I() A = LI() B = [LI() for _ in range(N)] ans = 0 oto = 0 for i in range(1,1<>j) & 1] l = len(X) score = 0 for x in X: score += A[x] for j in range(l-1): for k in range(j+1,l): score += B[X[j]][X[k]] if ans < score: ans = score oto = X print(ans) ANS = [x+1 for x in oto] print(*ANS)