Problem:
Checkered Pattern
You have a cross-section paper with W x H squares, and each of them is painted either in white or black. You want to re-arrange the squares into a neat checkered pattern, in which black and white squares are arranged alternately both in horizontal and vertical directions (the figure shown below is a checkered patter with
W = 5
and
H = 5
). To achieve this goal, you can perform the following two operations as many times you like in an arbitrary sequence: swapping of two arbitrarily chosen columns, and swapping of two arbitrarily chosen rows.
Create a program to determine, starting from the given cross-section paper, if you can re-arrange them into a checkered pattern.
Input
The input is given in the following format.
W
H
c
1,1
c
1,2
...
c
1,W
c
2,1
c
2,2
...
c
2,W
:
c
H,1
c
H,2
...
c
H,W
The first line provides the number of squares in horizontal direction
W
(2≤
W
≤1000) and those in vertical direction
H
(2≤
H
≤1000). Each of subsequent
H
lines provides an array of
W
integers
c
i,j
corresponding to a square of
i
-th row and
j
-th column. The color of the square is white if
c
i,j
is 0, and black if it is 1.
Output
Output "yes" if the goal is achievable and "no" otherwise.
Sample Input 1
3 2
1 1 0
0 0 1
Sample Output 1
yes
Sample Input 2
2 2
0 0
1 1
Sample Output 2
no

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <stack>
using namespace std;
using ll = long long;
int main() {
	int W, H;cin >> W >> H;
	set<string> st;
	map<string, int> cnt;
	for (int i = 0;i < H;i++) {
		string s = "";
		for (int j = 0;j < W;j++) {
			char c;cin >> c;
			s += c;
		}
		st.insert(s);
		cnt[s]++;
	}	
	if (st.size() != 2) {
		cout << "no" << endl;
		return 0;
	}
	string a = *st.begin();
	string b = *st.rbegin();
	if (abs(cnt[a]-cnt[b]) > 1) {
		cout << "no" << endl;
		return 0;
	}
	int da = 0;int db = 0;
	for (int i = 0;i < W;i++) {
		if (a[i] == b[i]) {
			cout << "no" << endl;
			return 0;
		}
		da += (a[i] == '1' ? 1 : -1);
		db += (b[i] == '1' ? 1 : -1);	
	}
	if (abs(da) <= 1 and abs(db) <= 1) {
		cout << "yes" << endl;
	} else {
		cout << "no" << endl;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 5632
final_rank: 2

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

using namespace std;

#define rep(i, l, n) for(int i = int(l); i < int(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T> bool chmin(T &a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a < b) {a = b; return true;} return false;}
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;

// bool -> Yes/No
string answer(bool b) {return b ? "Yes" : "No";}

void fix(int k) {cout << fixed << setprecision(k);}

const int inf = 2e9;
const long long INF = 2e18;
const long double eps = 1e-12;
const long double pi = 3.14159265358979323846264338;
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

void f() {
    cout << "no\n";
    exit(0);
}

void main_program() {
    int w, h; cin >> w >> h;
    string s[h];
    rep(i, 0, h) {
        int cnt[2];
        cnt[0] = cnt[1] = 0;
        string t;
        rep(j, 0, w) {
            int c; cin >> c;
            cnt[c]++;
            t += (char)('0' + c);
        }
        if(abs(cnt[0] - cnt[1]) > 1) f();
        s[i] = t;
    }
    sort(s, s + h);
    int c = 0;
    rep(i, 0, h - 1) {
        if(s[i] != s[i + 1]) {
            if(c) f();
            c++;
        }
    }
    rep(i, 0, w) if(s[0][i] == s[h - 1][i]) f();
    cout << "yes\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    //cin >> T;
    while(T--) {
        main_program();
    }
}
accuracy: 1
time_ms: 30
memory_kb: 4092
final_rank: 1

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

int main() {
	int H, W;
	cin >> W >> H;
	vector<vector<int> > S(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> S[i][j];
		}
	}
	sort(S.begin(), S.end());
	vector<vector<int> > T = S;
	T.erase(unique(T.begin(), T.end()), T.end());
	if (T.size() != 2) {
		cout << "no" << endl;
	}
	else {
		int c0 = 0, c1 = 0;
		for (int i = 0; i < H; i++) {
			if (S[i] == T[0]) {
				c0 += 1;
			}
			else {
				c1 += 1;
			}
		}
		if (abs(c0 - c1) >= 2) {
			cout << "no" << endl;
		}
		else {
			bool flag = true;
			for (int i = 0; i < W; i++) {
				if (T[0][i] == T[1][i]) {
					flag = false;
				}
			}
			int d0 = 0, d1 = 0;
			for (int i = 0; i < W; i++) {
				if (T[0][i] == 1) {
					d0 += 1;
				}
				else {
					d1 += 1;
				}
			}
			if (abs(d0 - d1) >= 2) {
				flag = false;
			}
			cout << (flag ? "yes" : "no") << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 11240
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    vector<vector<int> > masu(x,vector<int> (y));
    vector<vector<int> > masu2(x,vector<int> (y));
    vector<vector<int> > sample(x,vector<int> (y));
    vector<vector<int> > sample2(x,vector<int> (y));
    vector<int> tate(x);
    vector<int> yoko(y);
    for(int i=0;i<x;i+=1){
        tate.at(i)=0;
    }
    for(int i=0;i<y;i+=1){
        yoko.at(i)=0;
    }
    for(int j=0;j<y;j+=1){
    for(int i=0;i<x;i+=1){
            cin>>masu.at(i).at(j);
            if(masu.at(i).at(j)==1){
            tate.at(i)+=1;
            yoko.at(j)+=1;
            }
        }
    }
    for(int i=0;i<x;i+=1){
        for(int j=0;j<y;j+=1){
            int r=0;
            if(masu.at(i).at(j)==1){
                r+=(tate.at(i)-1)*10000+yoko.at(j)-1;
                r*=-1;
                r-=1;
            }else{
                r+=tate.at(i)*10000+yoko.at(j);
            }
            masu2.at(i).at(j)=r;
            if((i+j)%2==1){
            sample.at(i).at(j)=-(((y+(i%2))/2-1)*10000+(x+(j%2))/2-1)-1;
            sample2.at(i).at(j)=((y+((i+1)%2))/2)*10000+(x+((j+1)%2))/2;
            }else{
               sample.at(i).at(j)=(((y+(i%2))/2)*10000+(x+(j%2))/2);
               sample2.at(i).at(j)=-(((y+((i+1)%2))/2-1)*10000+(x+((j+1)%2))/2-1)-1;
            }
        }
    }
    for(int j=0;j<x;j+=1){
        sort(masu2.at(j).begin(),masu2.at(j).end());
    }
    sort(masu2.begin(),masu2.end());
    for(int j=0;j<x;j+=1){
        sort(sample.at(j).begin(),sample.at(j).end());
    }
    sort(sample.begin(),sample.end());
    for(int j=0;j<x;j+=1){
        sort(sample2.at(j).begin(),sample2.at(j).end());
    }
    sort(sample2.begin(),sample2.end());
    int ans=1,ans2=1;
    for(int i=0;i<x;i+=1){
        for(int j=0;j<y;j+=1){
            if(masu2.at(i).at(j)!=sample.at(i).at(j)){
                ans=0;
            }
            if(masu2.at(i).at(j)!=sample2.at(i).at(j)){
                ans2=0;
            }
        }
    }
    
    if(ans==1||ans2==1){
        cout<<"yes"<<endl;
    }else{
        cout<<"no"<<endl;
    }
}
accuracy: 0.5555555555555556
time_ms: 120
memory_kb: 16244
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    vector<vector<int> > masu(x,vector<int> (y));
    vector<vector<int> > masu2(x,vector<int> (y));
    vector<vector<int> > sample(x,vector<int> (y));
    vector<vector<int> > sample2(x,vector<int> (y));
    vector<int> tate(x);
    vector<int> yoko(y);
    for(int i=0;i<x;i+=1){
        tate.at(i)=0;
    }
    for(int i=0;i<y;i+=1){
        yoko.at(i)=0;
    }
    for(int j=0;j<y;j+=1){
    for(int i=0;i<x;i+=1){
            cin>>masu.at(i).at(j);
            if(masu.at(i).at(j)==1){
            tate.at(i)+=1;
            yoko.at(j)+=1;
                
            }
        }
    }
    for(int i=0;i<x;i+=1){
        for(int j=0;j<y;j+=1){
            int r=0;
            if(masu.at(i).at(j)==1){
                r+=(tate.at(i)-1)*1000+yoko.at(j)-1;
                r*=-1;
                r-=1;
            }else{
                r+=tate.at(i)*1000+yoko.at(j);
            }
            masu2.at(i).at(j)=r;
            if((i+j)%2==1){
            sample.at(i).at(j)=-(((y+(i%2))/2-1)*1000+(x+(j%2))/2-1)-1;
            sample2.at(i).at(j)=((y+((i+1)%2))/2)*1000+(x+((j+1)%2))/2;
            }else{
               sample.at(i).at(j)=(((y+(i%2))/2)*1000+(x+(j%2))/2);
               sample2.at(i).at(j)=-(((y+((i+1)%2))/2-1)*1000+(x+((j+1)%2))/2-1)-1;
            }
        }
    }
    for(int j=0;j<x;j+=1){
        sort(masu2.at(j).begin(),masu2.at(j).end());
    }
    sort(masu2.begin(),masu2.end());
    for(int j=0;j<x;j+=1){
        sort(sample.at(j).begin(),sample.at(j).end());
    }
    sort(sample.begin(),sample.end());
    for(int j=0;j<x;j+=1){
        sort(sample2.at(j).begin(),sample2.at(j).end());
    }
    sort(sample2.begin(),sample2.end());
    int ans=1,ans2=1;
    for(int i=0;i<x;i+=1){
        for(int j=0;j<y;j+=1){
            if(masu2.at(i).at(j)!=sample.at(i).at(j)){
                ans=0;
            }
            if(masu2.at(i).at(j)!=sample2.at(i).at(j)){
                ans2=0;
            }
        }
    }
    
    if(ans==1||ans2==1){
        cout<<"yes"<<endl;
    }else{
        cout<<"no"<<endl;
    }
}
accuracy: 0.5555555555555556
time_ms: 120
memory_kb: 16236
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main()
{
    ll W, H; cin >> W >> H;
    vector<vector<ll>>A(H, vector<ll>(W));
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    map<string, ll>MAP;
    set<string>S;
    for (ll i = 0; i < H; i++) {
        string T;
        for (ll j = 0; j < W; j++) {
            T.push_back(char(A[i][j] + '0'));
        }
        S.insert(T);
        if (MAP.count(T)) MAP[T]++;
        else MAP[T] = 1;
    }
    if (S.size() != 2) {
        cout << "no" << endl;
        return 0;
    }
    if (abs(MAP[*S.begin()] - MAP[*prev(S.end(), 1)]) != H % 2) {
        cout << "no" << endl;
        return 0;
    }
    MAP.clear(); S.clear();
    for (ll i = 0; i < W; i++) {
        string T;
        for (ll j = 0; j < H; j++) {
            T.push_back(char(A[j][i] + '0'));
        }
        S.insert(T);
        if (MAP.count(T)) MAP[T]++;
        else MAP[T] = 1;
    }
    if (S.size() != 2) {
        cout << "no" << endl;
        return 0;
    }
    if (abs(MAP[*S.begin()] - MAP[*prev(S.end(), 1)]) != W % 2) {
        cout << "no" << endl;
        return 0;
    }
    cout << "yes" << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 13332
final_rank: 14

code_snippet: #include"bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vpllint> vvpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define mod9 998244353
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define isin(i,n) (0<=i&&i<n)

int main() {
	int w, h;
	cin >> w >> h;
	vvbool table(h, vbool(w));
	rep(i, h) {
		rep(j, w) {
			int x;
			cin >> x;
			table[i][j] = x == 1;
		}
	}
	vint a(h), b(w);
	rep(i, h)a[i] = i;
	rep(i, w)b[i] = i;

	int cnt = 0;
	int x, y;
	rep(i, h) {
		if (table[a[i]][b[0]]) {
			swap(a[i], a[cnt]);
			cnt++;
		}
	}
	if (!(h % 2 == 0 && cnt == h / 2) &&
		!(h % 2 == 1 && cnt == h / 2 + 1) &&
		!(h % 2 == 1 && cnt == h / 2)) {
		cout << "no" << endl;
		return 0;
	}
	x = cnt;
	cnt = 0;
	rep(i, w) {
		if (table[a[0]][b[i]]) {
			swap(b[i], b[cnt]);
			cnt++;
		}
	}
	if (!(w % 2 == 0 && cnt == w / 2) &&
		!(w % 2 == 1 && cnt == w / 2 + 1) &&
		!(w % 2 == 1 && cnt == w / 2)) {
		cout << "no" << endl;
		return 0;
	}
	y = cnt;
	rep(i, h)rep(j, w) {
		if (table[a[i]][b[j]] == (i < x ^ j < y)) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3584
final_rank: 4

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0373.cc: Checkered Pattern
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_W = 1000;
const int MAX_H = 1000;

/* typedef */

typedef vector<int> vi;
typedef vector<vi> vvi;

/* global variables */

int cs[MAX_H][MAX_W];
int hs[MAX_H], vs[MAX_W];

/* subroutines */

int vsum(vi &v) {
  int sum = 0;
  for (auto u: v) sum += u;
  return sum;
}

bool check(vvi &vs) {
  int k = 0, c0 = 0, c1 = 0;
  vi v0, v1;
  for (auto v: vs) {
    if (k == 0) k++, c0++, v0 = v;
    else if (k == 1) {
      if (v0 == v) c0++;
      else k++, c1++, v1 = v;
    }
    else {
      if (v0 == v) c0++;
      else if (v1 == v) c1++;
      else return false;
    }
  }
  if (k != 2 || abs(c1 - c0) > 1) return false;

  int w = v0.size();
  int s0 = vsum(v0), s1 = vsum(v1);
  if (! (w & 1)) return (s0 == w / 2 && s1 == w / 2);

  int w0 = (w + 1) / 2, w1 = w - w0;
  return ((s0 == w0 && s1 == w1) || (s0 == w1 && s1 == w0));
}

/* main */

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

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) scanf("%d", cs[i] + j);

  vvi vs(h, vi(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) vs[i][j] = cs[i][j];
  if (! check(vs)) { puts("no"); return 0; }

  vs.assign(w, vi(h));
  for (int j = 0; j < w; j++)
    for (int i = 0; i < h; i++) vs[j][i] = cs[i][j];
  if (! check(vs)) { puts("no"); return 0; }

  puts("yes");
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 12492
final_rank: 8

code_snippet: #ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}



int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/
    
    int h,w;
    cin >> w >> h;
    vector<vector<int>> g(h,vector<int>(w));
    rep(i,h)rep(j,w)cin >> g[i][j];
    bool ok=true;
    rep(i,h){
        int cnt=0;
        rep(j,w)cnt+=g[i][j]==1;
        ok&=(cnt==w/2 || cnt==(w+1)/2);
    }
    rep(j,w){
        int cnt=0;
        rep(i,h)cnt+=g[i][j]==1;
        ok&=(cnt==h/2 || cnt==(h+1)/2);
    }
    if(!ok){
        cout << "no" << newl;
        return 0;
    }
    //一番上の行と同じ形の箇所がh/2 or (h+1)/2 個あり、かつそれと異なる（ちょうど反転になっている）ものが残り全てなら良い）
    int cnt=0;
    int cnt2=0;
    rep(i,h){
        cnt+=g[i]==g[0];
        bool now=true;
        rep(j,w)now&=(g[i][j]==!g[0][j]);
        cnt2+=now;
    }
    cout << ((cnt==h/2 || cnt==(h+1)/2) && cnt+cnt2==h ? "yes":"no") << newl;
}
accuracy: 1
time_ms: 70
memory_kb: 7296
final_rank: 6

code_snippet: //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
//#pragma GCC target("arch=skylake-avx512")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VS VE<ST>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define rep1(i,a,b,c) for(int i=a;i<b;i+=c)
#define rep2(i,a,b) rep1(i,a,b,1)
#define rep3(i,a) rep2(i,0,a)
#define rep4(a) rep3(i,a)
#define repr1(i,a,b,c) for(int i=b-1;i>=a;i-=c)
#define repr2(i,a,b) repr1(i,a,b,1)
#define repr3(i,a) repr2(i,0,a)
#define repr4(a) repr3(i,a)
#define overload4(a,b,c,d,e,...) e
#define rep(...) overload4(__VA_ARGS__,rep1,rep2,rep3,rep4)(__VA_ARGS__)
#define repr(...) overload4(__VA_ARGS__,repr1,repr2,repr3,repr4)(__VA_ARGS__)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define EPS 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
bool zero(LD d){return d<-EPS||EPS<d;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=max(a,b);b=a+b-c;a=c;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;rep(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vin(VE<T> &v,LL d=0){for(auto &a:v){cin>>a;a-=d;}}
template<typename T>void vout(VE<T> &v,LL d=0){rep(v.size()){cout<<v[i]+d;if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2in(VE<VE<T>> &v,LL d=0){for(auto &a:v)for(auto &b:a){cin>>b;b-=d;}}
template<typename T>void v2out(VE<VE<T>> &v,LL d=0){for(auto a:v)vout(a,d);}
template<typename T>void vin2(VE<T> &u,VE<T> &v,LL d=0){rep(u.size()){cin>>u[i]>>v[i];u[i]-=d,v[i]-=d;}}
template<typename T>void vout2(VE<T> &u,VE<T> &v,LL d=0){rep(u.size())cout<<u[i]+d<<" "<<v[i]+d<<endl;}
template<typename T>void pin(VE<pair<T,T>> &p,bool r=0,LL d=0){rep(p.size()){if(r)cin>>p[i].SE>>p[i].FI;else cin>>p[i].FI>>p[i].SE;p[i].FI-=d,p[i].SE-=d;}}
template<typename T>void pout(VE<pair<T,T>> &p,bool r=0,LL d=0){rep(p.size()){if(r)cout<<p[i].SE+d<<" "<<p[i].FI+d<<endl;else cout<<p[i].FI+d<<" "<<p[i].SE+d<<endl;}}
template<typename T>void gin(VE<VE<T>> &g,VE<T> &u,VE<T> &v,bool d=1,LL z=1){rep(u.size()){cin>>u[i]>>v[i];u[i]-=z,v[i]-=z;g[u[i]].PB(v[i]);if(d)g[v[i]].PB(u[i]);}}
template<typename T>void wgin(VE<VE<pair<T,T>>> &g,VE<T> &u,VE<T> &v,VE<T> &c,bool d=1,LL z=1){rep(u.size()){cin>>u[i]>>v[i]>>c[i];u[i]-=z,v[i]-=z;g[u[i]].PB({v[i],c[i]});if(d)g[v[i]].PB({u[i],c[i]});}}
template<class... T>constexpr auto MIN(T... a){return min(initializer_list<common_type_t<T...>>{a...});}
template<class... T>constexpr auto MAX(T... a){return max(initializer_list<common_type_t<T...>>{a...});}
template<class... T>void input(T&... a){(cin>>...>>a);}
void print(){cout<<endl;}
template<class T,class... Ts>void print(const T& a,const Ts&... b){cout<<a;(cout<<...<<(cout<<' ',b));cout<<endl;}

int main(){
	FAST;
	LL W,H;
	cin>>W>>H;
	VVL c(H,VL(W));
	v2in(c);
	LL h=0,w=0,f=1;
	rep(W)if(c[0][i]==1)w++;
	rep(H)if(c[i][0]==1)h++;
	if(W/2==w)f=0;
	if(W%2==1&&W/2+1==w)f=0;
	if(f){
		cout<<"no"<<endl;
		return 0;
	}
	f=1;
	if(H/2==h)f=0;
	if(H%2==1&&H/2+1==h)f=0;
	if(f){
		cout<<"no"<<endl;
		return 0;
	}
	VVL t(H,VL(W));
	rep(W)t[0][i]=c[0][i];
	rep(H)t[i][0]=c[i][0];
	rep(H-1){
		if(t[0][0]!=t[i+1][0])rep(j,W-1)t[i+1][j+1]=t[0][j+1]^1;
		else rep(j,W-1)t[i+1][j+1]=t[0][j+1];
	}
	if(t==c)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 16284
final_rank: 13

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)


long long sumvec(vector<int> A){
	long long res = 0;
	for (auto a : A) res += a;
	return res;
}


struct Order{
	int l[3], r[3];
};


bool solve(){
	int W, H; cin >> W >> H;
	vector<vector<int>> A(H, vector<int>(W));
	rep(y, H) rep(x, W) cin >> A[y][x];
	if (sumvec(A[0]) < W / 2 || (W + 1) / 2 < sumvec(A[0])) return false;
	for (int y = H - 1; y >= 0; y--){
		rep(x, W) A[y][x] ^= A[0][x];
	}
	int C = 0;
	rep(y, H){
		int s = sumvec(A[y]);
		if (s != W && s != 0) return false;
		C += s / W;
	}
	if (C < H / 2 || (H + 1) / 2 < C) return false;
	return true;
}


int main(){
	if(solve()) cout << "yes\n";
	else cout << "no\n";
	return 0;
}




struct ios_improve_speed{
	ios_improve_speed(){
		ios::sync_with_stdio(0);
		cin.tie(0);
	}
} ios_improve_speed_instance;
accuracy: 1
time_ms: 30
memory_kb: 6880
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int W,H;
map<vector<int>,int>mp;
main()
{
	cin>>W>>H;
	for(int i=0;i<H;i++)
	{
		vector<int>now(W);
		for(int j=0;j<W;j++)cin>>now[j];
		mp[now]++;
	}
	auto it=mp.begin();
	vector<int>A,B;
	int ca,cb;
	A=it->first;
	ca=it->second;
	it++;
	if(it==mp.end())
	{
		cout<<"no"<<endl;
		return 0;
	}
	B=it->first;
	cb=it->second;
	it++;
	bool ok=abs(ca-cb)<=1;
	int da=0,db=0;
	for(int i=0;i<W;i++)
	{
		if(A[i]==B[i])ok=false;
		if(A[i]==1)da++;
		else db++;
	}
	ok=ok&&abs(da-db)<=1;
	if(it!=mp.end()||!ok)
	{
		cout<<"no"<<endl;
	}
	else
	{
		cout<<"yes"<<endl;
	}
}
accuracy: 1
time_ms: 100
memory_kb: 7160
final_rank: 10

code_snippet: #include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define eb emplace_back
using namespace std;
const char newl='\n';
template<class T>
using V=vector<T>;
int main(){
    int w,h;cin>>w>>h;
    V<V<int>> c(h,V<int>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
        }
    }
    set<int> v1,v0;
    for(int i=0;i<h;i++){
        if(c[i][0]==1&&v1.empty()){
            for(int j=0;j<w;j++){
                if(c[i][j])v1.insert(j);
            }
        }
        if(c[i][0]==0&&v0.empty()){
            for(int j=0;j<w;j++){
                if(c[i][j])v0.insert(j);
            }
        }
    }
    if(v0.empty()||v1.empty()){
        cout<<"no"<<newl;
        return 0;
    }
    int c0=0,c1=0;
    for(int i=0;i<h;i++){
        if(c[i][0]==0){
            c0++;
        }else{
            c1++;
        }
        for(int j=0;j<w;j++){
            if(c[i][0]==0){
                if(v0.count(j)&&c[i][j]==0){
                    cout<<"no"<<newl;
                    return 0;
                }
                if(!v0.count(j)&&c[i][j]){
                    cout<<"no"<<newl;
                    return 0;
                }
            }else{
                if(v1.count(j)&&c[i][j]==0){
                    cout<<"no"<<newl;
                    return 0;
                }
                if(!v1.count(j)&&c[i][j]){
                    cout<<"no"<<newl;
                    return 0;
                }
            }
        }
    }
    for(auto e:v0){
        if(v1.count(e)){
            cout<<"no"<<newl;
            return 0;
        }
    }
    if(v0.size()+v1.size()!=w){
        cout<<"no"<<newl;
        return 0;
    }
    if(abs(c1-c0)==h%2&&abs((int)v1.size()-(int)v0.size())==w%2){
        cout<<"yes"<<newl;
        return 0;
    }
    cout<<"no"<<newl;
}
accuracy: 1
time_ms: 150
memory_kb: 6964
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int W, H; cin>>W>>H;
	int c[H][W];
	rep(i,0,H){
        int sum = 0;
        rep(j,0,W){ cin>>c[i][j]; sum += c[i][j]; }
        if(sum != W/2 && sum != (W+1)/2){ cout<<"no"<<endl; return 0; }
    }    
	int cnt = 0;
	rep(i,0,H){
		rep(j,0,W){
			if((c[i][j] ^ c[0][j]) != (c[i][0] ^ c[0][0])){ cout<<"no"<<endl; return 0; }
		}
        if(c[i][0] ^ c[0][0]) cnt++;
	}
	if(cnt == H/2 || cnt == (H+1)/2) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 6380
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define vvel V<vel>
#define rep(i,n) for(int i=0;i<n;i++)
signed main() {
	int w, h; cin >> w >> h;
	vvel c(h, vel(w));
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	int x = c[0][0];
	rep(i, h) {
		rep(j, w) {
			c[i][j] ^= x;
		}
	}
	int cnth = 0;
	int cntw = 0;
	rep(i, h) { cnth += c[i][0]; }
	rep(i, w) { cntw += c[0][i]; }
	if (abs(h - 2 * cnth) > 1) { cout << "no" << endl; return 0; }
	if (abs(w - 2 * cntw) > 1) { cout << "no" << endl; return 0; }
	rep(i, h) {
		rep(j, w) {
			if (c[i][j] != (c[i][0] ^ c[0][j])) {
				cout << "no" << endl; return 0;
			}
		}
	}
	cout << "yes" << endl;
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 10700
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main(){
    int h, w; cin >> w >> h;
    vector<vector<int>> ar(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> ar[i][j];
    vector<P> ta(h,P(0,0));
    vector<P> yo(w,P(0,0));
    rep(i,h){
        rep(j,w){
            if (ar[i][j] == 0) ta[i].first++;
            else ta[i].second++;
        }
    }
    rep(i,w){
        rep(j,h){
            if (ar[j][i] == 0) yo[i].first++;
            else yo[i].second++;
        }
    }
    bool t = true;
    if (w % 2 == 0){
        rep(i,h) if (ta[i].first != ta[i].second) t = false;
    }
    else {
        if (h % 2 == 1){
            int ze = 0;
            rep(i,h){
                if (abs(ta[i].first - ta[i].second) != 1) t = false;
                else {
                    if (ta[i].first > ta[i].second) ze++;
                }
            }
            if (abs(h - 2*ze) != 1) t = false;
            int zt = 0;
            rep(i,w){
                if (abs(yo[i].first - yo[i].second) != 1) t = false;
                else {
                    if (yo[i].first > yo[i].second) zt++;
                }
            }
            if (zt != ze) t = false;
        }
    }
    if (!t) {cout << "no" << endl; return 0;}
    bool s = true;
    if (h % 2 == 0){
        rep(i,w) if (yo[i].second != yo[i].first) s = false;
    }
    if (t && s) {
        vector<int> f;
        int ima = 0;
        rep(i,w){
            if (i == w-1 || ar[0][i] != ar[0][i+1]){
                f.emplace_back(ima+1);
            }
            else ima++;
        }
        repp(i,h,1){
            vector<int> g;
            int im = 0;
            rep(j,w){
                if (j == w-1 || ar[i][j] != ar[i][j+1]){
                    g.emplace_back(im+1);
                }
                else im++;
            }
            if (f != g) s = false;
        }
        if (s) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    else cout << "no" << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 7324
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int W, H;
  cin >> W >> H;
  vector<vector<int>> c(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> c[i][j];
    }
  }
  vector<vector<int>> E(H + W);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (c[i][j] == 1){
        E[i].push_back(H + j);
        E[H + j].push_back(i);
      }
    }
  }
  int cnt = 0;
  vector<int> cc(H + W, -1);
  for (int i = 0; i < H + W; i++){
    if (cc[i] == -1){
      cc[i] = cnt;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          if (cc[w] == -1){
            cc[w] = cnt;
            Q.push(w);
          }
        }
      }
      cnt++;
    }
  }
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if ((cc[i] == cc[H + j]) && c[i][j] == 0){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  vector<int> row(cnt, 0);
  vector<int> col(cnt, 0);
  for (int i = 0; i < H; i++){
    row[cc[i]]++;
  }
  for (int i = 0; i < W; i++){
    col[cc[H + i]]++;
  }
  if (cnt != 2){
    cout << "no" << endl;
    return 0;
  }
  if (row[0] != H / 2 && row[0] != (H + 1) / 2){
    cout << "no" << endl;
  } else if (col[0] != W / 2 && col[0] != (W + 1) / 2){
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
}
accuracy: 1
time_ms: 110
memory_kb: 15180
final_rank: 18

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int w, h;
    cin >> w >> h;
    vector v(h, vector(w, 0));
    vector<string> ss;
    for (auto &&i : v) {
        string s;
        for (auto &&j : i) scanf("%d", &j), s += '0'+j;
        ss.emplace_back(s);
    }
    string a, b;
    int cnt1 = 0, cnt2 = 0;
    for (auto &&s : ss) {
        if(a.empty()) {
            a = s;
            cnt1++;
        }else if(a == s){
            cnt1++;
        }else if(b.empty()){
            b = s;
            cnt2++;
        }else if(b == s) {
            cnt2++;
        }else {
            puts("no");
            return 0;
        }
    }
    int ccnt = 0;
    if(a.empty() || b.empty()) {
        puts("no");
        return 0;
    }
    for (int i = 0; i < w; ++i) {
        if(a[i]-'0'+b[i]-'0' != 1){
            puts("no");
            return 0;
        } else if(a[i]-'0') ccnt++;
        else ccnt--;
    }
    if(abs(ccnt) <= 1 && abs(cnt1-cnt2) <= 1) puts("yes");
    else puts("no");
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 8480
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
    ll n,m;cin>>m>>n;
    vvi v(n,vi(m));
    rep(i,n)rep(j,m)cin>>v[i][j];
    vi a,b;
    rep(i,m){
        if(v[0][i])b.pb(i);
        else a.pb(i);
    }
    if(abs((ll)(a.size())-(ll)(b.size()))>1)dame("no");
    ll c=0,d=0;
    rep(i,n){
        ll k=-1;
        rep(j,m){
            if(v[i][j]==v[0][j]){
                if(k==1)dame("no");
                k=0;
            }
            else{
                if(k==0)dame("no");
                k=1;
            }
        }
        if(k)c++;
        else d++;
    }
    yesno(abs(c-d)<2);
}
accuracy: 1
time_ms: 100
memory_kb: 10692
final_rank: 15

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};


int main(){
    int h, w;
    cin >> w >> h;
    vector<vector<int> > a(h, vector<int>(w));
    int cnt = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]) cnt++;
            else cnt--;
        }
    }
    bool ok = abs(cnt) <= 1;
    for(int i=0;i<h-1;i++){
        for(int j=0;j<w-1;j++){
            int x = 0;
            for(int k=0;k<4;k++){
                x += a[i+k/2][j+k%2];
            }
            if(x&1) ok = false;
        }
    }
    for(int i=0;i<h;i++){
        int x = 0;
        for(int j=0;j<w;j++){
            if(a[i][j]) x++;
            else x--;
        }
        ok &= abs(x) <= 1;
    }
    for(int j=0;j<w;j++){
        int x = 0;
        for(int i=0;i<h;i++){
            if(a[i][j]) x++;
            else x--;
        }
        ok &= abs(x) <= 1;
    }
    cout << (ok ? "yes" : "no") << endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 6792
final_rank: 11