f=[] n,k=list(map(int,input().split())) l=list(map(int,input().split())) for i in range(n): f.append(list(map(int,list(input())))) for i in range(k): nl=l[i] maxb=0 maxd=[0,0,0] for x in range(n-nl+1): for y in range(n-nl+1): h=0 w=0 for z in range(nl): h+=f[x][y+z] w+=f[x+z][y] m=max([h,w]) if maxb