#include using namespace std; #define ll long long #define FOR(i,n,m) for(ll i=(n);i<(m);i++) #define REP(i,n) FOR(i,0,n) #define REPR(i,n) for(ll i=(n);i>=0;i--) #define all(vec) vec.begin(),vec.end() using vi=vector; using vvi=vector; using vl=vector; using vvl=vector; using P=pair; using PP=pair; using vp=vector

; using vpp=vector; using vs=vector; #define fi first #define se second #define pb push_back templatebool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;} const ll MOD=1000000007LL; const int INF=1<<30; const ll LINF=1LL<<60; int dx[]={-1,0,1,0},dy[]={0,-1,0,1}; const int ScoreA=15; const int ScoreB=1; const int ScoreC=2; int main(){ int n,k; cin>>n>>k; vi d(k); REP(i,k){ cin>>d[i]; } vs vec(n); REP(i,n){ cin>>vec[i]; } REP(i,k){ int ma=-INF; P p(0,0); bool f=false; REP(j,n){ REP(k,n-d[i]){ int q=0; REP(l,d[i]){ if(vec[j][k+l]=='1'){ q+=ScoreA; }else{ q-=ScoreA; } REP(dir,4){ if(0<=j+dx[dir]&&j+dx[dir]ma){ ma=q; p=P(j,k); f=false; } } } REP(j,n-d[i]){ REP(k,n){ int q=0; REP(l,d[i]){ if(vec[j+l][k]=='1'){ q+=ScoreA; }else{ q-=ScoreA; } REP(dir,4){ if(0<=j+l+dx[dir]&&j+l+dx[dir]ma){ ma=q; p=P(j,k); f=true; } } } if(!f){ REP(l,d[i]){ if(vec[p.fi][p.se+l]=='1'){ vec[p.fi][p.se+l]='0'; }else{ vec[p.fi][p.se+l]='1'; } } cout<