#include <fstream> #include <cstring> using namespace std; ifstream fin("input.txt"); ofstream fout("output.txt"); int n,m,i,j; int qw[52][52]; int er[52][52]; char a[101]; struct vlad{ int come,l,c; }b[2505]; int tryy(int l,int c) { int s=0,i=0,come=0; b[++s].come=0; b[s].l=l; b[s].c=c; while(i<s) { i++; come=b[i].come; l=b[i].l; c=b[i].c; er[l][c]=1; if(come!=1 && qw[l][c]==qw[l-1][c] && er[l-1][c]==0) { b[++s].come=3; b[s].l=l-1; b[s].c=c; er[l-1][c]=1; } if(come!=2 && qw[l][c]==qw[l][c+1] && er[l][c+1]==0) { b[++s].come=4; b[s].l=l; b[s].c=c+1; er[l][c+1]=1; } if(come!=3 && qw[l][c]==qw[l+1][c] && er[l+1][c]==0) { b[++s].come=1; b[s].l=l+1; b[s].c=c; er[l+1][c]=1; } if(come!=4 && qw[l][c]==qw[l][c-1] && er[l][c-1]==0) { b[++s].come=2; b[s].l=l; b[s].c=c-1; er[l][c-1]=1; } } return i; } int main() { int cer=0,qww=0,maxx=0; fin>>cer>>n>>m; fin.get(); for(i=1;i<=n;i++) { fin.getline(a,100); for(j=0;j<m;j++) qw[i][j+1]=a[j]-'A'+1; } if(cer==1) { for(i=1;i<=n;i++) { for(j=1;j<=m;j++) if(er[i][j]==0) { qww=tryy(i,j); if(qww>maxx) { maxx=qww; } } } } fout<<maxx; return 0; }