from copy import copy N=int(input()) A=[0]+list(map(int,input().split())) B=["*"] for _ in range(N): B.append(["*"]+list(map(int,input().split()))) Max=-float("inf") Arg=[] for x in range(1<>=1 l=len(M) D=0 for i in range(l): for j in range(i+1,l): D+=B[M[i]][M[j]] Score=sum([A[x] for x in M])-D if Score>Max: Max=Score Arg=copy(M) print(Max,len(Arg)) print(" ".join(map(str,Arg)))