#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=(b-1);i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define print(x) cout<<#x<<" = "< &vs){ ll score = 0; rep(y,0,n){ rep(x,0,n){ if(vs[y][x]=='0')score++; } } return score; } void fh(ll y, ll x, ll a, vector &vs){ rep(p,0,a){ if(vs[y+p][x]=='1'){ vs[y+p][x]='0'; } else{ vs[y+p][x]='1'; } } } void fv(ll y, ll x, ll a, vector &vs){ rep(p,0,a){ if(vs[y][x+p]=='1'){ vs[y][x+p]='0'; } else{ vs[y][x+p]='1'; } } } unsigned int xor128(void) { static unsigned int x = 123456789; static unsigned int y = 362436069; static unsigned int z = 521288629; static unsigned int w = 88675123; unsigned int t; t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } int main() { cin>>n>>k; vector v; rep(i,0,k){ ll a; cin>>a; v.pb(a); } vector vs; rep(i,0,n){ string s; cin>>s; vs.pb(s); } ll score = f(vs); vector,ll > > best_vv; rep(t,0,9000){ vector,ll > > vv; rep(i,0,k){ ll b = xor128()%2; if(b==0){ vv.pb(mp(mp(xor128()%(n-v[i]+1),xor128()%n),0)); } else{ vv.pb(mp(mp(xor128()%n,xor128()%(n-v[i]+1)),1)); } } vector vs1 = vs; rep(i,0,k){ if(vv[i].se==0){ fh(vv[i].fi.fi,vv[i].fi.se,v[i],vs1); } else{ fv(vv[i].fi.fi,vv[i].fi.se,v[i],vs1); } } ll score1 = f(vs1); if(score1>score){ score = score1; best_vv = vv; } } vector,ll > > vv = best_vv; rep(i,0,best_vv.sz){ if(vv[i].se==0){ cout << vv[i].fi.fi+1 << " " << vv[i].fi.se+1 << " " << vv[i].fi.fi+v[i] << " " << vv[i].fi.se+1 << endl; } else{ cout << vv[i].fi.fi+1 << " " << vv[i].fi.se+1 << " " << vv[i].fi.fi+1 << " " << vv[i].fi.se+v[i] << endl; } } return 0; }