#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a(now-start).count(); return ms; } } bitset<1000> v[1000]; ll n; inline void a(ll r,ll c){ v[r][c].flip(); v[r][(c-1+n)%n].flip(); v[(r-1+n)%n][c].flip(); v[(r-1+n)%n][(c-1+n)%n].flip(); } inline void b(ll r,ll c){ a(r,c); a(r,0); a(0,c); } inline void sa(ll r,ll c,set &st){ st.insert({r,c}); st.insert({(r-1+n)%n,c}); st.insert({r,(c-1+n)%n}); st.insert({(r-1+n)%n,(c-1+n)%n}); } inline int sb(ll r,ll c){ set st; sa(r,c,st); sa(r,0,st); sa(0,c,st); ll ret=0; for(auto [i,j]:st) ret+=v[i][j]; return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; ll pre_score=0; rep(i,n){ rep(j,n){ char c; cin >> c; if(c=='#'){ v[i][j]=1; pre_score++; } } } vector> f(n,vector(n,0)); mt19937 mt; while(true){ ll ms=timer::get(); if(1900<=ms) break; ll i=mt()%n,j=mt()%n; f[i][j]^=1; ll x=sb(i,j); b(i,j); ll y=sb(i,j); ll new_score=pre_score-x+y; double temp=4.0+(0.1-4.0)*(double)ms/1900.0; double prob=exp((double)(pre_score-new_score)/temp); if(1.0*mt()/mt19937::max() ans; rep(i,n){ rep(j,n){ if(f[i][j]) ans.emplace_back(i,j); } } cout << len(ans) << '\n'; for(auto [i,j]:ans){ cout << i << ' ' << j << '\n'; } exit(0); } }