semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int n=0,m=0;
	char a[110][110]={'\0'};
	int i=0,j=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>m;
	for(int k=0;k<m-1;k++)
	{
		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(i+1<n && a[i+1][j]=='.')
						a[i+1][j]='%';
					if(j-1>=0 && a[i][j-1]=='.')
						a[i][j-1]='%';
					if(j+1<n && a[i][j+1]=='.')
						a[i][j+1]='%';
				}
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(a[i][j]=='%')
					a[i][j]='@';
			}
		}
	}
	int num=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i][j]=='@')
				num++;
		}
	}
	cout<<num<<endl;
	return 0;
}
int main()
{
    char s[102][102];int n,m,i,j,k;
    cin>>n;
    cin.get();
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>s[i][j];
    for(i=0;i<=n+1;i++)
    {
        s[i][0]='#';
        s[i][n+1]='#';
    }
    for(j=0;j<=n+1;j++)
    {
        s[0][j]='#';
        s[n+1][j]='#';
    }
    cin>>m;
    for(k=1;k<m;k++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if (s[i][j]=='@')
                {
                    if(s[i-1][j]=='.')s[i-1][j]='*';
                    if(s[i+1][j]=='.')s[i+1][j]='*';
                    if(s[i][j-1]=='.')s[i][j-1]='*';
                    if(s[i][j+1]=='.')s[i][j+1]='*';
                }
            }
        }
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j++)
                if(s[i][j]=='*')s[i][j]='@';
    }
    int flag=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(s[i][j]=='@') flag++;
    cout << flag;
    return 0;
}
int main(){
	char a[102][102],c[102][102];
	int n,i,j,m,t,r=0,x,y;
	memset (a,'@',sizeof a);
	scanf("%d\n",&n);
	for(i=1;i<=n;i++){ 
	  for(j=1;j<=n;j++){ 
	    scanf("%c\n",&a[i][j]);
	    c[i][j]=a[i][j];
	  }  
	} 
	scanf("%d\n",&m);
for(t=1;t<m;t++){
	for(i=1;i<=n;i++)
	for(j=1;j<=n;j++){
		if(c[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(x=1;x<=n;x++)
	for(y=1;y<=n;y++)
	{c[x][y]=a[x][y];}
	} 
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
	if(a[i][j]=='@')
	r+=1;
}
printf("%d\n",r);
return 0; 
}
int main(){
	int i,j,m,n,k,p;
	char s[N][N];
	scanf("%d",&n);
	for(j=0;j<n;j++){
		scanf("%s",s[j]);
	}
	scanf("%d",&m);
	k=1;
	while(k<m){
		for(j=0;j<n;j++){
			for(i=0;i<n;i++){
				if(s[i][j]=='@'){
					if(i>0&&s[i-1][j]=='.'){
						s[i-1][j]='@'+1;
					}
					if(j>0&&s[i][j-1]=='.'){
						s[i][j-1]='@'+1;
					}
					if(i<n-1&&s[i+1][j]=='.'){
						s[i+1][j]='@'+1;
					}
					if(j<n-1&&s[i][j+1]=='.'){
						s[i][j+1]='@'+1;
					}
				}
			}
		}
		k++;
		for(j=0;j<n;j++){
			for(i=0;i<n;i++){
				if(s[i][j]=='@'+1){
					s[i][j]='@';
				}
			}
		}
	}
	p=0;
	for(j=0;j<n;j++){
		for(i=0;i<n;i++){
			if(s[i][j]=='@'){
				p++;
			}	
		}
	}
printf("%d",p);
	return 0;
}
int main()
{
  int count=0,t,n,i,j,m;
  char a[1000][1000],b[1000][1000];
  scanf("%d\n",&n);
  for (i=0;i<n;i++)
  {
   for (j=0;j<n;j++)
    {
        if (j==n-1)
        scanf("%c\n",&a[i][j]);
        else
        scanf("%c",&a[i][j]);
    }
  }
  scanf("%d",&m);
  for ( t=1;t<m;t++)
  {
   for (i=0;i<n;i++)
   {
    for (j=0;j<n;j++)
    {
     if (a[i][j]=='@')
      {
      if ( (i+1)<n && a[i+1][j]=='.' )
      b[i+1][j]='@';
      
      if ( (i-1)>=0 && a[i-1][j]=='.')
      b[i-1][j]='@';
        
      if ((j+1)<n  &&  a[i][j+1]=='.')
      b[i][j+1]='@';
       
      if ((j-1)>=0  &&  a[i][j-1]=='.')
      b[i][j-1]='@';
     }
    }
   }     for (i=0;i<n;i++)
        {
            for (j=0;j<n;j++)
               {
                if (b[i][j]=='@'&&a[i][j]!='#')
                     a[i][j]='@';
               } 
        }
   }
        for (i=0;i<n;i++)
         {
            for (j=0;j<n;j++)
             {
              if (a[i][j]=='@')
                 count++;
             }
         }
    /*  for (i=0;i<n;i++)
      {
          for (j=0;j<n;j++)
            {
               if (j==n-1)
                printf("%c\n",a[i][j]);
               else 
                printf("%c",a[i][j]);
            }
      }*/
printf("%d",count);
}
//#include <string>
int grids[100][100][100] = {0}; //day y x; grids: 0 noperson,1 healthyperson,2 illperson

int main()
{
	int n, i, j, k, day, illCount = 0;
	char stat;
	cin >> n;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
		{
			cin >> stat;
			switch (stat)
			{
			case '.':
				grids[0][i][j] = 1;
				break;
			case '#':
				grids[0][i][j] = 0;
				break;
			case '@':
				grids[0][i][j] = 2;
				illCount++;
				break;
			}
		};
	cin >> day;
	for (i = 1; i < day; i++)
		for (j = 0; j < n; j++)
			for(k = 0; k < n; k++)
			{
				if (grids[i - 1][j][k] == 2)
				{
					grids[i][j][k] = 2;
					if (j != 0 && grids[i - 1][j - 1][k] == 1 && grids[i][j - 1][k] != 2)
					{
						illCount++;
						grids[i][j - 1][k] = 2;
					}
					if (j != n - 1 && grids[i - 1][j + 1][k] == 1 && grids[i][j + 1][k] != 2)
					{
						illCount++;
						grids[i][j + 1][k] = 2;
					}
					if (k != 0 && grids[i - 1][j][k - 1] == 1 && grids[i][j][k - 1] != 2)
					{
						illCount++;
						grids[i][j][k - 1] = 2;
					}
					if (k != n - 1 && grids[i - 1][j][k + 1] == 1 && grids[i][j][k + 1] != 2)
					{
						illCount++;
						grids[i][j][k + 1] = 2;
					}
				}
				else
				{
					if (grids[i][j][k] != 2) 
						grids[i][j][k] = grids[i - 1][j][k];
				}
			}
	cout << illCount;
	return 0;
}
/*
 *  ????.cpp
 *  Created on: 2012-11-11
 *  Author: ???
 *  ??:???m???????
 */
int main() {
	int n, day, num = 0, i, j, k;//?????day???
	cin >> n;//??n
	char room1[n + 2][n + 2], room2[n + 2][n + 2], t;//room1???????????room2?????????
	t = getchar();//??????
	for (i = 1; i <= n; i++) {//????????
		for (j = 1; j <= n + 1; j++) {
			room1[i][j] = room2[i][j] = getchar();
		}
	}
	cin >> day;//????
	for (k = 1; k < day; k++) {//??day?
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				if (room2[i][j] == '@' || room2[i][j] == '#')
					continue;//??????????????????
				if (room1[i - 1][j] == '@' || room1[i + 1][j] == '@'
						|| room1[i][j - 1] == '@' || room1[i][j + 1] == '@') {//?????????
					room2[i][j] = '@';//?????
				}
			}
		}
		for (i = 1; i <= n; i++) {//?room1???room2????????
			for (j = 1; j <= n; j++) {
				room1[i][j] = room2[i][j];
			}
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (room2[i][j] == '@')
				num++;//?????@??????1
		}
	}
	cout << num << endl;//????????
	return 0;
}
int main()
{
    int n,i , j ,m ,time,num;
    char a[100][100];
    char b[100][100];
    num =0;
    cin>> n;
    for(i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            cin >> a[i][j];
        }
    }
    cin >> m;
    for (time=1;time<m;time++)
    {


        for(i =1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if (a[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]='@';
                    }
                    b[i][j]='@';
                }
                if (a[i][j]=='#')
                {
                    b[i][j]='#';
                }
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                a[i][j]=b[i][j];
            }
        }

    }
    for (i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if (a[i][j]=='@')
            num++;
        }
    }
    cout << num << endl;
    return 0;
}
int main() {
	int n;
	cin >>n;
	int room[100][100];
	for (int i=0;i<=n-1;++i)
	{
		for (int j=0;j<=n-1;++j)
		{
			char get;
			cin >>get;
			if (get=='.')
				room[i][j]=2;
			if (get=='#')
				room[i][j]=0;
			if (get=='@')
				room[i][j]=1;

		}
		getchar();
	}



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

	}






	int sumcought=0;
	for (int i=0;i<=n-1;++i)
	{
		for (int j=0;j<=n-1;++j)
		{
			if (room[i][j]==1)
				++sumcought;
		}
	}
	cout <<sumcought << endl;
	return 0;
}
int main()
{
	int n,m,sum=0;
	char a[102][102]={0},b[102][102]={0};
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
			b[i][j]=a[i][j];
		}
	}
	cin>>m;
	for(int j=2;j<=m;j++)
	{
	for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(a[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(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					a[i][j]=b[i][j];
				}
			}
				}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i][j]=='@')
			{
				sum++;
			}
		}
	}
	cout<<sum;
	return 0;
	}
int a[200][200] = {0};
int b[200][200] = {0};
int main() {
	int n, m;
	char tmp;
	scanf("%d", &n);
	getchar();
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			scanf("%c", &a[i][j]);
			if (a[i][j] == '@')
				b[i][j] = 1;

		}
		getchar();
	}
	scanf("%d", &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] == '@' && b[i][j] == k) {
					if (a[i+1][j] == '.') {
						a[i+1][j] = '@';
						b[i+1][j] = k+1;
					}
					if (a[i-1][j] == '.') {
						a[i-1][j] = '@';
						b[i-1][j] = k+1;
					}
					if (a[i][j+1] == '.') {
						a[i][j+1] = '@';
						b[i][j+1] = k+1;
					}
					if (a[i][j-1] == '.') {
						a[i][j-1] = '@';
						b[i][j-1] = k+1;
					}
				}
			}
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j)
			if (a[i][j] == '@')
				cnt++;
	}
	printf("%d", cnt);
}
int main()
{
	int n,i,j;
	int a[101][101]={0};
	char map[101][101];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf(" %c ",&map[i][j]);
			if(map[i][j]=='.')a[i][j]=1;     //1??????
			else if(map[i][j]=='#')a[i][j]=0;//0??????
			else a[i][j]=2   ;                 //2???????
		}
	}
	int m;
	scanf("%d",&m);
	m=m-1;
	while(m--)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]==2)
				{
					if(a[i-1][j]==1) a[i-1][j]=3;//3???????????
					if(a[i+1][j]==1) a[i+1][j]=3;
					if(a[i][j-1]==1) a[i][j-1]=3;
					if(a[i][j+1]==1) a[i][j+1]=3;
				}
			}
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]==3) a[i][j]=2;
			}
		}


		


	}
	int num=0;
	for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]==2) num++;
			}
		}
	printf("%d",num);


	
}
//*************************
//??:???? **
//??:??? 1300012991 **
//??:2013.11.11 **
//*************************

int main()
{
    int n, m, i, j, sum = 0; //sum??????, m????, n^2?????
    char sickman[101][101]; //sickman???????
 
    cin >> n; //?????
    memset (sickman, '#', sizeof(sickman)); //???????'#',?????
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
        {
            cin >> sickman[i][j]; //??????
          //  if( '\n' == sickman[i][j] )
            //    --j;
        }
 
	cin >> m; //????
      
    while(--m > 0) //???????????????????????????
    {
        for ( i = 0; i < n; i++)
            for ( j = 0; j < n; j++)
            {
                if (sickman[i][j] == '@') //??????
                {
                    if( i-1 >= 0 && sickman[i-1][j] == '.') //???????????= =,?????*
                        sickman[i-1][j] = '*';
                    if( i+1 < n  && sickman[i+1][j] == '.')
                        sickman[i+1][j] = '*';
                    if( j-1 >= 0  && sickman[i][j-1] == '.')
                        sickman[i][j-1] = '*';
                    if( j+1 < n  && sickman[i][j+1] == '.')
                        sickman[i][j+1] = '*';
                }
            }
 
        for( i = 0; i < n; i++)
            for( j = 0; j < n; j++)
                if(sickman[i][j] == '*') //*???@
                    sickman[i][j] = '@';
    }
 
    for( i = 0; i < n; i++)
        for( j = 0; j < n; j++)
                if(sickman[i][j] == '@') //@??????
                    ++sum;
	cout << sum; //???????
    return 0;
}
int main()
{
	char a[100][100];
    int i, j, k, l, n, n2, m, num = 0;

    cin >> n;
	n2 = n * n;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
		{	
			cin >> a[i][j];
			if (a[i][j] == '@')
                num++;
        }
    cin >> m; 
	for (k = 1; k < m; k++)
	{    
		 if (num >= n2)
			 break;
	     for (i = 0; i < n; i++)
		     for (j = 0; j < n; j++)
				 if (a[i][j] == '@')
				 {
					 if (i > 0 && a[i - 1][j] == '.')
					 {	 
                         a[i - 1][j] = '*';
						 num++;
					 }
					 if (j > 0 && a[i][j - 1] == '.')
					 {	 
                         a[i][j - 1] = '*';
					     num++;
					 }
					 if (i < n - 1 && a[i + 1][j] == '.' )
					 {	 
                         a[i + 1][j] = '*';
					     num ++;
					 }
					 if (j < n - 1 && a[i][j + 1] == '.' )
					 {
                         a[i][j + 1] = '*';
						 num ++;
					 }
				 }	
         for (i = 0; i < n; i++)
		     for (j = 0; j < n; j++)
				 if (a[i][j] == '*')
					 a[i][j] = '@';
				 
	}

	cout << num << endl;
	    return 0;
}
int n,i,j,k,m,r=0;
char a[100][101],b[100][101];
void cr(char a[100][101]);
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",a[i]);
	}
	scanf("%d",&m);
	cr(a);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i][j]=='@')
			{
				r++;
			}
		}
	}
	printf("%d",r);
	return 0;
}
void cr(char a[100][101])
{
	for(i=0;i<n;i++)
	{
		strcpy(b[i],a[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(b[i][j]=='@')
			{
				if(i!=0&&b[i-1][j]=='.')
				{
					a[i-1][j]='@';
				}
				if(j!=0&&b[i][j-1]=='.')
				{
					a[i][j-1]='@';
				}
				if(i!=n-1&&b[i+1][j]=='.')
				{
					a[i+1][j]='@';
				}
				if(j!=n-1&&b[i][j+1]=='.')
				{
					a[i][j+1]='@';
				}
			}
		}
	}
	m=m-1;
	if(m!=1)
	{
		cr(a);
	}
}
int main()
{
	int n=0,number=0,day=0;
	cin>>n;
	int nn=n*n;
	char a[nn];
	char b[nn];
	for(int iii=0;iii<n;iii++)
	for(int i=0;i<n;i++)
	cin>>a[n*iii+i];
	cin>>day;
	for(int m=1;m<day;m++)
	{for(int i=0;i<nn;i++)
		b[i]=a[i];
	for(int ii=0;ii<nn;ii++)
	{
		if(a[ii]=='@')
		{
			if(a[ii+1]!='#')
				{
				if((ii+1)%n!=0)
				b[ii+1]='@';
				}
			if(a[ii-1]!='#')
			{
							if((ii)%n!=0)
							b[ii-1]='@';
							}
			if(a[ii+n]!='#')
							b[ii+n]='@';
			if(a[ii-n]!='#')
							b[ii-n]='@';
		}
	}


	for(int w=0;w<nn;w++)
			a[w]=b[w];
	}
	for(int q=0;q<nn;q++)
			if(a[q]=='@')
				number=number+1;
		cout<<number;
	return 0;
}
void chuanran(char a[110][110],int n)
{
	int i,j;
	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]='A';
				if(a[i][j-1]=='.')
					a[i][j-1]='A';
				if(a[i+1][j]=='.')
					a[i+1][j]='A';
				if(a[i-1][j]=='.')
					a[i-1][j]='A';
			}
		}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(a[i][j]=='A')
				a[i][j]='@';
		}
}
int main()
{
	int n;
	cin >> n;
	char a[110][110];
	int i,j;
	for(i=0;i<=n+1;i++)
		for(j=0;j<=n+1;j++)
		{
			if(i==0||j==0||i==n+1||j==n+1){
				a[i][j]='#';
				continue;
			}
			cin >> a[i][j];
		}
	int m;
	cin >> m;
	m--;
	while(m--)
		chuanran(a,n);
	int sum=0;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i][j]=='@')
				sum++;
	cout << sum <<endl;
}
const int MAXN=10000;
 char a[MAXN+10][MAXN+10];
int main()
{
	static int n,i,j,m,k,g,sum=0,temp1[MAXN+10],temp2[MAXN+10],r;
	
	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++)
		{r=1;
	     for(i=1;i<=n;i++)
		   {for(j=1;j<=n;j++)
			   if(a[i][j]=='@')
			   {temp1[r]=i;temp2[r]=j;r+=1;}}
        for(g=1;g<r;g++)
			{i=temp1[g];j=temp2[g];
		     if(a[i+1][j]=='.') {a[i+1][j]='@';}
			 if(a[i][j+1]=='.') {a[i][j+1]='@';}
			 if(a[i-1][j]=='.') {a[i-1][j]='@';}
			 if(a[i][j-1]=='.') {a[i][j-1]='@';}}}
   for(i=1;i<=n;i++)
		{for(j=1;j<=n;j++)
	      {if(a[i][j]=='@'){sum+=1;}}}
	cout<<sum<<endl;

    return 0;
}
//****************************
//?????? 1200012971**
//???5.cpp **
//???2012.11.11 **
//****************************
int main()
{
	int i, j, n, a[100][100] = {0}, d, m = 0;                        //?????? 
	char  b[100][100];                                                 //????????
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)                                          //??????????
		{
			cin >> b[i][j];                                               //????????@?????????????????1
			if (b[i][j] == '@')
				a[i][j] = 1;
		}
	}
	cin >> d;                                                    //????
	for (int k = 1; k < d; k++)
	{
		for (i = 0; i < n; i ++)
		{
			for (j = 0; j < n; j ++)
			{
				if (b[i][j] == '@')                                //???????? ?????
				{
					if (j == 0)                                   //????????????????????????????????
					{
						if (i == 0)                                  //????????
						{
							a[i + 1][j] = 1;
							a[i][j + 1] = 1;
						}
						if (i == n - 1)                            //?????????
						{
							a[i - 1][j] = 1;
							a[i][j + 1] = 1;
						}
						if (i != 0 && i != n - 1)                //?????????????????
						{
							a[i - 1][j] = 1;
							a[i][j + 1] = 1;
							a[i + 1][j] = 1;
						}
					}
					if (j == n - 1)                              //??????
					{
						if (i == 0)                                //???????
						{
							a[i + 1][j] = 1;
							a[i][j - 1] = 1;
						}
						if (i == n - 1)                             //????????
						{
							a[i - 1][j] = 1;
							a[i][j - 1] = 1;
						}
						if (i != 0 && i != n - 1)                   //?????????????
						{
							a[i - 1][j] = 1;
							a[i][j - 1] = 1;
							a[i + 1][j] = 1;
						}
					}
					if (j != 0 && j != n - 1)                      //????????
					{
						if (i == 0)                                    //?????
						{
							a[i + 1][j] = 1;
							a[i][j - 1] = 1;
							a[i][j + 1] = 1;
						}
						if (i == n - 1)                            //??????
						{
							a[i - 1][j] = 1;
							a[i][j - 1] = 1;
							a[i][j + 1] = 1;
						}
						if (i != 0 && i != n - 1)                       //????????
						{
							a[i - 1][j] = 1;
							a[i][j - 1] = 1;
							a[i + 1][j] = 1;
							a[i][j + 1] = 1;
						}
					}
				}
			}
		}
		for (i = 0; i < n; i++)                                  //???????????@
		{
			for (j = 0; j < n; j ++)
			{
				if (a[i][j] == 1)
				{
					if (b[i][j] == '#')                            //????????????????0
						a[i][j] = 0;
					else 
						b[i][j] = '@';
				}
			}
		}
	}
	for (i = 0; i < n; i++)                                  //??????????????d???????
	{
		for (j = 0; j < n; j++)
		{
			m += a[i][j];
		}
	}
	cout << m;
	return 0;
	}
/*
 * cold.cpp
 * ??:???m??????
 *  Created on: 2013-1-13
 *      Author: ???
 */



int m=0,n=0,sum=0;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

void check();
void change();
char room[200][200];

int main()
{
	cin>>n;
	int i=0,j=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++){
			cin>>room[i][j];
			if(room[i][j]=='@')
			sum++;
		}
	cin>>m;
	for(i=1;i<m;i++)
	{
		check();
	    change();
	}
	cout<<sum<<endl;
	return 0;
}

void check()
{
	int i=0,j=0,k=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(room[i][j]=='@')
			for(k=0;k<4;k++)
				if(i+dx[k]>=0&&i+dx[k]<n&&j+dy[k]>=0&&j+dy[k]<n&&room[i+dx[k]][j+dy[k]]=='.')
					room[i+dx[k]][j+dy[k]]=',';
    return ;
}
void change()
{
	int i=0,j=0;
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(room[i][j]==','){
					sum++;
					room[i][j]='@';}
	return ;
}
int main()
{
	int n,i,j,k=0,m,s=0;
	char a[105][105],b[105][105];
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		gets(a[i]);
	}
	for(i=0;i<=n;i++)
		a[i][n]=a[n][i]='#';
	scanf("%d",&m);
	for(j=0;j<=n;j++)
		for(k=0;k<=n;k++)
				b[j][k]=a[j][k];
	for(i=1;i<m;i++)
	{
        for(j=0;j<n;j++)
		{
			for(k=0;k<n;k++)
			{
				if(a[j][k]=='.')
				{if(a[j][k+1]=='@'||a[j+1][k]=='@')
						b[j][k]='@';
				else 
				{if(k!=0)
				    if(a[j][k-1]=='@')
						b[j][k]='@';
			     if(i!=0)
					if(a[j-1][k]=='@')
						b[j][k]='@';
				}
				}
				else
					b[j][k]=a[j][k];
			}
		}
		for(j=0;j<n;j++)
			for(k=0;k<n;k++)
				a[j][k]=b[j][k];
	}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{if(a[i][j]=='@')
		s++;}
			printf("%d",s);
	return 0;
}
int main()
{
    int n,flag[105][105],i,j,m,sum=0;
    char a[105][105];
    cin>>n;
    for (i=1;i<=n;i++)
    {for (j=1;j<=n;j++)
    {cin>>a[i][j];
    if (a[i][j]=='#')
    flag[i][j]=-1;
    if (a[i][j]=='@')
    flag[i][j]=1;
    if (a[i][j]=='.')
    flag[i][j]==0;
    
    }
    }
    cin>>m;
    for (int k=2;k<=m;k++)
    {for (i=1;i<=n;i++)
         {for (j=1;j<=n;j++)
              {if (a[i][j]=='@'&&flag[i][j]<k)
                  {if (flag[i][j-1]==0){a[i][j-1]='@';flag[i][j-1]=k;}
                  if (flag[i][j+1]==0){a[i][j+1]='@';flag[i][j+1]=k;}
                  if (flag[i+1][j]==0){a[i+1][j]='@';flag[i+1][j]=k;}
                  if (flag[i-1][j]==0){a[i-1][j]='@';flag[i-1][j]=k;}}
              }
         }
    }
    for (i=1;i<=n;i++)
    {for (j=1;j<=n;j++)
    {if (a[i][j]=='@')sum++;
    }
    }
    cout<<sum;
    return 0;
}
int main(){
	int n,r,i,j,m;
	int sum=0;
	char sz[100][100],SZ[100][100],zfc[100];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%s",zfc);
      for(j=0;j<n;j++){
			sz[i][j+1]=zfc[j];
			SZ[i][j+1]=zfc[j];
		}
	}
	scanf("%d",&m);
	for(r=1;r<=m-1;r++){
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(sz[i][j]=='@'&&sz[i-1][j]!='#'){
					SZ[i-1][j]='@';
				}
				if(sz[i][j]=='@'&&sz[i+1][j]!='#'){
					SZ[i+1][j]='@';
				}
				if(sz[i][j]=='@'&&sz[i][j-1]!='#'){
					SZ[i][j-1]='@';
				}
				if(sz[i][j]=='@'&&sz[i][j+1]!='#'){
					SZ[i][j+1]='@';
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				sz[i][j]=SZ[i][j];
			}
		}
	}
	for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(sz[i][j]=='@'){
					sum++;
				}
			}
	}
	printf("%d",sum);
	return 0;
}
int main()
{
	int n,m,i,j,a,s,tj[102][102];
	char zf[102][102];
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++){
		gets(zf[i]);
	}
	scanf("%d",&m);
	s=0;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			tj[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(zf[i][j]=='@'){
				tj[i][j]=1;
				s++;
			}
		}
	}
	a=1;
	while(a<m){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(tj[i][j]==1){
					if(i>0&&zf[i-1][j]=='.'){
						zf[i-1][j]='@';
						s++; 
					}
					if(i<n-1&&zf[i+1][j]=='.'){
						zf[i+1][j]='@';
						s++;
					}
					if(j>0&&zf[i][j-1]=='.'){
						zf[i][j-1]='@';
						s++;
					}
					if(j<n-1&&zf[i][j+1]=='.'){
						zf[i][j+1]='@';
						s++;
					}
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(zf[i][j]=='@'){
					tj[i][j]=1;
			}
		}
	}
		a++;
	}
	printf("%d",s);
	return 0;
}
int n,m;
char c[110][110]={0};
int nextt[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
//. ???# ??@ ???& ????
void flu(int dep)
{
	int i,j,k;
	if (dep==m) return;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
		{
			if (c[i][j]=='@')
			{
				for (k=0;k<=3;k++)
				{
					int x,y;
					x=i+nextt[k][0];
					y=j+nextt[k][1];
					if (c[x][y]=='.')
					{
						c[x][y]='&';
					}
				}
			}
		}
    for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			if (c[i][j]=='&')
				c[i][j]='@';
	flu(dep+1);
}
int main()
{
	int i,j;
	cin >>n;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			cin >>c[i][j];
	cin >>m;
	flu(1);
	int total=0;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
		{
			if (c[i][j]=='@')
				total++;
		}
	cout <<total;
	return 0;
}