Problem:
E : 台風 / Typhoon
問題文
南北方向に
H
，東西方向に
W
の大きさの町がある． 町には一辺の長さが
1
の正方形の区画に隙間なく整備されており，全ての区画に
1
軒ずつ家が建っている．
この町のある区画の上空で台風が発生し，被害を与えた後，ある区画の上空で温帯低気圧に変化した． 変化した後は被害を与えない． 下図のように，台風は高さ
3
, 幅
3
の正方形であり， ★のついたマスを中心と呼ぶことにする．台風は
8
近傍に区画単位で移動する． つまり，台風の中心は辺または頂点を共有する区画(現在の区画を含む)に移るように，全体を伴って移動する． ただし，町の外に台風がはみ出ることはなく，

台風の中心は，下の図の網掛けのように，北から
0
番目と
H − 1
番目，西から
0
番目と
W − 1
番目の区間は通らないように移動する．
家は台風が一度上空に来ると，以下のように被害の程度が変化する．
損壊ナシ → 一部損壊 → 半壊 → 全壊 → 跡形ナシ
だが，幸い跡形ナシとなった家は無かったようだ． 各家の被害の状況が与えられるので，台風が発生した地点と，温帯低気圧に変化した地点を求めよ． ただし，発生した区画を北から
s_i
番目，西から
s_j
番目， 温帯低気圧に変化した区画を北から
t_i
番目，西から
t_j
番目とすると，
2
つの地点は
10000 t_i + t_j
≤
10000 s_i + s_j
を満たすように定まる．
入力
H \ W
D_{11} \ … \ D_{1W}
D_{21} \ … \ D_{2W}
…
D_{H1} \ … \ D_{HW}
D_{ij}
は北から
i
番目， 西から
j
番目の家の被害の程度を以下のように表す整数である．
0
: 損壊ナシ
1
: 一部損壊
2
: 半壊
3
: 全壊
制約
整数である
入力は答えが一意に定まるようなもののみ与えられる
3 ≤ H,W ≤ 500
0 ≤ D_{ij} ≤ 3
出力
答えを以下のように
1
行で出力せよ．
s_i \ s_j \ t_i \ t_j
サンプル
サンプル入力1
7 5
0 0 0 0 0
0 1 1 1 0
0 2 2 2 0
0 3 3 3 0
0 2 2 2 0
0 1 1 1 0
0 0 0 0 0
サンプル出力1
4 2 2 2
サンプル入力2
6 6
0 0 0 1 1 1
0 0 0 2 2 2
0 0 1 3 3 2
1 2 3 3 2 1
1 2 3 2 1 0
1 2 2 1 0 0
サンプル出力2
4 1 1 4
サンプル入力3
4 4
2 2 2 0
2 2 2 0
2 2 2 0
0 0 0 0
サンプル出力3
1 1 1 1

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define FOR(i,s,t )for(int i = s; i <t ; i++)
using LL = long long; using ll = LL;
using PLL = pair<LL, LL>; using  pll = PLL;
using PII = pair<int, int>; using  pii = PII;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
using VI = vector<int>;
using VVI = vector<VI>;
#define debug(x) cout<<#x<<":="<<x<<endl;

void solve() {
	int H, W; cin >> H >> W;
	VVI m(H, VI(W));
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			cin >> m[i][j];
		}
	}

	VVI cent(H + 10, VI(W + 10, 0));
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (m[i][j]) {
				cent[i + 1][j + 1] = 1;
				int x = m[i][j];
				for (int k = 0; k < 2 + 1; k++) {
					for (int l = 0; l < 2 + 1; l++) {
						m[i+k][j+l] -= x;
					}
				}
			}
		}
	}

	vector<PII>pos;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (cent[i][j]) {
				int cnt = 0;
				for (int k = -1; k < 2 ; k++) {
					for (int l = -1; l < 2; l++) {
						if (cent[i + k][j + l])cnt++;
					}
				}
				if (cnt == 1) {
					pos.push_back(PII(i, j));
				}
				else if (cnt == 2) {
					pos.push_back(PII(i, j));
				}
				else if (cnt == 3) {
					// nashi
				}
				else {
					// nasi
				}
			}
		}
	}
	SORT(pos);
	PII s, t;
	s = pos.back(), t = pos.front();
	cout << s.first << " " << s.second << " " << t.first << " " << t.second << endl;;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5192
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w;
    cin >> h >> w;
    vector<vector<int>> damage(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> damage[i][j];
        }
    }

    // Compute differences along rows
    for (int i = 0; i < h; i++) {
        for (int j = 0; j + 2 < w; j++) {
            damage[i][j + 1] -= damage[i][j];
            damage[i][j + 2] -= damage[i][j];
        }
    }

    // Compute differences along columns
    for (int i = 0; i + 2 < h; i++) {
        for (int j = 0; j < w; j++) {
            damage[i + 1][j] -= damage[i][j];
            damage[i + 2][j] -= damage[i][j];
        }
    }

    vector<int> dx = {1, 1, 1, 0, 0, -1, -1, -1};
    vector<int> dy = {1, 0, -1, 1, -1, 1, 0, -1};

    pair<int,int> start = {-1, -1}, endp = {-1, -1};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (damage[i][j] != 0) {
                int neighbors = 0;
                for (int k = 0; k < 8; k++) {
                    int ni = i + dx[k];
                    int nj = j + dy[k];
                    if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                    neighbors += damage[ni][nj];
                }
                if (neighbors <= 1) {
                    if (start.first == -1) {
                        start = {i + 1, j + 1};
                        endp = start;
                    } else {
                        endp = {i + 1, j + 1};
                    }
                }
            }
        }
    }

    if (make_pair(start.first, start.second) < make_pair(endp.first, endp.second)) {
        swap(start, endp);
    }

    cout << start.first << " " << start.second << " ";
    cout << endp.first << " " << endp.second << "\n";
}
accuracy: 1
time_ms: 10
memory_kb: 4140
final_rank: 1

code_snippet: // AOJ #2756 Typhoon
// 2025.3.2

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int h,w; cin >> h >> w;
    vector<vector<int>> D(h, vector<int>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) cin >> D[i][j];
    }

    vector<vector<int>> X(h, vector<int>(w,0));
    for (int i = 1; i <= h-2; i++){
        for (int j = 1; j <= w-2; j++){
            bool can = true;
            for(int di=-1;di<=1;di++){
                for(int dj=-1;dj<=1;dj++){
                    if(D[i+di][j+dj] <= 0) { can = false; break; }
                }
                if(!can) break;
            }
            if(can){
                X[i][j] = 1;
                for(int di=-1;di<=1;di++){
                    for(int dj=-1;dj<=1;dj++) D[i+di][j+dj]--;
                }
            }
        }
    }

    vector<pair<int,int>> P;
    for(int i=1;i<=h-2;i++){
        for(int j=1;j<=w-2;j++){
            if(X[i][j]==1) P.push_back({i,j});
        }
    }

    int n = P.size();
    vector<vector<int>> adj(n);
    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++){
            int r1 = P[i].first, c1 = P[i].second;
            int r2 = P[j].first, c2 = P[j].second;
            if(abs(r1-r2)<=1 && abs(c1-c2)<=1){
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }
    vector<int> ends;
    for (int i=0;i<n;i++){
        if(n==1 || adj[i].size()==1) ends.push_back(i);
    }

    pair<int,int> s,t;
    if(ends.size()==1) s = P[ends[0]], t = P[ends[0]];
    else {
        pair<int,int> a = P[ends[0]], b = P[ends[1]];
        if(a.first*10000+a.second > b.first*10000+b.second) s = a, t = b;
        else s = b, t = a;
    }
    cout << s.first << " " << s.second << " " << t.first << " " << t.second << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5496
final_rank: 5

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD1 1000000007
#define MOD2 998244353
#define MOD1_BASE 131
#define INF (LLONG_MAX / 2)
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define GET_VALUENAME(value) # value

using namespace std;
using ll = long long;
using LL = __int128_t;
using ull = unsigned long long;

template<typename T> // T:重み
using p_que = priority_queue<T,vector<T>,greater<T>>;

template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

ll modpow(ll a, ll n, ll mod) {ll res=1;while (n>0) {if(n&1)res=(res*(a%mod))%mod;a=((a%mod)*(a%mod))%mod;n>>=1;}return res;}

template<typename T>
void RotateVec2(vector<vector<T>>&v){ll h=v.size();ll w=v[0].size();vector<vector<T>>t(w,vector<T>(h));rep(i,h){rep(j,w){t[j][h-i-1]=v[i][j];}}v=t;}

template<class T>
bool InRange(T x, T mn, T mx){return (mn <= x && x <= mx);}

template<typename T>
vector<T>&merged(vector<T>&a,vector<T>&b) {vector<T>res;merge(a.begin(),a.end(),b.begin(),b.end(),back_inserter(res));return res;}

struct UnionFind{
    vector<ll>tree;
    UnionFind(ll x):tree(x, -1){}
    ll root(ll x){if(tree[x]<0) return x;return tree[x]=root(tree[x]);}
    bool same(ll x,ll y){return root(x)==root(y);}
    ll size(ll x){return -tree[root(x)];}
    void unite(ll x,ll y){x=root(x),y=root(y);if(x==y)return;if(size(x)<size(y))swap(x,y);tree[x]+=tree[y];tree[y]=x;}
};

template<class T>
struct SegTree{
    ll n;T e;vector<T>tree,lazy;function<T(T,T)>f,add;
    SegTree(ll n_,function<T(T,T)>f_,T e_=0,function<T(T,T)>add_=[](T next,T old){return next;}):e(e_),f(f_),add(add_){ll x=1;while(x<n_)x*=2;n=x;tree.assign(n*2,e);lazy.assign(n*2,e);}
    void eval(T k) {if (lazy[k] == e) return;if (k < n-1){lazy[k*2+1]=lazy[k*2+1]=lazy[k];}tree[k]=lazy[k], lazy[k]=e;}
    void update(ll idx,T x){update(idx, idx+1, x);}
    void update(ll a, ll b, ll x) { update(a, b, x, 0, n, 0); }
    void update(ll a, ll b, ll x, ll l, ll r, ll k) {eval(k);if (a <= l and r <= b) {lazy[k] = x;eval(k);}else if (a < r and l < b) {update(a, b, x, l, (l+r)/2, k*2+1);update(a, b, x, (l+r)/2, r, k*2+1);tree[k] = f(tree[k*2+1], tree[k*2+2]);}}
    T query(ll x,ll y){return query_sub(x,y,0,n,0);}
    T query_sub(ll x,ll y,ll l,ll r,ll k){eval(k);if(r<=x||y<=l)return e;if(x<=l&&r<=y)return tree[k];T c1=query_sub(x,y,l,(l+r)/2,k*2+1);T c2=query_sub(x,y,(l+r)/2,r,k*2+2);return f(c1,c2);}
    T get(ll idx){return tree[idx+n-1];}
};

template<std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus)+Modulus)%Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {return modint(*this) += rhs;}
    constexpr modint operator-(const modint rhs) const noexcept {return modint(*this) -= rhs;}
    constexpr modint operator*(const modint rhs) const noexcept {return modint(*this) *= rhs;}
    constexpr modint operator/(const modint rhs) const noexcept {return modint(*this) /= rhs;}
    constexpr modint &operator+=(const modint rhs) noexcept {a += rhs.a;if (a >= Modulus) {a -= Modulus;}return *this;}
    constexpr modint &operator-=(const modint rhs) noexcept {if (a < rhs.a) {a += Modulus;}a -= rhs.a;return *this;}
    constexpr modint &operator*=(const modint rhs) noexcept {a = a * rhs.a % Modulus;return *this;}
    constexpr modint &operator/=(modint rhs) noexcept {u64 exp = Modulus - 2;while (exp) {if (exp % 2) {*this *= rhs;}rhs *= rhs;exp /= 2;}return *this;}
    constexpr modint &operator=(u64 x){ a = x % Modulus; return *this; }
};

template<class T=ll>
struct Vector2D {
    T x, y;
    Vector2D():x(0),y(0) {}
    Vector2D(T x_, T y_):x(x_),y(y_) {}

    double length() const { return sqrt((double)x*x+y*y); };
    T lengthp() const { return x*x+y*y; };
    bool inrange(const Vector2D a, const Vector2D b) { return (InRange(x, a.x, b.x) and InRange(y, a.y, b.y)); }
    Vector2D yx() { return Vector2D{ y, x }; }
    Vector2D operator-(const Vector2D a) const { return Vector2D(*this) -= a; }
    Vector2D operator+(const Vector2D a) const { return Vector2D(*this) += a; }
    T operator*(const Vector2D a) const { return x*a.x+y*a.y; }
    Vector2D operator*(const T a) const { return Vector2D(*this) *= a; }
    Vector2D operator/(const T a) const { return Vector2D(*this) /= a; }
    Vector2D &operator+=(const Vector2D a) { x += a.x; y += a.y; return *this; }
    Vector2D &operator-=(const Vector2D a) { x -= a.x; y -= a.y; return *this; }
    Vector2D &operator-=(const T a) { x -= a; y -= a; return *this; }
    Vector2D &operator*=(const T a) { x *= a; y *= a; return *this; }
    Vector2D &operator/=(const T a) { x /= a; y /= a; return *this; }
    friend ostream& operator<< (ostream& stream, const Vector2D<>& x);
    bool operator==(const Vector2D a) const { return (x==a.x and y==a.y); }
    bool operator!=(const Vector2D a) const { return not (x==a.x and y==a.y); }
    bool operator>(const Vector2D a) const { return a < *this; }
    bool operator<(const Vector2D a) const 
    {
        // return make_pair(x,y) < make_pair(a.x, a.y);
        return x*10000+y<a.x*10000+a.y;
    }
};

ostream& operator<< (ostream& stream, const Vector2D<ll>& x) {
    string s = "(" + to_string(x.x) + ", " + to_string(x.y) + ")";
    stream << s;
    return stream;
}

ll popcount(ll x) { ll res = 0; while(x) {res+=x%2;x>>=1;} return res; }

// debug kit
void print() { cout << endl; }
template<class T>
void print_(vector<T>x) { for(auto i : x) cout << i << " "; }
template<class T>
void print_(T x) { cout << x << " "; }
#ifdef ONLINE_JUDGE 
template<class T, class ...Args>
void print(T head, Args... args) {}
template<class T>
void debug(T value) {}
#else
template<class T, class ...Args>
void print(T head, Args... args) { print_(head); print(args...); }
template<class T>
void debug(T value) { print((string)"\""+GET_VALUENAME(value)+"\": ", value); }
#endif

// MAIN PROGRAM ------------

using mint = modint<MOD1>;
using Vec2 = Vector2D<ll>;
const Vec2 Angle[] = {{0,1}, {0,-1}, {-1,0}, {1,0}};

int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>>s(h, vector<ll>(w));
    vector<Vec2>edge;
    rep(i, h) rep(j, w) cin >> s[i][j];
    rep(i, h) rep(j, w-2)
    {
        if (s[i][j] * s[i][j+1] * s[i][j+2] == 1) 
        {
            if (i==0 or s[i-1][j+1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i-1, j+1});
        }
    }
    rep(i, h-2) rep(j, w)
    {
        if (s[i][j] * s[i+1][j] * s[i+2][j] == 1)
        {
            if (j==0 or s[i+1][j-1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i+1, j-1});
        }
    }
    sort(BACK(edge));

    auto raw = edge;

    edge.erase(unique(ALL(edge)), edge.end());

    if (edge.size() == 0 or edge.size() > 2)
    {
        rep(i_, h-2) rep(j_, w-2)
        {
            ll i = i_+1, j = j_+1;
            ll t = s[i][j];
            rep(x, 3) rep(y, 3) t *= s[i+x-1][j+y-1];
            if (t != 0)
            {
                cout << i << " " << j << " " << i << " " << j << endl;
                return 0;
            }
        }
    }
    if (edge.size() == 1)
    {
        if (raw.size() != edge.size())
        {
            for (auto angle : { Vec2{-1,-1},Vec2{-1, 1},Vec2{ 1,-1},Vec2{ 1, 1}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] != 1) 
                {
                    edge.push_back(a);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
        else
        {
            for (auto angle : { Vec2{ 0,-1},Vec2{ 0, 1},Vec2{ 1, 0},Vec2{ -1, 0}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] == 1) 
                {
                    edge.push_back(edge[0]-angle);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
    }
    if (edge.size() == 2)
    {
        cout << edge[0].x << " " << edge[0].y << " " << edge[1].x << " " << edge[1].y << endl;
    }
}
accuracy: 0.16666666666666666
time_ms: 20
memory_kb: 5332
final_rank: 18

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD1 1000000007
#define MOD2 998244353
#define MOD1_BASE 131
#define INF (LLONG_MAX / 2)
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define GET_VALUENAME(value) # value

using namespace std;
using ll = long long;
using LL = __int128_t;
using ull = unsigned long long;

template<typename T> // T:重み
using p_que = priority_queue<T,vector<T>,greater<T>>;

template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

ll modpow(ll a, ll n, ll mod) {ll res=1;while (n>0) {if(n&1)res=(res*(a%mod))%mod;a=((a%mod)*(a%mod))%mod;n>>=1;}return res;}

template<typename T>
void RotateVec2(vector<vector<T>>&v){ll h=v.size();ll w=v[0].size();vector<vector<T>>t(w,vector<T>(h));rep(i,h){rep(j,w){t[j][h-i-1]=v[i][j];}}v=t;}

template<class T>
bool InRange(T x, T mn, T mx){return (mn <= x && x <= mx);}

template<typename T>
vector<T>&merged(vector<T>&a,vector<T>&b) {vector<T>res;merge(a.begin(),a.end(),b.begin(),b.end(),back_inserter(res));return res;}

struct UnionFind{
    vector<ll>tree;
    UnionFind(ll x):tree(x, -1){}
    ll root(ll x){if(tree[x]<0) return x;return tree[x]=root(tree[x]);}
    bool same(ll x,ll y){return root(x)==root(y);}
    ll size(ll x){return -tree[root(x)];}
    void unite(ll x,ll y){x=root(x),y=root(y);if(x==y)return;if(size(x)<size(y))swap(x,y);tree[x]+=tree[y];tree[y]=x;}
};

template<class T>
struct SegTree{
    ll n;T e;vector<T>tree,lazy;function<T(T,T)>f,add;
    SegTree(ll n_,function<T(T,T)>f_,T e_=0,function<T(T,T)>add_=[](T next,T old){return next;}):e(e_),f(f_),add(add_){ll x=1;while(x<n_)x*=2;n=x;tree.assign(n*2,e);lazy.assign(n*2,e);}
    void eval(T k) {if (lazy[k] == e) return;if (k < n-1){lazy[k*2+1]=lazy[k*2+1]=lazy[k];}tree[k]=lazy[k], lazy[k]=e;}
    void update(ll idx,T x){update(idx, idx+1, x);}
    void update(ll a, ll b, ll x) { update(a, b, x, 0, n, 0); }
    void update(ll a, ll b, ll x, ll l, ll r, ll k) {eval(k);if (a <= l and r <= b) {lazy[k] = x;eval(k);}else if (a < r and l < b) {update(a, b, x, l, (l+r)/2, k*2+1);update(a, b, x, (l+r)/2, r, k*2+1);tree[k] = f(tree[k*2+1], tree[k*2+2]);}}
    T query(ll x,ll y){return query_sub(x,y,0,n,0);}
    T query_sub(ll x,ll y,ll l,ll r,ll k){eval(k);if(r<=x||y<=l)return e;if(x<=l&&r<=y)return tree[k];T c1=query_sub(x,y,l,(l+r)/2,k*2+1);T c2=query_sub(x,y,(l+r)/2,r,k*2+2);return f(c1,c2);}
    T get(ll idx){return tree[idx+n-1];}
};

template<std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus)+Modulus)%Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {return modint(*this) += rhs;}
    constexpr modint operator-(const modint rhs) const noexcept {return modint(*this) -= rhs;}
    constexpr modint operator*(const modint rhs) const noexcept {return modint(*this) *= rhs;}
    constexpr modint operator/(const modint rhs) const noexcept {return modint(*this) /= rhs;}
    constexpr modint &operator+=(const modint rhs) noexcept {a += rhs.a;if (a >= Modulus) {a -= Modulus;}return *this;}
    constexpr modint &operator-=(const modint rhs) noexcept {if (a < rhs.a) {a += Modulus;}a -= rhs.a;return *this;}
    constexpr modint &operator*=(const modint rhs) noexcept {a = a * rhs.a % Modulus;return *this;}
    constexpr modint &operator/=(modint rhs) noexcept {u64 exp = Modulus - 2;while (exp) {if (exp % 2) {*this *= rhs;}rhs *= rhs;exp /= 2;}return *this;}
    constexpr modint &operator=(u64 x){ a = x % Modulus; return *this; }
};

template<class T=ll>
struct Vector2D {
    T x, y;
    Vector2D():x(0),y(0) {}
    Vector2D(T x_, T y_):x(x_),y(y_) {}

    double length() const { return sqrt((double)x*x+y*y); };
    T lengthp() const { return x*x+y*y; };
    bool inrange(const Vector2D a, const Vector2D b) { return (InRange(x, a.x, b.x) and InRange(y, a.y, b.y)); }
    Vector2D yx() { return Vector2D{ y, x }; }
    Vector2D operator-(const Vector2D a) const { return Vector2D(*this) -= a; }
    Vector2D operator+(const Vector2D a) const { return Vector2D(*this) += a; }
    T operator*(const Vector2D a) const { return x*a.x+y*a.y; }
    Vector2D operator*(const T a) const { return Vector2D(*this) *= a; }
    Vector2D operator/(const T a) const { return Vector2D(*this) /= a; }
    Vector2D &operator+=(const Vector2D a) { x += a.x; y += a.y; return *this; }
    Vector2D &operator-=(const Vector2D a) { x -= a.x; y -= a.y; return *this; }
    Vector2D &operator-=(const T a) { x -= a; y -= a; return *this; }
    Vector2D &operator*=(const T a) { x *= a; y *= a; return *this; }
    Vector2D &operator/=(const T a) { x /= a; y /= a; return *this; }
    friend ostream& operator<< (ostream& stream, const Vector2D<>& x);
    bool operator==(const Vector2D a) const { return (x==a.x and y==a.y); }
    bool operator!=(const Vector2D a) const { return not (x==a.x and y==a.y); }
    bool operator>(const Vector2D a) const { return a < *this; }
    bool operator<(const Vector2D a) const 
    {
        // return make_pair(x,y) < make_pair(a.x, a.y);
        return x*10000+y<a.x*10000+a.y;
    }
};

ostream& operator<< (ostream& stream, const Vector2D<ll>& x) {
    string s = "(" + to_string(x.x) + ", " + to_string(x.y) + ")";
    stream << s;
    return stream;
}

ll popcount(ll x) { ll res = 0; while(x) {res+=x%2;x>>=1;} return res; }

// debug kit
void print() { cout << endl; }
template<class T>
void print_(vector<T>x) { for(auto i : x) cout << i << " "; }
template<class T>
void print_(T x) { cout << x << " "; }
#ifdef ONLINE_JUDGE 
template<class T, class ...Args>
void print(T head, Args... args) {}
template<class T>
void debug(T value) {}
#else
template<class T, class ...Args>
void print(T head, Args... args) { print_(head); print(args...); }
template<class T>
void debug(T value) { print((string)"\""+GET_VALUENAME(value)+"\": ", value); }
#endif

// MAIN PROGRAM ------------

using mint = modint<MOD1>;
using Vec2 = Vector2D<ll>;
const Vec2 Angle[] = {{0,1}, {0,-1}, {-1,0}, {1,0}};

int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>>s(h, vector<ll>(w));
    vector<Vec2>edge;
    rep(i, h) rep(j, w) cin >> s[i][j];
    rep(i, h) rep(j, w-2)
    {
        if (s[i][j] * s[i][j+1] * s[i][j+2] == 1) 
        {
            if (i==0 or s[i-1][j+1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i-1, j+1});
        }
    }
    rep(i, h-2) rep(j, w)
    {
        if (s[i][j] * s[i+1][j] * s[i+2][j] == 1)
        {
            if (j==0 or s[i+1][j-1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i+1, j-1});
        }
    }
    sort(BACK(edge));

    auto raw = edge;

    edge.erase(unique(ALL(edge)), edge.end());

    if (edge.size() == 0)
    {
        rep(i_, h-2) rep(j_, w-2)
        {
            ll i = i_+1, j = j_+1;
            ll t = 1;
            rep(x, 3) rep(y, 3) t *= s[i+x-1][j+y-1];
            if (t != 0)
            {
                cout << i << " " << j << " " << i << " " << j << endl;
                return 0;
            }
        }
    }
    if (edge.size() == 1)
    {
        if (raw.size() != edge.size())
        {
            for (auto angle : { Vec2{-1,-1},Vec2{-1, 1},Vec2{ 1,-1},Vec2{ 1, 1}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] != 1) 
                {
                    edge.push_back(a);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
        else
        {
            for (auto angle : { Vec2{ 0,-1},Vec2{ 0, 1},Vec2{ 1, 0},Vec2{ -1, 0}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] == 1) 
                {
                    edge.push_back(edge[0]-angle);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
    }
    if (edge.size() == 2)
    {
        cout << edge[0].x << " " << edge[0].y << " " << edge[1].x << " " << edge[1].y << endl;
    }
}
accuracy: 0.16666666666666666
time_ms: 20
memory_kb: 5112
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD1 1000000007
#define MOD2 998244353
#define MOD1_BASE 131
#define INF (LLONG_MAX / 2)
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define GET_VALUENAME(value) # value

using namespace std;
using ll = long long;
using LL = __int128_t;
using ull = unsigned long long;

template<typename T> // T:重み
using p_que = priority_queue<T,vector<T>,greater<T>>;

template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

ll modpow(ll a, ll n, ll mod) {ll res=1;while (n>0) {if(n&1)res=(res*(a%mod))%mod;a=((a%mod)*(a%mod))%mod;n>>=1;}return res;}

template<typename T>
void RotateVec2(vector<vector<T>>&v){ll h=v.size();ll w=v[0].size();vector<vector<T>>t(w,vector<T>(h));rep(i,h){rep(j,w){t[j][h-i-1]=v[i][j];}}v=t;}

template<class T>
bool InRange(T x, T mn, T mx){return (mn <= x && x <= mx);}

template<typename T>
vector<T>&merged(vector<T>&a,vector<T>&b) {vector<T>res;merge(a.begin(),a.end(),b.begin(),b.end(),back_inserter(res));return res;}

struct UnionFind{
    vector<ll>tree;
    UnionFind(ll x):tree(x, -1){}
    ll root(ll x){if(tree[x]<0) return x;return tree[x]=root(tree[x]);}
    bool same(ll x,ll y){return root(x)==root(y);}
    ll size(ll x){return -tree[root(x)];}
    void unite(ll x,ll y){x=root(x),y=root(y);if(x==y)return;if(size(x)<size(y))swap(x,y);tree[x]+=tree[y];tree[y]=x;}
};

template<class T>
struct SegTree{
    ll n;T e;vector<T>tree,lazy;function<T(T,T)>f,add;
    SegTree(ll n_,function<T(T,T)>f_,T e_=0,function<T(T,T)>add_=[](T next,T old){return next;}):e(e_),f(f_),add(add_){ll x=1;while(x<n_)x*=2;n=x;tree.assign(n*2,e);lazy.assign(n*2,e);}
    void eval(T k) {if (lazy[k] == e) return;if (k < n-1){lazy[k*2+1]=lazy[k*2+1]=lazy[k];}tree[k]=lazy[k], lazy[k]=e;}
    void update(ll idx,T x){update(idx, idx+1, x);}
    void update(ll a, ll b, ll x) { update(a, b, x, 0, n, 0); }
    void update(ll a, ll b, ll x, ll l, ll r, ll k) {eval(k);if (a <= l and r <= b) {lazy[k] = x;eval(k);}else if (a < r and l < b) {update(a, b, x, l, (l+r)/2, k*2+1);update(a, b, x, (l+r)/2, r, k*2+1);tree[k] = f(tree[k*2+1], tree[k*2+2]);}}
    T query(ll x,ll y){return query_sub(x,y,0,n,0);}
    T query_sub(ll x,ll y,ll l,ll r,ll k){eval(k);if(r<=x||y<=l)return e;if(x<=l&&r<=y)return tree[k];T c1=query_sub(x,y,l,(l+r)/2,k*2+1);T c2=query_sub(x,y,(l+r)/2,r,k*2+2);return f(c1,c2);}
    T get(ll idx){return tree[idx+n-1];}
};

template<std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus)+Modulus)%Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {return modint(*this) += rhs;}
    constexpr modint operator-(const modint rhs) const noexcept {return modint(*this) -= rhs;}
    constexpr modint operator*(const modint rhs) const noexcept {return modint(*this) *= rhs;}
    constexpr modint operator/(const modint rhs) const noexcept {return modint(*this) /= rhs;}
    constexpr modint &operator+=(const modint rhs) noexcept {a += rhs.a;if (a >= Modulus) {a -= Modulus;}return *this;}
    constexpr modint &operator-=(const modint rhs) noexcept {if (a < rhs.a) {a += Modulus;}a -= rhs.a;return *this;}
    constexpr modint &operator*=(const modint rhs) noexcept {a = a * rhs.a % Modulus;return *this;}
    constexpr modint &operator/=(modint rhs) noexcept {u64 exp = Modulus - 2;while (exp) {if (exp % 2) {*this *= rhs;}rhs *= rhs;exp /= 2;}return *this;}
    constexpr modint &operator=(u64 x){ a = x % Modulus; return *this; }
};

template<class T=ll>
struct Vector2D {
    T x, y;
    Vector2D():x(0),y(0) {}
    Vector2D(T x_, T y_):x(x_),y(y_) {}

    double length() const { return sqrt((double)x*x+y*y); };
    T lengthp() const { return x*x+y*y; };
    bool inrange(const Vector2D a, const Vector2D b) { return (InRange(x, a.x, b.x) and InRange(y, a.y, b.y)); }
    Vector2D yx() { return Vector2D{ y, x }; }
    Vector2D operator-(const Vector2D a) const { return Vector2D(*this) -= a; }
    Vector2D operator+(const Vector2D a) const { return Vector2D(*this) += a; }
    T operator*(const Vector2D a) const { return x*a.x+y*a.y; }
    Vector2D operator*(const T a) const { return Vector2D(*this) *= a; }
    Vector2D operator/(const T a) const { return Vector2D(*this) /= a; }
    Vector2D &operator+=(const Vector2D a) { x += a.x; y += a.y; return *this; }
    Vector2D &operator-=(const Vector2D a) { x -= a.x; y -= a.y; return *this; }
    Vector2D &operator-=(const T a) { x -= a; y -= a; return *this; }
    Vector2D &operator*=(const T a) { x *= a; y *= a; return *this; }
    Vector2D &operator/=(const T a) { x /= a; y /= a; return *this; }
    friend ostream& operator<< (ostream& stream, const Vector2D<>& x);
    bool operator==(const Vector2D a) const { return (x==a.x and y==a.y); }
    bool operator!=(const Vector2D a) const { return not (x==a.x and y==a.y); }
    bool operator>(const Vector2D a) const { return a < *this; }
    bool operator<(const Vector2D a) const 
    {
        return make_pair(x,y) < make_pair(a.x, a.y);
        // return x*a.y < y*a.x;
    }
};

ostream& operator<< (ostream& stream, const Vector2D<ll>& x) {
    string s = "(" + to_string(x.x) + ", " + to_string(x.y) + ")";
    stream << s;
    return stream;
}

ll popcount(ll x) { ll res = 0; while(x) {res+=x%2;x>>=1;} return res; }

// debug kit
void print() { cout << endl; }
template<class T>
void print_(vector<T>x) { for(auto i : x) cout << i << " "; }
template<class T>
void print_(T x) { cout << x << " "; }
#ifdef ONLINE_JUDGE 
template<class T, class ...Args>
void print(T head, Args... args) {}
template<class T>
void debug(T value) {}
#else
template<class T, class ...Args>
void print(T head, Args... args) { print_(head); print(args...); }
template<class T>
void debug(T value) { print((string)"\""+GET_VALUENAME(value)+"\": ", value); }
#endif

// MAIN PROGRAM ------------

using mint = modint<MOD1>;
using Vec2 = Vector2D<ll>;
const Vec2 Angle[] = {{0,1}, {0,-1}, {-1,0}, {1,0}};

int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>>s(h, vector<ll>(w));
    vector<Vec2>edge;
    rep(i, h) rep(j, w) cin >> s[i][j];
    rep(i, h) rep(j, w-2)
    {
        if (s[i][j] * s[i][j+1] * s[i][j+2] == 1) 
        {
            if (i==0 or s[i-1][j+1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i-1, j+1});
        }
    }
    rep(i, h-2) rep(j, w)
    {
        if (s[i][j] * s[i+1][j] * s[i+2][j] == 1)
        {
            if (j==0 or s[i+1][j-1]==0) edge.push_back(Vec2{i+1, j+1});
            else edge.push_back(Vec2{i+1, j-1});
        }
    }
    sort(BACK(edge));

    auto raw = edge;

    edge.erase(unique(ALL(edge)), edge.end());

    if (edge.size() == 0)
    {
        rep(i_, h-2) rep(j_, w-2)
        {
            ll i = i_+1, j = j_+1;
            ll t = 1;
            rep(x, 3) rep(y, 3) t *= s[i+x-1][j+y-1];
            if (t != 0)
            {
                cout << i << " " << j << " " << i << " " << j << endl;
                return 0;
            }
        }
    }
    if (edge.size() == 1)
    {
        if (raw.size() != edge.size())
        {
            for (auto angle : { Vec2{-1,-1},Vec2{-1, 1},Vec2{ 1,-1},Vec2{ 1, 1}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] != 1) 
                {
                    edge.push_back(a);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
        else
        {
            for (auto angle : { Vec2{ 0,-1},Vec2{ 0, 1},Vec2{ 1, 0},Vec2{ -1, 0}, })
            {
                auto a = edge[0]+angle;
                if (not a.inrange({0,0},{h-1,w-1})) continue;
                if (s[a.x][a.y] == 1) 
                {
                    edge.push_back(edge[0]-angle);
                    break;
                }
            }
            sort(ALL(edge));
            cout << edge[1].x << " " << edge[1].y << " " << edge[0].x << " " << edge[0].y << endl;
            return 0;
        }
    }
    if (edge.size() == 2)
    {
        cout << edge[0].x << " " << edge[0].y << " " << edge[1].x << " " << edge[1].y << endl;
    }
}
accuracy: 0.16666666666666666
time_ms: 10
memory_kb: 5052
final_rank: 14

code_snippet: #include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll h, w, sum = 0;
vector<vector<ll>> s;

bool isValid(ll x, ll y){
    if (1 <= x and x < h - 1 and 1 <= y and y <= h - 1) return true;
    return false;
}
bool isTyph(ll x, ll y){
    if (!isValid(x, y)) return false;
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (s[x + k][y + l] == 0) return false;
        }
    }
    return true;
}
void addTyph(ll x, ll y, ll a){
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            s[x + k][y + l] += a;
        }
    }
    sum += 9 * a;
}
P dfs(ll x, ll y, ll c){
    if(c == 0){
        if(!isTyph(x, y)){
            return P(-1, -1);
        }
        addTyph(x, y, -1);
        P res = dfs(x, y, 1);
        addTyph(x, y, 1);
        return res;
    }
    if (sum == 0) return P(x, y);
    if (c >= 3) return P(-1, -1);
    P res = P(-1, -1);
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (!isTyph(x + k, y + l)) continue;
            addTyph(x + k, y + l, -1);
            P nres = dfs(x + k, y + l, c + 1);
            if (nres != P(-1, -1)) res = nres;
            addTyph(x + k, y + l, 1);
        }
    }
    return res;
}
int main(){
    cin >> h >> w;
    s.resize(h);
    REP(i, h){
        REP(j, w){
            ll a;
            cin >> a;
            s[i].push_back(a);
            sum += a;
        }
    }
    //全探索, 3回まで
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            P res = dfs(i, j, 0);
            if(res != P(-1, -1)){
                if(i * 10000 + j >=res.first * 10000 + res.second ) cout << i << " " << j << " " << res.first << " " << res.second << endl;
                else cout << res.first << " " << res.second <<" " <<i << " " << j<< endl;
                return 0;
            }
        }
    }
    vector<P> ans;
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            if (s[i][j] != 2) continue;
            ll c0 = 0, c1 = 0, c3 = 0;
            FOR(k, -1, 2){
                FOR(l, -1, 2){
                    if (s[i + k][j + l] == 0)c0++;
                    if (s[i + k][j + l] == 1)c1++;
                    if (s[i + k][j + l] == 3)c3++;

                }
            }
            if (c1 >= 1 and c3 >= 1 and c0 == 0) ans.push_back(P(i, j));
        }
    }
    sort(ALL(ans));
    cout << ans[1].first  << " " << ans[1].second  << " " << ans[0].first<< " " << ans[0].second << endl;
}
accuracy: 0.16666666666666666
time_ms: 20
memory_kb: 5340
final_rank: 19

code_snippet: #include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll h, w, sum = 0;
vector<vector<ll>> s;

bool isValid(ll x, ll y){
    if (1 <= x and x < h - 1 and 1 <= y and y <= h - 1) return true;
    return false;
}
bool isTyph(ll x, ll y){
    if (!isValid(x, y)) return false;
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (s[x + k][y + l] == 0) return false;
        }
    }
    return true;
}
void addTyph(ll x, ll y, ll a){
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            s[x + k][y + l] += a;
        }
    }
    sum += 9 * a;
}
P dfs(ll x, ll y, ll c){
    if(c == 0){
        if(!isTyph(x, y)){
            return P(-1, -1);
        }
        addTyph(x, y, -1);
        P res = dfs(x, y, 1);
        addTyph(x, y, 1);
        return res;
    }
    if (sum == 0) return P(x, y);
    if (c >= 3) return P(-1, -1);
    P res = P(-1, -1);
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (!isTyph(x + k, y + l)) continue;
            addTyph(x + k, y + l, -1);
            P nres = dfs(x + k, y + l, c + 1);
            if (nres != P(-1, -1)) res = nres;
            addTyph(x + k, y + l, 1);
        }
    }
    return res;
}
int main(){
    cin >> h >> w;
    s.resize(h);
    REP(i, h){
        REP(j, w){
            ll a;
            cin >> a;
            s[i].push_back(a);
            sum += a;
        }
    }
    //全探索, 3回まで
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            P res = dfs(i, j, 0);
            if(res != P(-1, -1)){
                if(i * 10000 + j >=res.first * 10000 + res.second ) cout << i << " " << j << " " << res.first << " " << res.second << endl;
                else cout << res.first << " " << res.second <<" " <<i << " " << j<< endl;
                return 0;
            }
        }
    }
    vector<P> ans;
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            if (s[i][j] != 2) continue;
            ll c0 = 0, c1 = 0, c3 = 0;
            FOR(k, -1, 2){
                FOR(l, -1, 2){
                    if (s[i + k][j + l] == 0)c0++;
                    if (s[i + k][j + l] == 1)c1++;
                    if (s[i + k][j + l] == 3)c3++;

                }
            }
            if (c3 >= 1 and c0 == 0) ans.push_back(P(i, j));
        }
    }
    sort(ALL(ans));
    cout << ans[1].first  << " " << ans[1].second  << " " << ans[0].first<< " " << ans[0].second << endl;
}
accuracy: 0.16666666666666666
time_ms: 20
memory_kb: 5164
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll h, w, sum = 0;
vector<vector<ll>> s;

bool isValid(ll x, ll y){
    if (1 <= x and x < h - 1 and 1 <= y and y <= h - 1) return true;
    return false;
}
bool isTyph(ll x, ll y){
    if (!isValid(x, y)) return false;
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (s[x + k][y + l] == 0) return false;
        }
    }
    return true;
}
void addTyph(ll x, ll y, ll a){
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            s[x + k][y + l] += a;
        }
    }
    sum += 9 * a;
}
P dfs(ll x, ll y, ll c){
    if(c == 0){
        if(!isTyph(x, y)){
            return P(-1, -1);
        }
        addTyph(x, y, -1);
        P res = dfs(x, y, 1);
        addTyph(x, y, 1);
        return res;
    }
    if (sum == 0) return P(x, y);
    if (c >= 3) return P(-1, -1);
    P res = P(-1, -1);
    FOR(k, -1, 2){
        FOR(l, -1, 2){
            if (!isTyph(x + k, y + l)) continue;
            addTyph(x + k, y + l, -1);
            P nres = dfs(x + k, y + l, c + 1);
            if (nres != P(-1, -1)) res = nres;
            addTyph(x + k, y + l, 1);
        }
    }
    return res;
}
int main(){
    cin >> h >> w;
    s.resize(h);
    REP(i, h){
        REP(j, w){
            ll a;
            cin >> a;
            s[i].push_back(a);
            sum += a;
        }
    }
    //全探索, 3回まで
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            P res = dfs(i, j, 0);
            if(res != P(-1, -1)){
                if(i * 10000 + j >=res.first * 10000 + res.second ) cout << i << " " << j << " " << res.first << " " << res.second << endl;
                else cout << res.first << " " << res.second <<" " <<i << " " << j<< endl;
                return 0;
            }
        }
    }
    vector<P> ans;
    FOR(i, 1, h - 1){
        FOR(j, 1, w - 1){
            if (s[i][j] != 2) continue;
            ll c0 = 0, c1 = 0, c3 = 0;
            FOR(k, -1, 2){
                FOR(l, -1, 2){
                    if (s[i + k][j + l] == 0)c0++;
                    if (s[i + k][j + l] == 1)c1++;
                    if (s[i + k][j + l] == 3)c3++;

                }
            }
            if (c1 >= 3 and c3 >= 1 and c0 == 0) ans.push_back(P(i, j));
        }
    }
    sort(ALL(ans));
    cout << ans[1].first  << " " << ans[1].second  << " " << ans[0].first<< " " << ans[0].second << endl;
}
accuracy: 0.16666666666666666
time_ms: 20
memory_kb: 5368
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
using ll = long long;
using ld = long double;
const ll INF = (1ll<<61) - 1;
template<class T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
#define all(p) p.begin(),p.end()



int main(){
    int H,W;
    cin>>H>>W;
    vector A(H+1,vector<ll>(W+1));
    rep(i,0,H) rep(j,0,W) cin>>A[i][j];
    vector B(H+1,vector<ll>(W+1));
    rep(i,0,H) rep(j,0,W-1) B[i][j+1]=A[i][j+1]-A[i][j];
    rep(i,0,H) B[i][0]=A[i][0];
    swap(A,B);
    rep(i,0,H) rep(j,0,W) B[i][j]=0;
    rep(i,0,H-1) rep(j,0,W) B[i+1][j]=A[i+1][j]-A[i][j];
    rep(j,0,W) B[0][j]=A[0][j];
    swap(A,B);
    rep(i,0,H+1) rep(j,0,W+1) B[i][j]=0;

    rep(i,0,H) rep(j,0,W) if(A[i][j]){
        B[i][j]=A[i][j];
        A[i][j+3]+=A[i][j];
    }
    swap(A,B);
    rep(i,0,H+1) rep(j,0,W+1) B[i][j]=0;

    rep(i,0,H) rep(j,0,W) if(A[i][j]){
        B[i][j]=A[i][j];
        A[i+3][j]+=A[i][j];
    }
    swap(A,B);
    rep(i,0,H) rep(j,0,W) B[i][j]=0;

    vector<pair<int,int>> s;
    vector<int> dx={1,-1,0,0,1,1,-1,-1},dy={0,0,1,-1,1,-1,-1,1};
    rep(i,0,H) rep(j,0,W) if(A[i][j]){
        int x=0;
        rep(k,0,8){
            int a=i+dx[k],b=j+dy[k];
            if(min(a,b)==-1) continue;
            x+=A[a][b];
        }
        if(x<2) s.push_back({i+1,j+1});
    }
    if(int(s.size())==1){
        cout<<s[0].first<<" "<<s[0].second<<" "<<s[0].first<<" "<<s[0].second<<"\n";
    }
    else{
        if(s[0]<s[1]) swap(s[0],s[1]);
        cout<<s[0].first<<" "<<s[0].second<<" "<<s[1].first<<" "<<s[1].second<<"\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 7408
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    vector<vector<int>> b(h, vector<int>(w,0));
    rep(i,0,h){
        rep(j,0,w){
            cin >> a[i][j];
        }
    }

    rep(i,0,h-2){
        rep(j,0,w-2){
            while(a[i][j] > 0){
                rep(k,0,3){
                    rep(l,0,3){
                        a[i+k][j+l]--;
                    }
                }
                b[i+1][j+1]++;
            }
        }
    }

    vector<pair<int,int>> kouho;
    vector<pair<int,int>> s;

    rep(i,1,h-1){
        rep(j,1,w-1){
            int res = 0;
            rep(k,-1,2){
                rep(l,-1,2){
                    if(k == 0 && l == 0) continue;
                    if(b[i+k][j+l] == 0){
                        res++;
                    }
                }
            }
            if(b[i][j] && res >= 6){
                if(res == 6)kouho.push_back({i,j});
                else s.push_back({i,j});
            }
        }
    }

    while(s.size() < 2 && kouho.size() > 0){
        s.push_back(kouho.back());
        kouho.pop_back();
    }
    while(s.size() < 2){
        s.push_back(s.back());
    }

    sort(all(s));
    swap(s[0],s[1]);

    cout << s[0].first << " " << s[0].second << " " << s[1].first << " " << s[1].second << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5456
final_rank: 6

code_snippet: #include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>H>>W;
	vector<vector<int>>v(H,vector<int>(W));
	for(auto &i:v)for(auto &j:i)cin>>j;
	vector<vector<int>>visited(H,vector<int>(W));
	for(int i=0;i<H-2;i++){
		for(int j=0;j<W-2;j++){
			while(v[i][j]){
				visited[i+1][j+1]++;
				for(int k=0;k<3;k++){
					for(int l=0;l<3;l++){
						v[i+k][j+l]--;
					}
				}
			}
		}
	}
	vector<pair<int,int>>two;
	vector<pair<int,int>>one;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(!visited[i][j])continue;
			if(visited[i][j]==1){
				int sum=0;
				for(int k=-1;k<=1;k++){
					for(int l=-1;l<=1;l++){
						sum+=visited[i+k][j+l];
					}
				}
				if(sum<3){
					one.push_back({i,j});
				}
			}
			else{
				two.push_back({i,j});
			}
		}
	}
	vector<pair<int,int>>ans;
	for(auto i:one)ans.push_back(i);
	for(auto i:two)ans.push_back(i);
	if(ans.size()==1&&!two.empty()){
		ans.push_back(two[0]);
	}
	sort(ans.begin(),ans.end());
	cout<<ans[1].first<<" "<<ans[1].second<<" "<<ans[0].first<<" "<<ans[0].second<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4972
final_rank: 2

code_snippet: #include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

using ARRAY = vector<int>;
using CONTAINER = vector<ARRAY>;
using POS = pair<size_t, size_t>;

int dx[] = {-1,0,1,-1,0,1,-1,0,1};
int dy[] = {1,1,1,0,0,0,-1,-1,-1};

bool isMatch(const CONTAINER &m, size_t h, size_t w){
	vector<vector<vector<bool>>> f({ {{1,1,0}, {1,0,0}, {0,0,0}} });
	for(auto e : f){
		bool flag = true;
		for(size_t i = 0; i < 9; i++){
			if(e[1+dx[i]][1+dy[i]]){
				if(m[h+dx[i]][w+dy[i]] != 0){
					flag = false;
					break;
				}
			}
			/*
			else{
				if(m[h+dx[i]][w+dy[j]] == 0){
					flag = false;
					i = j = (size_t)1e9;
					break;
				}
			}
			*/
		}
		if(flag){
//			cerr << h << ":" << w << endl;
			return true;
		}
	}
	return false;
}

void reduce(CONTAINER &m, size_t h, size_t w){
	for(size_t i = 0; i < 9; i++){
		m[h+dx[i]][w+dy[i]] -= 1;
	}
//	cerr << "pass" << endl;
}
			
bool isSwipe(const CONTAINER &m){
	for(auto a : m)for(auto e : a)
		if(e != 0)return false;
	return true;
}

signed main(){
	size_t h,w; cin >> h >> w;
	CONTAINER m(h+2, ARRAY(w+2,0));
	CONTAINER p(m);

	for(size_t i = 1; i <= h; i++)for(size_t j = 1; j <= w; j++)cin >> m[i][j];
//	for(auto a : m){for(auto e : a)cerr << e << " ";cerr << endl;}

	while(!isSwipe(m)){
		for(size_t i = 1; i <= h; i++){
			for(size_t j = 1; j <= w; j++){
				if(m[i][j] > 0 && isMatch(m,i,j)){
					size_t r = i+1, c = j+1;
					p[r][c] += 1;
					reduce(m, r, c);
//					for(auto a : m){for(auto e : a)cerr << e << " ";cerr << endl;}
					break;
				}
			}
		}
	}

//	for(auto a : p){for(auto e : a)cerr << e << " ";cerr << endl;}
	vector<POS> ans;
	{
		int acc = 0;
		for(auto a : p)for(auto e : a)if(e > 0)acc++;
		if(acc == 1){
		for(size_t i = 1; i <= h; i++){
			for(size_t j = 1; j <= w; j++){
				if(p[i][j] > 0){
					cout << (i-1) << " " << (j-1) << " ";
					cout << (i-1) << " " << (j-1) << endl;
					return 0;
				}
			}
		}
		}
	}
			
	for(size_t i = 1; i <= h; i++){
		for(size_t j = 1; j <= w; j++){
			if(p[i][j] > 0){
				int acc = 0;
				for(size_t k = 0; k < 9; k++){
					if(p[i+dx[k]][j+dy[k]] > 0)acc++;
				}
				if(acc == 2)ans.push_back({i,j});
			}
		}
	}
	if(ans[0].first*10000 + ans[0].second < ans[1].first*10000 + ans[1].second){
		swap(ans[0], ans[1]);
	}
	cout << (ans[0].first-1) << " " << (ans[0].second-1) << " ";
	cout << (ans[1].first-1) << " " << (ans[1].second-1) << endl;
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4976
final_rank: 9

code_snippet: #include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>

constexpr size_t m1 = -1;
constexpr size_t di[] = {m1, m1, m1, 0, 0, 1, 1, 1};
constexpr size_t dj[] = {m1, 0, 1, m1, 1, m1, 0, 1};

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  std::vector<std::vector<int>> s(h, std::vector<int>(w));
  for (auto& si: s)
    for (auto& sij: si)
      scanf("%d", &sij);

  std::vector<std::vector<size_t>> t(h, std::vector<size_t>(w));

  for (size_t i = 1; i+1 < h; ++i)
    for (size_t j = 1; j+1 < w; ++j) {
      int c;
      do {
        c = 0;
        for (int k = 0; k < 8; ++k) {
          size_t ni = i + di[k];
          size_t nj = j + dj[k];
          if (s[ni][nj] > 0) ++c;
        }
        if (c < 8) break;
        ++t[i][j];
        for (int k = 0; k < 8; ++k) {
          size_t ni = i + di[k];
          size_t nj = j + dj[k];
          --s[ni][nj];
        }
        break;
      } while (c == 8);
    }

  std::vector<std::pair<size_t, size_t>> res;
  for (size_t i = 1; i+1 < h; ++i)
    for (size_t j = 1; j+1 < w; ++j) {
      if (!t[i][j]) continue;
      int c = 0;
      for (int k = 0; k < 8; ++k) {
        size_t ni = i + di[k];
        size_t nj = j + dj[k];
        if (t[ni][nj] > 0) ++c;
      }
      if (c <= 1) res.emplace_back(i, j);
    }

  // if (res.size() > 1)
  //   if (res[0] < res[1]) std::swap(res[0], res[1]);

  size_t si, sj, ti, tj;
  std::tie(si, sj) = res.front();
  std::tie(ti, tj) = res.back();

  if (!(10000*ti + tj <= 10000*si + sj)) {
    std::swap(si, ti);
    std::swap(sj, tj);
  }

  printf("%zu %zu %zu %zu\n", si, sj, ti, tj);
}
accuracy: 0.375
time_ms: 10
memory_kb: 5348
final_rank: 10

code_snippet: #include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>

constexpr size_t m1 = -1;
constexpr size_t di[] = {m1, m1, m1, 0, 0, 1, 1, 1};
constexpr size_t dj[] = {m1, 0, 1, m1, 1, m1, 0, 1};

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  std::vector<std::vector<int>> s(h, std::vector<int>(w));
  for (auto& si: s)
    for (auto& sij: si)
      scanf("%d", &sij);

  std::vector<std::vector<size_t>> t(h, std::vector<size_t>(w));

  for (size_t i = 1; i+1 < h; ++i)
    for (size_t j = 1; j+1 < w; ++j) {
      int c;
      do {
        c = 0;
        for (int k = 0; k < 8; ++k) {
          size_t ni = i + di[k];
          size_t nj = j + dj[k];
          if (s[ni][nj] > 0) ++c;
        }
        if (c < 8) break;
        ++t[i][j];
        for (int k = 0; k < 8; ++k) {
          size_t ni = i + di[k];
          size_t nj = j + dj[k];
          --s[ni][nj];
        }
        // fprintf(stderr, "+ (%zu, %zu)\n", i, j);
      } while (c == 8);
    }

  std::vector<std::pair<size_t, size_t>> res;
  for (size_t i = 1; i+1 < h; ++i)
    for (size_t j = 1; j+1 < w; ++j) {
      if (!t[i][j]) continue;
      int c = 0;
      for (int k = 0; k < 8; ++k) {
        size_t ni = i + di[k];
        size_t nj = j + dj[k];
        if (t[ni][nj] > 0) ++c;
      }
      // fprintf(stderr, "(%zu, %zu): %d\n", i, j, c);
      if (c <= 1) res.emplace_back(i, j);
    }

  if (res.size() > 1)
    if (res[0] < res[1]) std::swap(res[0], res[1]);

  size_t si, sj, ti, tj;
  std::tie(si, sj) = res.front();
  std::tie(ti, tj) = res.back();

  printf("%zu %zu %zu %zu\n", si, sj, ti, tj);
}
accuracy: 0.16666666666666666
time_ms: 10
memory_kb: 5188
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int H, W, A[515][515]; bool used[515][515];
int dx[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
vector<pair<int, int>>vec; pair<int, int>C;

bool isOK(int px, int py) {
	if (px <= 0 || py <= 0 || px >= H - 1 || py >= W - 1) return false;
	if (A[px][py] <= 1) return false;
	for (int i = 0; i < 8; i++) {
		if (A[px + dx[i]][py + dy[i]] == 0) return false;
	}
	return true;
}

int main() {
	//FILE *in = freopen("in1.txt", "r", stdin);
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) cin >> A[i][j];
	}
	for (int i = 1; i < H - 1; i++) {
		for (int j = 1; j < W - 1; j++) {
			int cnt = 0, R[4] = { 0, 0, 0, 0 };
			for (int k = 0; k < 8; k++) {
				if (isOK(i + dx[k], j + dy[k]) == true) cnt++;
				R[A[i + dx[k]][j + dy[k]]]++;
			}
			if (isOK(i, j) == 0) cnt = 0;
			if (cnt == 1 && A[i][j] == 2 && R[3] <= 3 && R[0] == 0) vec.push_back(make_pair(i, j));
			if (R[0] == 0) C = make_pair(i, j);
		}
	}

	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	if (vec.size() == 0) cout << C.first << " " << C.second << " " << C.first << " " << C.second << endl;
	if (vec.size() == 1) cout << vec[0].first << " " << vec[0].second << " " << vec[0].first << " " << vec[0].second << endl;
	if (vec.size() == 2) cout << vec[0].first << " " << vec[0].second << " " << vec[1].first << " " << vec[1].second << endl;
	return 0;
}
accuracy: 0.2916666666666667
time_ms: 30
memory_kb: 4124
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int H, W, A[515][515]; bool used[515][515];
int dx[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) cin >> A[i][j];
	}
	for (int i = 1; i < H - 1; i++) {
		for (int j = 1; j < W - 1; j++) {
			int cnt = 0;
			for (int k = 0; k < 8; k++) {
				if (A[i + dx[k]][j + dy[k]] == 0) cnt++;
			}
			if (cnt == 0 && A[i][j] >= 1) used[i][j] = true;
		}
	}
	vector<pair<int, int>>vec;
	for (int i = 1; i < H - 1; i++) {
		for (int j = 1; j < W - 1; j++) {
			if (used[i][j] == false) continue;
			int cnt = 0;
			for (int k = 0; k < 8; k++) {
				if (used[i + dx[k]][j + dy[k]] == true) cnt++;
			}
			if (cnt == 0) { vec.push_back(make_pair(i, j)); vec.push_back(make_pair(i, j)); }
			if (cnt == 1) { vec.push_back(make_pair(i, j)); }
		}
	}
	sort(vec.begin(), vec.end());

	cout << vec[1].first << " " << vec[1].second << " " << vec[0].first << " " << vec[0].second << endl;
	return 0;
}
accuracy: 0.25
time_ms: 30
memory_kb: 4288
final_rank: 12

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2756>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ================================================================
 */

vector<int> solve(){
    vector<int> res;
    int H,W; cin >> H >> W;
    vector<vector<int>> D(H,vector<int>(W));
    for(auto& vec:D) for(auto& in:vec) cin >> in;
    vector<vector<int>> couho(H,vector<int>(W,0));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W;j++){
            if(D[i][j] == 0) continue;
            if(D[i][j] != 0){
                int cost = D[i][j];
                for(int k = 0; k < 3;k++){
                    for(int l = 0; l < 3;l++){
                        D[i+k][j+l] -= cost;
                    }
                }
                couho[i+1][j+1]++;
            }
        }
    }
    vector<pii> loc;
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            if(couho[i][j]){
                int cnt = 0;
                for(int k = -1; k <= 1; k++){
                    for(int l = -1; l <= 1; l++){
                        if(couho[i+k][j+l]) cnt++;
                    }
                }
                if(cnt <= 2){
                    loc.push_back({i,j});
                }
            }
        }
    }
    sort(loc.rbegin(),loc.rend());
    res = vector<int>{loc.begin()->first,loc.begin()->second,loc.rbegin()->first,loc.rbegin()->second};
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4984
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2756>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ================================================================
 */

vector<int> solve(){
    vector<int> res;
    int H,W; cin >> H >> W;
    vector<vector<int>> D(H,vector<int>(W));
    for(auto& vec:D) for(auto& in:vec) cin >> in;
    vector<vector<int>> couho(H,vector<int>(W,0));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W;j++){
            if(D[i][j] == 0) continue;
            if(D[i][j] != 0){
                int cost = D[i][j];
                for(int k = 0; k < 3;k++){
                    for(int l = 0; l < 3;l++){
                        D[i+k][j+l] -= cost;
                    }
                }
                couho[i+1][j+1]++;
            }
        }
    }
    [&](){
        for(int i = H-1; i >= 0; i--){
            for(int j = 0; j < W;j++){
                if(couho[i][j]){
                    res.push_back(i);
                    res.push_back(j);
                    return;
                }
            }
        }
    }();
    [&](){
        for(int i = 0; i < H; i++){
            for(int j = W-1; j >= 0;j--){
                if(couho[i][j]){
                    res.push_back(i);
                    res.push_back(j);
                    return;
                }
            }
        }
    }();
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
accuracy: 0.16666666666666666
time_ms: 10
memory_kb: 4980
final_rank: 13

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int H,W;
int table[500][500],calc[500][500],adj_count[500][500];
int diff_row[8] = {-1,-1,-1,0,0,1,1,1},diff_col[8] = {-1,0,1,-1,1,-1,0,1};


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

int main(){

	scanf("%d %d",&H,&W);
	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)scanf("%d",&table[row][col]);
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			calc[row][col] = 0;
		}
	}

	int adj_sum,adj_row,adj_col;

	for(int row = 0; row <= H-2; row++){
		for(int col = 0; col <= W-2; col++){

			adj_sum = 0;
			for(int i = 0; i < 8; i++){
				adj_row = row+diff_row[i];
				adj_col = col+diff_col[i];
				if(rangeCheck(adj_row,adj_col) == false)continue;

				adj_sum += calc[adj_row][adj_col];
			}

			calc[row+1][col+1] = table[row][col]-(calc[row][col]+adj_sum);
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)adj_count[row][col] = 0;
	}

	vector<Info> ANS;
	int count;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(calc[row][col] == 0)continue;

			count = 0;
			for(int i = 0; i < 8; i++){
				adj_row = row+diff_row[i];
				adj_col = col+diff_col[i];

				if(rangeCheck(adj_row,adj_col) == false || calc[adj_row][adj_col] == 0)continue;

				count++;
				if(count >= 2)break;
			}
			if(count <= 1)ANS.push_back(Info(row,col));
		}
	}

	if(ANS.size() == 1){
		printf("%d %d %d %d\n",ANS[0].row,ANS[0].col,ANS[0].row,ANS[0].col);
		return 0;
	}

	if(10000*ANS[1].row+ANS[1].col > 10000*ANS[0].row+ANS[0].col)swap(ANS[0],ANS[1]);

	printf("%d %d %d %d\n",ANS[0].row,ANS[0].col,ANS[1].row,ANS[1].col);

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6156
final_rank: 7