#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; double score(const string& parts, const string& prev, string& next){ double ret = 0; rep(i,parts.size()){ if(parts[i] == '1'){ ret += 1.0; } else { if(prev[i] == '1' && next[i] == '1') ret += 0.5; else ret -= 10.0; } } return ret; } int main(){ int N, K; cin >> N >> K; vector L; rep(i,K){ int l; cin >> l; L.push_back(l); } vector A; rep(i,N){ string a; cin >> a; A.push_back(a); } int W0 = 0; rep(y,N) rep(x,N){ if(A[y][x] == '0') W0++; } rep(t, K){ double best_score = -1e18; int best_y = 0, best_x = 0, which = 0; rep(y,N){ rep(x,N){ if(x+L[t]=0) prev += A[y-1][x+i]; parts += A[y][x+i]; if(y+1=0) prev += A[y+i][x-1]; parts += A[y+i][x]; if(x+1