#include using namespace std; //#include //using namespace atcoder; using ll=long long; using Graph=vector>; #define MAX 1000000 #define MOD 1000000009 //#define MOD 998244353 //#define INF 1000000000 #define INF 1000000000000000000 int H,W; int di[4]={1,0,-1,0}; int dj[4]={0,1,0,-1}; bool dfs(vector> &M,int i,int j,int pi,int pj,vector> &visit){ visit[i][j]=true; for(int k=0;k<4;k++){ int ni=i+di[k]; int nj=j+dj[k]; if(ni<0||nj<0||ni>=H||nj>=W){ continue; } if(ni==pi&&nj==pj){ continue; } if(M[ni][nj]==M[i][j]){ if(visit[ni][nj]==true){ return true; } if(dfs(M,ni,nj,i,j,visit)){ return true; } } } return false; } int main(){ cin>>W>>H; vector> M(H,vector(W)); for(int i=0;i>M[i][j]; } } vector> visit(H,vector(W,false)); for(int i=0;i