#include <iostream> #define M 410 using namespace std; fstream fin("ferma3.in",ios::in),fout("ferma3.out",ios::out); int di[]={-1,0,1,0},dj[]={0,1,0,-1},n,m,t,who[M][M],cost[M*M],ap[M*M],maxim2=-M,maxim1=-M,xi,xj,sum,dfsc; char color,s[M][M],col; void citire(){ cin>>t>>n>>m; for(int i=1;i<=n;i++) cin>>(s[i]+1); } bool into(int i,int j){ return (0<i && i<=n && 0<j && j<=m); } void dfs(int i,int j,int ind){ int ii,jj; dfsc++; who[i][j]=ind; for(int k=0;k<4;k++) { ii=i+di[k]; jj=j+dj[k]; if(into(ii,jj)==1&&who[ii][jj]==0&&s[ii][jj]==s[i][j]) dfs(ii,jj,ind); } } void rec(int nr,int x,int y,int put){ int ii=0,jj=0; if(put==4) return ; if((nr&(1<<put))==(1<<put)) { ii=x+di[put]; jj=y+dj[put]; if(into(ii,jj)) { if(ap[who[ii][jj]]==1||(col!='0'&&col!=s[ii][jj])||(s[ii][jj]==s[x][y])) return; else { col=s[ii][jj]; ap[who[ii][jj]]=1; sum+=cost[who[ii][jj]]; } } } rec(nr,x,y,put+1); ap[who[ii][jj]]=0; } void cmp(int x,int y){ for(int k=0;k<15;k++){ sum=0;col='0'; rec(k,x,y,0); if(sum>maxim2){ maxim2=sum; xi=x; xj=y; color=col; } } } int main() { int a,i,j,ind=1,k,r; citire(); for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(who[i][j]==0) { dfsc=0; dfs(i,j,ind); cost[ind]=dfsc; maxim1=max(maxim1,dfsc); ind++; } if(t==2){ for(i=1;i<=n;i++) for(j=1;j<=m;j++) cmp(i,j); cout<<xi<<" "<<xj<<"\n"<<color<<"\n"; return 0; } cout<<maxim1<<"\n"; return 0; }