n = int(input()) *a, = map(int,input().split()) b = [list(map(int,input().split())) for _ in range(n)] ans = val = 0 N = 1<>i&1==0: continue v += a[i] for j in range(i+1,n): if mask>>j&1: v += b[i][j] if v > val: val = v ans = mask print(val) print(*(i+1 for i in range(n) if ans>>i&1))