semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int A[200][200]={0};
int n;
void F(int i,int j)
{
	
		if(A[i-1][j]==-1)
		{
			A[i-1][j]=A[i][j]+1;
			F(i-1,j);
		}
		else if(A[i-1][j]>0&&A[i][j]+1<A[i-1][j])
		{
			
			A[i-1][j]=A[i][j]+1;
			F(i-1,j);
		}
		
		if(A[i+1][j]==-1)
		{
			A[i+1][j]=A[i][j]+1;
			F(i+1,j);
		}
		else if(A[i+1][j]>0&&A[i][j]+1<A[i+1][j])
		{
			
			A[i+1][j]=A[i][j]+1;
			F(i+1,j);
		}
		
		if(A[i][j-1]==-1)
		{
			A[i][j-1]=A[i][j]+1;
			F(i,j-1);
		}
		else if(A[i][j-1]>0&&A[i][j]+1<A[i][j-1])
		{
			
			A[i][j-1]=A[i][j]+1;
			F(i,j-1);
		}
		if(A[i][j+1]==-1)
		{
			A[i][j+1]=A[i][j]+1;
			  F(i,j+1);
		}
		else if(A[i][j+1]>0&&A[i][j]+1<A[i][j+1])
		{
			
			A[i][j+1]=A[i][j]+1;
			  F(i,j+1);
		}
	  

}
int main()
{
	for(int i=0;i<200;i++)
	{
		for(int j=0;j<=200;j++)
		{
			A[i][j]=-5;
		}
	}
	cin>>n;
	char p;
	for(int i=1;i<=n;i++)//???????????
	{
		for(int j=1;j<=n;j++)
		{
			cin>>p;if(p=='.')A[i][j]=-1;
			if(p=='@')A[i][j]=0;
			if(p=='#')A[i][j]=-2;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(A[i][j]>=0)
			{
				F(i,j);
			}
		}
	}
	int m;
	cin>>m;
	int num=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(A[i][j]>=0&&A[i][j]<m)
			{
				num++;
			}
		}
	}
	cout<<num;
	    return 0;
}
int  main()
{

	char a[102][102]={' '},x,b[102][102];
	
	int i,j,n,t,i1,j1;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin.get(x);
		for(j=1;j<=n;j++)
		{
			cin.get(a[i][j]);
		}
		
	}
	cin>>t;
	int sum=1;
	while(sum<t)
	{
		for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{ if(a[i][j]=='#') b[i][j]='#';
			if(a[i][j]=='@') 
			{  b[i][j]='@';
		
					if(a[i-1][j]!='#')
					{
						b[i-1][j]='@';
					}
					else{ b[i-1][j]='#';}
		
					if(a[i+1][j]!='#')
					{
						b[i+1][j]='@';
					}
					else{ b[i+1][j]='#';}
		 
			       if(a[i][j-1]!='#')
					{
						b[i][j-1]='@';
					}
					else{ b[i][j-1]='#';}
		
	                if(a[i][j+1]!='#')
					{
						b[i][j+1]='@';
					}
					else{ b[i][j+1]='#';}
		
			}
			
		}
		}
		
		for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			a[i][j]=b[i][j];
		}
	}
		sum++;
	}
	
	
	int countt=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
		if(a[i][j]=='@')   countt++;
		}
	}
	cout<<countt;

return 0;
}
/* Name      : ???? 
 * Version   : 1.0
 * Date      : 2012-11-24
 * New       : Null
 * Func&Feat : 
 * State     : Design
 */
//char infection(int,int,char room[][]);
int main()
{
    int n,m,infector=0;
    char room[100][101];
    cin>>n;
    for(int i=0;i<n;i++)cin>>room[i];
    cin>>m;
    for(int d=1;d<m;d++)
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(room[i][j]=='@')
                {
                    if(i>0&&room[i-1][j]=='.')room[i-1][j]='$';
                    if(i<n-1&&room[i+1][j]=='.')room[i+1][j]='$';
                    if(j>0&&room[i][j-1]=='.')room[i][j-1]='$';
                    if(j<n-1&&room[i][j+1]=='.')room[i][j+1]='$';
                }
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(room[i][j]=='$')room[i][j]='@';
/*        cout<<"?"<<d+2<<"??"<<endl;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)cout<<room[i][j];
            cout<<endl;
        }
        cout<<endl;//*/
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(room[i][j]=='@')infector++;
    cout<<infector;
    return 0;
}
char flu(char a)
{
	if(a=='.')
		return '!';
	else
		return a;
}//????
int change(char a[110][110],int m,int n)
{
	if(m>1)
	{
	int i,j;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i][j]=='@')
			{
				 a[i][j+1]=flu(a[i][j+1]);
					 a[i][j-1]=flu(a[i][j-1]);
					 a[i+1][j]=flu(a[i+1][j]);
					 a[i-1][j]=flu(a[i-1][j]);
			}//??????????
		}
	}
	int x,y;
	for(x=1;x<=n;x++)
	{
		for(y=1;y<=n;y++)
		{
			if(a[x][y]=='!')
			{a[x][y]='@';}//?????????????
		}
	}
	}
	if(m==1)
	{return 0;}
	change(a,m-1,n);//?????
}
int main()
{
	int room,i,j,m,s=0;
	char a[110][110]={'\0'};
	cin>>room;
	for(i=1;i<=room;i++)
	{
		for(j=1;j<=room;j++)
		{
			cin>>a[i][j];//??
		}
	}
	cin>>m;
	change(a,m,room);
	for(i=1;i<=room;i++)
	{
		for(j=1;j<=room;j++)
		{
			if(a[i][j]=='@')
			{s++;}
		}
	}//????
	cout<<s;//??
	return 0;
}
int main()
{
		 char c[110][110]; //????????110*110?????????
		 memset ( c, 0, sizeof(c) ); //?????c
		 int n, day, sum = 0; //n?n*n????day??day?,sum???????
		 int k = 0; //k??????? 
		 cin >> n;
		 cin.get(); //??????? 
		 for ( int i = 1; i <= n; i++ )
		 {
			 cin.getline( c[i] + 1, n + 1 ); //?i???1?????n??????'\0',???h+1 
		 }
		 cin >> day;
		 while ( k < day )
		 {
			 sum = 0;
			 for ( int i = 1; i <= n; i++)
			 {
					 for (int j = 1; j <= n; j++ )
					 {
						 	if ( c[i][j] == '@' )
						sum++;
							 if ( c[i][j] == '.' &&(c[i][j+1] == '@' || c[i][j-1] == '@' || c[i+1][j] == '@' || c[i-1][j] == '@' ) )
								 c[i][j] = 'N';  //??????????????????????
					 }
			 }
			 for (int i = 1; i <= n; i++)
			 {
				 for (int j = 1; j <= n; j++)
				 {
					 if (c[i][j] == 'N')
						 c[i][j] = '@';
				 }
			 }
			 k++;				
		 }
		 cout << sum << endl;
		 return 0;
}
int main()
{
	char a[101][101];
	int n,m;
	cin >>n;
	int i, j,k,count=0;
	for(i =1;i<=n;i++)
	{
		for(j =1;j<=n;j++)
		{
			cin >>a[i][j];
		}
	}
	cin >>m;
	for (i =1; i<=m-1;i++)
	{
		for(j =1;j<=n;j++)
		{
			for(k =1;k<=n;k++)
			{
				if(a[j][k] == '@')
				{
					if(a[j][k-1]=='.')
						a[j][k-1]='a';
					if(a[j][k+1]=='.')
						a[j][k+1]='a';
					if(a[j-1][k]=='.')
						a[j-1][k]='a';
					if(a[j+1][k]=='.')
						a[j+1][k]='a';
				}
			}
		}
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				if(a[j][k]=='a')
					a[j][k]='@';
			}
		}
	}
	for(i =1;i<=n;i++)
	{
		for(j =1;j<=n;j++)
		{
			if(a[i][j] =='@')
				count++;
		}
	}
	cout <<count;
	return 0;
}
int main ()
{
    int n;
    cin>>n;
    int a[102][102]={0};//????0?????1?????2???????????
    int b[102][102]={0};
    for (int i=1 ; i<=n ; i++)
    {
        for (int j=1 ; j<=n ; j++)
        {
            char temp;
            cin>>temp;
            switch (temp)
            {
                case '.':a[i][j]=1;b[i][j]=1;break;
                case '#':a[i][j]=0;b[i][j]=0;break;
                case '@':a[i][j]=2;b[i][j]=2;break;
            }
        }
    }

    int day;
    cin>>day;
    for (int k=2 ; k<=day ; k++)
    {
        for (int i=1 ; i<=n ; i++)
        {
            for (int j=1 ; j<=n ; j++)
            {
                if (a[i][j]==2)
                {
                    if (a[i-1][j]==1) b[i-1][j]=2;
                    if (a[i+1][j]==1) b[i+1][j]=2;
                    if (a[i][j-1]==1) b[i][j-1]=2;
                    if (a[i][j+1]==1) b[i][j+1]=2;
                }
            }
        }
        for (int i=1 ; i<=n ; i++)
        {
            for (int j=1 ; j<=n ; j++)
            {
                a[i][j]=b[i][j];
            }
        }
    }

    int sum=0;//??????
    for (int i=1 ; i<=n ; i++)
    {
        for (int j=1 ; j<=n ; j++)
        {
            if (a[i][j]==2)
                sum++;
        }
    }
    cout<<sum;
    return 0;
}
int main()
{   int n,m,i,j,t=0,day;
    char bf1[101][101]={'#'},bf2[101][101]={'#'};
	char kongbai[10];
	scanf("%d",&n);
	gets(kongbai);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			scanf("%c",&bf1[i][j]);
		}
		gets(kongbai);
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			bf2[i][j]=bf1[i][j];
		}
	}
    scanf("%d",&m);
	for(day=1;day<m;day++){
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(bf1[i][j]=='@'){
					if(bf1[i+1][j]!='#'){
						bf2[i+1][j]='@';
					}
					if(bf1[i][j+1]!='#'){
						bf2[i][j+1]='@';
					}
					if(bf1[i-1][j]!='#'){
						bf2[i-1][j]='@';
					}
					if(bf1[i][j-1]!='#'){
						bf2[i][j-1]='@';
					}
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				bf1[i][j]=bf2[i][j];
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(bf1[i][j]=='@'){
				t++;
			}
		}
	}
	printf("%d",t);
	return 0;
}
int main()
{
	int n;
	cin >> n;
	char a[102][103];
	char temp[102][103];

	for (int i = 1; i <= n; i++)
		cin >> a[i] + 1;
	memcpy(temp,a,102*103);
	int m;
	cin >> m;
	for (int o = 0; o < m - 1; o++)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= strlen(a[i]+1); j++)
				if (a[i][j] == '@')
				{
					if (a[i+1][j] == '.')
						temp[i+1][j] = '@';
					if (a[i-1][j] == '.')
						temp[i-1][j] = '@';
					if (a[i][j+1] == '.')
						temp[i][j+1] = '@';
					if (a[i][j-1] == '.')
						temp[i][j-1] = '@';
				}
		}
		memcpy(a,temp,102*103);
	}
	int c = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= strlen(a[i]+1); j++)
				if (a[i][j] == '@')
					c++;
		cout << c;

}
int main()
{
	int a[110][110];
	int i,j,k;
	for(i=0;i<110;i++)
	{
		for(j=0;j<110;j++)
			a[i][j]=-1;
	}
	int n,m;
	cin>>n;
	getchar();
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			char x;
			x=getchar();
			if(x=='.')a[i][j]=0;
			if(x=='@')a[i][j]=1;
		}
		getchar();
	}
	cin>>m;//?????????-1????0??????????1
	if(m!=1)
	{
		for(k=2;k<=m;k++)
		{
			for(i=1;i<=n;i++)
			{
				for(j=1;j<=n;j++)
				{
					if(a[i][j]==k-1)
					{
						a[i][j]=k;
						if(a[i][j+1]==0)a[i][j+1]=k;
						if(a[i][j-1]==0)a[i][j-1]=k;
						if(a[i-1][j]==0)a[i-1][j]=k;
						if(a[i+1][j]==0)a[i+1][j]=k;//?????????????
					}
				}
			}
		}
	}
	int jishu=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i][j]==m)jishu++;
		}
		
	}
	cout<<jishu;



	return 0;
	
}
char room_W[102][102][2] = {0};

void Spread(int n, int k)
{
	int i, j;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			if (room_W[i][j][k] == '@')
			{
				if (room_W[i - 1][j][k] != '#') room_W[i - 1][j][1 - k] = '@';
				if (room_W[i + 1][j][k] != '#') room_W[i + 1][j][1 - k] = '@';
				if (room_W[i][j - 1][k] != '#') room_W[i][j - 1][1 - k] = '@';
				if (room_W[i][j + 1][k] != '#') room_W[i][j + 1][1 - k] = '@';
			}
		}
}

int main()
{
	int n, m;
	cin >> n;
	int i, j;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			cin >> room_W[i][j][0];
			room_W[i][j][1] = room_W[i][j][0];
		}
	cin >> m;
	int k = 0;
	for (i = 1; i < m; i++)
	{
		Spread(n, k);
		k = 1 - k;
	}
	int count = 0;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			if (room_W[i][j][k] == '@')
				count++;
		};
	cout << count << endl;
	return 0;
}
/*
 * 2.cpp
 *
 *  Created on: 2012-11-11
 *      Author: a
 */
int main()
{
	int n,i,j,d,m;
	cin>>n;
	char s[n][n],a[n][n],b[n][n];
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>s[i][j];
	cin>>m;
	for(d=1;d<m;d++){
		for(i=0;i<n;i++)
			for(j=0;j<n;j++){
		     a[i][j]=s[i][j];
			 b[i][j]=s[i][j];
			}
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(a[i][j]=='@'){
					if(i-1>=0&&a[i-1][j]=='.') a[i-1][j]='@';
					if(j-1>=0&&a[i][j-1]=='.') a[i][j-1]='@';
				}
			for(i=n-1;i>=0;i--)
				for(j=n-1;j>=0;j--)
					if(b[i][j]=='@'){
						if(i+1<n&&b[i+1][j]=='.') b[i+1][j]='@';
						if(j+1<n&&b[i][j+1]=='.') b[i][j+1]='@';
					}

			for(i=0;i<n;i++)
				for(j=0;j<n;j++){
				if(a[i][j]=='@') s[i][j]=a[i][j];
				if(a[i][j]=='.'&&b[i][j]=='@') s[i][j]=b[i][j];
				}
	}
	int cont=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(s[i][j]=='@') cont++;
	cout<<cont<<endl;
	return 0;

}
int main()
{
	int n,i,j,count=0;
	char s[105][105];
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		gets(s[i]);
	}
	int m,r;
	scanf("%d",&m);
	if(m>1)
	{
	    for(i=0;i<m;i++)
		{
			for(j=0;j<n;j++)
			{
			    for(r=0;r<n;r++)
				{
				    if(s[j][r]=='*')
					{
					    s[j][r]='@';
					}
				}
			}
		    for(j=0;j<n;j++)
			{
			    for(r=0;r<n;r++)
				{
				    if(s[j][r]=='@')
					{
					    if(j!=0 && s[j-1][r]=='.')
						{
						    s[j-1][r]='*';
						}
					    if(j!=n-1 && s[j+1][r]=='.')
						{
					    	s[j+1][r]='*';
						}
					    if(r!=n-1 && s[j][r+1]=='.')
						{
					    	s[j][r+1]='*';
						}
					    if(r!=0 && s[j][r-1]=='.')
						{
					    	s[j][r-1]='*';
						}
					}
				}
			}
		}
	}
	for(j=0;j<n;j++)
	{
		for(r=0;r<n;r++)
		{
			if(s[j][r]=='@')
			{
				count++;
			}
		}
	}
	printf("%d",count);
	return 0;
}
char a[101][101], b[101][101];

int main()
{
	int n, i, j, m, k, count = 0;
	for (i = 1; i <= 100; i++)
		for (j = 1; j <= 100; j++)
		{
			a[i][j] = '0';
			b[i][j] = '0';
		}		
	cin >> n;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			cin >> a[i][j];
	cin >> m;
	for (k = 1; k < m; k++)
	{
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
			{
				if (a[i][j] == '@')
				{
					b[i][j] = '@';
					if (a[i-1][j] != '#')
						b[i-1][j] = '@';
					if (a[i+1][j] != '#')
						b[i+1][j] = '@';
					if (a[i][j-1] != '#')
						b[i][j-1] = '@';
					if (a[i][j+1] != '#')
						b[i][j+1] = '@';
				}
			}
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
			{
				if (b[i][j] == '@')
					a[i][j] = b[i][j];
			}
	}
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			if (a[i][j] == '@')
				count++;
		}
	cout << count;
	return 0;
}
int main()
{
	int n,m,num=0;
	char a[101][101];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>m;
	for(int k=1;k<m;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]=='@')
				{
					if(a[i+1][j]=='.')
					{
						a[i+1][j]='!';
					}
					if(a[i-1][j]=='.')
					{
						a[i-1][j]='!';
					}
					if(a[i][j-1]=='.')
					{
						a[i][j-1]='!';
					}
					if(a[i][j+1]=='.')
					{
						a[i][j+1]='!';
					}
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]=='!')
				{
					a[i][j]='@';
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i][j]=='@')
			{
				num++;
			}
		}
	}
	cout<<num<<endl;
	return 0;
}
int main()
{
	int n,m;
	cin>>n;
	char a[1000][1000]={'0'};
	int i,j,k,o,p;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
	       cin>>a[i][j];
	cin>>m;
	for(i=1;i<=m-1;i++)
	{
		for(k=1;k<=n;k++)
			for(j=1;j<=n;j++)
			{
				if(a[k][j]=='@')
				{
					if(a[k][j+1]=='.')
						a[k][j+1]='&';
					if(a[k][j-1]=='.')
						a[k][j-1]='&';
					if(a[k-1][j]=='.')
						a[k-1][j]='&';
					if(a[k+1][j]=='.')
						a[k+1][j]='&';
				}
			}
		for(o=1;o<=n;o++)
			for(p=1;p<=n;p++)
			{
				if(a[o][p]=='&')
					a[o][p]='@';
			}
	}
	int count=0;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(a[i][j]=='@')
				count++;
		}

    cout<<count<<endl;
}
int main(){
    int n,m,sum;
    int i,p,q,r,s;
    char f[102][102],g[102][102]={0};
    scanf("%d",&n);
//    printf("%d",n);
    for(p=1;p<n+1;p++){
        for(q=1;q<n+1;q++){
            scanf("%c",&f[p][q]);
//            printf("%d%d=%c",p,q,f[p][q]);
            if(f[p][q]=='\n'){
                q--;
            }
        }
    }
//    printf("p=%dq=%d\n",p,q);
//     goto lp;
//    printf("%c",f[2][3]);
    scanf("%d",&m);
//    printf("%d\n",m);
//    goto lp;
    for(i=1;i<m;i++){
        for(p=1;p<n+1;p++){
            for(q=1;q<n+1;q++){
                if(f[p][q]=='@'){
//                    printf("%d%d\n",p,q);
//                    for(r=p-1;r<p+2;r++){
//                        for(s=q-1;s<q+2;s++){
//                            if(f[r][s]=='.'){                 
//                                g[r][s]='@';
//                                printf("%c",g[r][s]);
//                                  printf("@=%d%d\n",r,s);
//                            }
//                        }
                    if(f[p-1][q]=='.'){
                        g[p-1][q]='@';
                    } 
                    if(f[p][q-1]=='.'){
                        g[p][q-1]='@';
                    }
                    if(f[p][q+1]=='.'){
                        g[p][q+1]='@';
                    }
                    if(f[p+1][q]=='.'){
                        g[p+1][q]='@';
                    }
                    }
                }
            }
        
//        for(p=1;p<n+1;p++){
//            for(q=1;q<n+1;q++){
//                printf("%c",g[p][q]);
//            }
//        }
//        goto lp;
        for(p=1;p<n+1;p++){
            for(q=1;q<n+1;q++){
                if(g[p][q]=='@'){
                    f[p][q]='@';
                }
            }
        }
    }
    for(p=1,sum=0;p<n+1;p++){
        for(q=1;q<n+1;q++){
            if(f[p][q]=='@'){
                sum++;
            }
//            printf("%c",f[p][q]);
        }
    }
    printf("%d",sum);
    lp:return 0;
}
/**
 * @file   5.cpp
 * @author ???
 * @date   2013-11-1
 * @description
 *         ???????????
 */



int main()
{
	int a[102][102] = {0}, b[102][102], n, m, i, j, sum = 0;
	cin >> n;
	char c;

	for (i = 1; i <= n; ++i)
		for (j = 1; j <= n; ++j)
		{
			cin >> c;
			switch (c)
			{
			case '@':                    // ??????????-1??
				a[i][j] = -1;
				++sum;
				break;
			case '.':
				a[i][j] = 1;             // ??????????1??
				break;
			}
		}

	cin >> m;

	while (m)
	{
		for (i = 1; i <= n; ++i)
			for (j = 1; j <= n; ++j)
			{
				if (b[i][j] == 1 && (a[i - 1][j] == -1 || a[i + 1][j] == -1 || a[i][j - 1] == -1 || a[i][j + 1] == -1))
				{
					b[i][j] = -1;
					++sum;
				}
				else b[i][j] = a[i][j];
			}

		for (i = 1; i <= n; ++i)
			for (j = 1; j <= n; ++j)
				a[i][j] = b[i][j];

		--m;
	}

	cout << sum;

	return 0;
}
int main()
{
	int n,m,num,i,j,k,a[102][102],b[101][101];
	char c;
	cin >> n;
	for (i = 0; i <= n + 1 ; i++)
	{
		for (j = 0; j <= n + 1; j++)
		{
			a[i][j] = 2;
		}
	}
	for (i = 1; i <= n ; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> c;
			switch(c)
			{
				case '.': a[i][j] = 1;break;
				case '@': a[i][j] = 0;break;
				case '#': a[i][j] = 2;break;
			}
		}
	}
	cin >> m;
	for (k = 1; k <= m - 1; k++)
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (a[i][j] == 1 && (a[i + 1][j] == 0 || a[i - 1][j] == 0 || a[i][j + 1] == 0 || a[i][j - 1] == 0))
					b[i][j] = 0;
				else
					b[i][j] = a[i][j];
			}
		}
		for (i = 1; i <= n; i++)
		{
			for (j = 1;j <= n; j++)
			{
				a[i][j] = b[i][j];
			}
		}
	}

	num = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1;j <= n; j++)
		{
			if (a[i][j] == 0)
			{
				num++;
			}
		}
	}
	cout << num  << endl;
	return 0;
}
char a[100][100];

int main()
{
    int m, n, i, j, k, count = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
       scanf("%s", a[i]);
       for (j = 0; j < n; j++) {
           switch (a[i][j]) {
               case '@': a[i][j] = 1; count++; break;
               case '.': a[i][j] = 0; break;
               case '#': a[i][j] = -1; break;
           }
       }
    }
    scanf("%d", &m);
    for (k = 1; k < m; k++) {
        for (i = 0; i < n; i++) {
            for (j = 0; j < n; j++) {
                if (a[i][j] == k) {
                    if (i > 0 && a[i-1][j] == 0) {
                        a[i-1][j] = k + 1;
                        count++;
                    }
                    if (i < n-1 && a[i+1][j] == 0) {
                        a[i+1][j] = k + 1;
                        count++;
                    }
                    if (j > 0 && a[i][j-1] == 0) {
                        a[i][j-1] = k + 1;
                        count++;
                    }
                    if (j < n-1 && a[i][j+1] == 0) {
                        a[i][j+1] = k + 1;
                        count++;
                    }
                }
            }
        }
    }
    printf("%d", count);
    return 0;
}
int main()
{
	int n,m,i,j,k,s=0;
	char a[102][102];
	scanf("%d",&n); 
	for(i=1;i<=n;i++)
	{
		getchar();
		for(j=1;j<=n;j++)
		{
			scanf("%c",&a[i][j]);
		}
	}
	scanf("%d",&m);
	for(k=1;k<m;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]=='@')
				{
					if(a[i][j+1]=='.')
					{
						a[i][j+1]='*';
					}
					if(a[i][j-1]=='.')
					{
						a[i][j-1]='*';
					}
					if(a[i+1][j]=='.')
					{
						a[i+1][j]='*';
					}
					if(a[i-1][j]=='.')
					{
						a[i-1][j]='*';
					}
				}
			}
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]=='*')
				{
					a[i][j]='@';
				}
			}
		}
	}
	for(i=1;i<=n;i++)
	{
	    for(j=1;j<=n;j++)
		{
		     if(a[i][j]=='@')
		     {
			     s++;
			 }
			// printf("%c ",a[i][j]);
		} 
	} 
	printf("%d",s);
 
	return 0;
}
/*
 * homework3.cpp
 *
 *  Created on: 2012-12-4
 *      Author: Lixurong
 */

int main()
{
	int n, m;
		cin >> n;
		char a[n][n];
		int b[n][n];
		for( int i=0; i<n; i++ )
		{
			for( int j=0; j<n; j++ )
			{
				cin >> a[i][j];
				if( a[i][j]=='.' )
					b[i][j]=0;
				else if( a[i][j]=='#' )
					b[i][j]=-1;
				else
					b[i][j]=1;
			}
		}
		cin >> m;
		m--;
	for( int k=1; k<=m; k++ )
	{
		for( int i=0; i<n; i++ )
		{
			for( int j=0; j<n; j++ )
			{
				if( b[i][j]==k )
				{
					if( b[i][j-1]==0 && j-1>=0 )
					{
						b[i][j-1]=k+1;
					}
					if( b[i][j+1]==0 && j+1<n )
					{
						b[i][j+1]=k+1;
					}
					if( b[i-1][j]==0 && i-1>=0 )
					{
						b[i-1][j]=k+1;
					}
					if( b[i+1][j]==0 && i+1<n )
					{
						b[i+1][j]=k+1;
					}
				}
			}
		}
	}
	int s=0;
	for( int i=0; i<n; i++ )
	{
		for(int j=0; j<n; j++ )
		{
			if( b[i][j]>0 )
				s++;
		}
	}
    cout << s;
	return 0;
}
int main()
{
	int m, n, i, j, k, sum=0;
	char a[102][102];
	cin >> n;
	for(i=1; i <= n; i++)
	{
		for(j=1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	for(i=0; i <= n+1; i++)
	{
		a[0][i]=' ';
		a[i][0]=' ';
		a[n+1][i]=' ';
		a[i][n+1]=' ';
	} 
	cin >> m;
	for(k=1; k<m; k++)
	{
		for(i=1; i <= n; i++)
			for(j=1; j <= n; j++)
			{
				if(a[i][j] == '@')
				{
					if(a[i-1][j] == '.')
					{
						a[i-1][j] = '+';
					}
					if(a[i+1][j] == '.')
					{
						a[i+1][j] = '+';
					}
					if(a[i][j-1] == '.')
					{
						a[i][j-1] = '+';
					}
					if(a[i][j+1] == '.')
					{
						a[i][j+1] = '+';
					}
				}
				else
					continue;
			}
		for(i=1; i <= n; i++)
			for(j=1; j <= n; j++)
			{
				if(a[i][j] == '+')
				{
					a[i][j] ='@';
				}
			}
	}
	for(i=1; i <= n; i++)
		for(j=1; j <= n; j++)
		{
			if(a[i][j] == '@')
				sum++;
		}
	cout << sum << endl;
}
int main(){
int n,i,j,k,m,num=0;
scanf("%d",&n);
char s[n][n+1];
int a[n][n];
for(i=0;i<n;i++){
scanf("%s",s[i]);
}
for(j=0;j<n;j++){
        for(k=0;k<n;k++){
            a[j][k]=0;
        }
}
scanf("%d",&m);
if(m==1){
    for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        if(s[i][j]=='@')
        a[i][j]=1;
    }
}
}
else
    {for(i=0;i<m-1;i++){
    for(j=0;j<n;j++){
        for(k=0;k<n;k++){
        if(s[j][k]=='@' && a[j][k]!=i+10){
        a[j][k]=1;
        if(j+1<n){
            if(s[j+1][k]=='.' &&  a[j][k]!=i+10){
        s[j+1][k]='@';
        a[j+1][k]=i+10;
        }
        }
        if(j-1>=0){
            if(s[j-1][k]=='.' &&  a[j][k]!=i+10){
        s[j-1][k]='@';
        a[j-1][k]=i+10;
        }
        }
        if(k+1<n){
            if(s[j][k+1]=='.' && a[j][k]!=i+10){
        s[j][k+1]='@';
        a[j][k+1]=i+10;
            }
            }
        if(k-1>=0){
            if(s[j][k-1]=='.' && a[j][k]!=i+10){
        s[j][k-1]='@';
        a[j][k-1]=i+10;
            }
        }
        }
        }
    }
}
}
for(j=0;j<n;j++){
        for(k=0;k<n;k++){
            if(a[j][k]!=0){
            num++;
        }
}
}
printf("%d",num);
return 0;
}
int main()
{
	int n,m,i,j,d=1,count=0;
	char c[200][200];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>c[i][j];
		}
	}
	cin>>m;
	
	while(d<m)
	{
		for(i=1;i<=n;i++)
	    {
		  for(j=1;j<=n;j++)
		  {
			if(c[i][j]=='.')
			{
				if((c[i-1][j]=='@')||(c[i][j-1]=='@')||(c[i][j+1]=='@')||(c[i+1][j]=='@'))
					c[i][j]='*';
			}
		  }
		}
		for(i=1;i<=n;i++)
	    {
		  for(j=1;j<=n;j++)
		  {
			if(c[i][j]=='*')
				c[i][j]='@';
		  }
		}
		d++;
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(c[i][j]=='@')
				count++;
		}
		
	}
	cout<<count<<endl;
	
	return 0;
}