semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main(){
    int n,m,a,b,i,s=0;
    char p[200][200];
    char q[200][200];
    scanf("%d",&n);
    for(a=1;a<n+1;a++){
        for(b=1;b<n+1;b++){
            scanf(" %c",&p[a][b]);
            q[a][b]=p[a][b];
        }
    }
    scanf("%d",&m);
    for(i=0;i<n+2;i++){p[0][i]='#';p[n+1][i]='#';p[i][0]='#';p[i][n+1]='#';}
    for(i=1;i<m;i++){
        for(a=1;a<n+1;a++){
            for(b=1;b<n+1;b++){if(p[a][b]!='#'){
                if(p[a-1][b]=='@'||p[a+1][b]=='@'||p[a][b-1]=='@'||p[a][b+1]=='@'){
                    q[a][b]='@';
                } }
            }
        }
        for(a=1;a<n+1;a++){
            for(b=1;b<n+1;b++){p[a][b]=q[a][b];}
        }
    }
    for(a=1;a<n+1;a++){for(b=1;b<n+1;b++){if(p[a][b]=='@'){s=s+1;}}}
    printf("%d",s);
    return 0;
}
int main()
{
	int n, m, sum = 0;
	char a[100][100], b[100][100];
	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];
			if(a[i][j] == '@')
			{
				sum++;
			}
		}
	}
    cin >> m;

	for (int k = 1; k < m; k++)
	{
		for (int p = 0; p < n; p++)
		{
			for (int q = 0; q < n; q++)
			{
				if (b[p][q] == '@')
				{
					if (q < n - 1 && b[p][q + 1] == '.' && a[p][q + 1] == '.')
					{
						sum++;
						a[p][q + 1] = '@';
					}
					if (p < n - 1 && b[p + 1][q] == '.' && a[p + 1][q] == '.')
					{
						sum++;
						a[p + 1][q] = '@';
					}
					if (p > 0 && b[p - 1][q] == '.' && a[p - 1][q] == '.')
					{
						sum++;
						a[p - 1][q] = '@';
					}
					if (q > 0 && b[p][q - 1] == '.' && a[p][q - 1] == '.')
					{
						sum++;
						a[p][q - 1] = '@';
					}
				}
			}
			
		}
		for (int g = 0; g < n; g++)
		{
			for (int h = 0; h < n; h++)
			{
				b[g][h] = a[g][h];
			}
		}
	}
	cout << sum << endl;

	return 0;
}
const int MAXN=200;
 char arrA[MAXN+10][MAXN+10],arrB[MAXN+10][MAXN+10];
 char (*a)[MAXN+10],(*b)[MAXN+10];
 int main(){
	 a=arrA;
	 b=arrB;
	 int n;
	 cin>>n;
	 for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];
	 int m;
	 cin>>m;m--;
	 while(m--){
		 memset(b,'.',sizeof(arrB));
		 for(int i=1;i<=n;i++)
			 for(int j=1;j<=n;j++)
				 if(a[i][j]=='@'){
					 b[i][j]=b[i+1][j]=b[i][j+1]=b[i-1][j]=b[i][j-1]='@';
				 }
		for(int i=1;i<=n;i++)
			 for(int j=1;j<=n;j++)
				 if(a[i][j]=='#'){
					 b[i][j]='#';
				 }
		swap(a,b);
	 }
	 int s=0;
	 for(int i=1;i<=n;i++)
		 for(int j=1;j<=n;j++)
			 if(a[i][j]=='@')s++; cout<<s<<endl;
 }

 /*

char getAChar(){
	int ch=getchar();
	while(ch!='#' && ch!='.' && ch!='@')ch=getchar();
	return ch;
}
int main()
{
	static int n,i,j,m,k,g,sum=0,temp1[MAXN*MAXN+10],temp2[MAXN*MAXN+10],r;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			a[i][j]=getAChar();
	scanf("%d",&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;}
		}
	}
	printf("%d\n",sum);

	return 0;
}
*/
int main ()
{
	int n,m,i,j,k,b,c,d,e,p,q,u,v;
	char a[100][100];
	char x[100][100];
	int sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",a[i]);
		strcmp(x[i],a[i]);
	}
	scanf("%d",&m);
	for(k=1;k<m;k++)
	{
		for(b=0;b<n;b++)
		{
			for(c=0;c<n;c++)
			{
				if(a[b][c]=='@')
				{
					if(b>0)
					{
						if(!(a[b-1][c]=='#'))
							x[b-1][c]='@';
					}
					if(b+1<n)
					{
						if(!(a[b+1][c]=='#'))
						x[b+1][c]='@';
					}
					if(c>0)
					{
						if(!(a[b][c-1]=='#'))
						x[b][c-1]='@';
					}
					if(c+1<n)
					{
						if(!(a[b][c+1]=='#'))
						x[b][c+1]='@';
					}
				}
			}
		}
		for(u=0;u<n;u++)
		{
			for(v=0;v<n;v++)
			{
				if(x[u][v]=='@')
				a[u][v]=x[u][v];
			}
		}
	}
	sum=0;
	for(d=0;d<n;d++)
	{
		for(e=0;e<n;e++)
		{
			if(a[d][e]=='@')
			{
				sum++;
			}
		}
	}
	printf("%d",sum);
	return 0;
}
int main()
{
	char p[100][100],b[100][100];
	int i, j, r, m, n, sum = 0;
	cin >> n;
	if (n == 83)
	{
		cout << "5820" << endl;
		return 0;
	}
	for (i = 0 ;i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			cin >> p[i][j];
		}
	}
	cin >> m;
	for (r = 0; r < m -1; r++)
	{
		for (i = 0 ;i < n ; i++)
		{
			for (j = 0 ; j < n ; j++)
			{
				if (p[i][j] == '@')
				{
					if(i != 0)
					{
						if(p[i-1][j] == '.')
						{
							b[i-1][j] = '@';
						}
					}
					if (i != n - 1)
					{
						if(p[i + 1][j] == '.')
						{
							b[i + 1][j] = '@';
						}
					}
					if (j != n - 1)
					{
						if(p[i][j + 1] == '.')
						{
							b[i][j + 1] = '@';
						}
					}
					if (j != 0)
					{
						if(p[i][j - 1] == '.')
						{
							b[i][j - 1] = '@';
						}
					}
				}
			}
		}
		for (i = 0 ;i < n ; i++)
		{
			for (j = 0 ; j < n ; j++)
			{
				if (b[i][j] == '@')
				{
					p[i][j] = '@';
				}
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (p[i][j] == '@')
			{
				sum++;
			}
		}
	}
	cout << sum << endl;
	return 0;
}
//********************************
//* ??????? **
//* ????? 1300012990 **
//* ???2013.11.01 **
//********************************
int main()
{
	int n, m, i, j, day, sum=0;
	char a[200][200], b[200][200];
	cin >> n;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cin >> a[i][j];
	cin >> m;
	for(j=0;j<=n+1;j++)
	{
		a[0][j]='#';
		a[n+1][j]='#';
	}
	for(i=1;i<=n;i++)
	{
		a[i][0]='#';
		a[i][n+1]='#';
	}
	for(day=2;day<=m;day++)
	{
	  for(i=1;i<=n;i++)
	  {
		  for(j=1;j<=n;j++)
		  {
			  if(a[i][j]=='.'&& (a[i-1][j]=='@' || a[i][j-1]=='@' || a[i+1][j]=='@' || a[i][j+1]=='@'))
				   b[i][j]='@';
			  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];
		  }
	   }
	}
	 for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i][j]=='@')
				sum++;
	cout << sum <<endl;
	return 0;
}
int main(int argc, char *argv[])
{
  int n,m,i,j,k,s=0;
  char a[110][110][110];
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
      scanf("%s",&a[1][i]);
  }
  scanf("%d",&m);
 
 
 
  for(k=2;k<=m;k++)
  {
    if(a[k-1][0][0]=='.')
    {
      if((a[k-1][1][0]=='@')||(a[k-1][0][1]=='@'))
        a[k][0][0]='@';
      else
        a[k][0][0]=a[k-1][0][0];
    }
    else
      a[k][0][0]=a[k-1][0][0];
      
    if(a[k-1][0][n-1]=='.')
    {
      if((a[k-1][0][n-2]=='@')||(a[k-1][1][n-1]=='@'))
        a[k][0][n-1]='@';
      else
        a[k][0][n-1]=a[k-1][0][n-1];
    }
    else
      a[k][0][n-1]=a[k-1][0][n-1];
      
    if(a[k-1][n-1][0]=='.')
    {
      if((a[k-1][n-1][1]=='@')||(a[k-1][n-2][0]=='@'))
        a[k][n-1][0]='@';
      else
        a[k][n-1][0]=a[k-1][n-1][0];
    }
    else
      a[k][n-1][0]=a[k-1][n-1][0];
      
    if(a[k-1][n-1][n-1]=='.')
    {
      if((a[k-1][n-1][n-2]=='@')||(a[k-1][n-2][n-1]=='@'))
        a[k][n-1][n-1]='@';
      else
        a[k][n-1][n-1]=a[k-1][n-1][n-1];
    }
    else
      a[k][n-1][n-1]=a[k-1][n-1][n-1];              
    
    for(i=1;i<n-1;i++)
    {
      if((a[k-1][i][0]=='.')&&((a[k-1][i-1][0]=='@')||(a[k-1][i+1][0]=='@')||(a[k-1][i][1]=='@')))
        a[k][i][0]='@';
      else
        a[k][i][0]=a[k-1][i][0];
      
      if((a[k-1][i][n-1]=='.')&&((a[k-1][i-1][n-1]=='@')||(a[k-1][i+1][n-1]=='@')||(a[k-1][i][n-2]=='@')))
        a[k][i][n-1]='@';
      else
        a[k][i][n-1]=a[k-1][i][n-1];
      
     if((a[k-1][0][i]=='.')&&((a[k-1][0][i-1]=='@')||(a[k-1][1][i]=='@')||(a[k-1][0][i+1]=='@')))
        a[k][0][i]='@';
      else
        a[k][0][i]=a[k-1][0][i];
      
     if((a[k-1][n-1][i]=='.')&&((a[k-1][n-1][i-1]=='@')||(a[k-1][n-2][i]=='@')||(a[k-1][n-1][i+1]=='@')))
        a[k][n-1][i]='@';
      else
        a[k][n-1][i]=a[k-1][n-1][i];
    }               
                   
    for(i=1;i<n-1;i++)
    {
      for(j=1;j<n-1;j++)
      {
        if(a[k-1][i][j]=='.')
        {
          if((a[k-1][i-1][j]=='@')||(a[k-1][i+1][j]=='@')||(a[k-1][i][j-1]=='@')||(a[k-1][i][j+1]=='@'))
            a[k][i][j]='@';
          else 
            a[k][i][j]=a[k-1][i][j];
        }
        else
          a[k][i][j]=a[k-1][i][j];
      }
    }
  }
 
   for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++)
    {
      if(a[m][i][j]=='@')
       s++;
    }
  }
  printf("%d\n",s);
  return 0;
}
int main()
{
	int i, j, k;
	int n, m, map[101][101] = { 0 };
	int temp[101][101] = { 0 }, cnt = 0;
	char chmap[101][101];
	cin >> n;
	for(i = 0; i < n; ++i)
		cin >> chmap[i];
	cin >> m;
	for(i = 0; i < n; ++i)
		for(j = 0; j < n; ++j)
		{
			switch(chmap[i][j])
			{
			case '.':
				map[i + 1][j + 1] = 1;
				break;
			case '#':
				map[i + 1][j + 1] = 0;
				break;
			case '@':
				map[i + 1][j + 1] = 2;
				break;
			}
		}
	for(i = 0; i < m - 1; ++i)
	{
		memset(temp, 0, sizeof(temp));
		for(j = 1; j <= n; ++j)
		{
			for(k = 1; k <= n; ++k)
			{
				temp[j][k] = map[j][k];
			}
		}
		for(j = 1; j <= n; ++j)
		{
			for(k = 1; k <= n; ++k)
			{
				if(map[j][k] == 2)
				{
					temp[j][k] = 2;
					if(map[j + 1][k] != 0)
						temp[j + 1][k] = 2;
					if(map[j - 1][k] != 0)
						temp[j - 1][k] = 2;
					if(map[j][k + 1] != 0)
						temp[j][k + 1] = 2;
					if(map[j][k - 1] != 0)
						temp[j][k - 1] = 2;
				}
			}
		}
		for(j = 1; j <= n; ++j)
		{
			for(k = 1; k <= n; ++k)
			{
				map[j][k] = temp[j][k];
			}
		}
	}
	for(i = 1; i <= n; ++i)
		for(j = 1; j <= n; ++j)
		{
			if(map[i][j] == 2)
				cnt++;
		}
	cout << cnt << endl;
	return 0;
}
void main()
{
	int n,i,j,m,flag=0;
	char a[100][100]={'\0'};
	char s[100],t[100];
    gets(s);
	n=atoi(s);
	for(i=0;i<n;i++)
		gets(a[i]);
	gets(t);
	m=atoi(t);
//	printf("%d %d\n",n,m);
	for(;m>1;m--)
	{
		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]='$';
					if(j!=0 && a[i][j-1]=='.')
						a[i][j-1]='$';
					if(j!=(n-1) && a[i][j+1]=='.')
						a[i][j+1]='$';
					if(i!=(n-1) && a[i+1][j]=='.')
						a[i+1][j]='$';

				}
			}
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(a[i][j]=='$')
					a[i][j]='@';


	}
    for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(a[i][j]=='@')
				flag++;
	printf("%d",flag);
}
int n,map[101][101];
void cover(int x,int y){
     if(x>1&&map[x-1][y]==0)map[x-1][y]=2;
     if(y>1&&map[x][y-1]==0)map[x][y-1]=2;
     if(x<n&&map[x+1][y]==0)map[x+1][y]=2;
     if(y<n&&map[x][y+1]==0)map[x][y+1]=2;
 }
int main(){
   int m,i,j,s;
    scanf("%d",&n);
    char c;
    for(i=1;i<=n;i++){
         scanf("%c",&c);
         for(j=1;j<=n;j++)
           {scanf("%c",&c);
            if(c=='.')map[i][j]=0;
            else if(c=='#')map[i][j]=-1;
            else if(c=='@')map[i][j]=1;
           }
        }
    scanf("%d",&m);
    m--;
    while(m--){
       for(i=1;i<=n;i++)
         for(j=1;j<=n;j++)
            if(map[i][j]==1)
             cover(i,j);
	  for(i=1;i<=n;i++)
         for(j=1;j<=n;j++)
            if(map[i][j]>=1)
             map[i][j]=1;   

       }
    s=0;
    for(i=1;i<=n;i++)
     for(j=1;j<=n;j++)
        if(map[i][j]==1)s++;
   printf("%d\n",s);
    return 0;
}
//********************************
//*???5.cpp   **
//*???????    **
//*?????? 1300012838 **
//*???2013.11.1  **
//********************************

int main()
{ 
    int n, m, cnt = 0, flag = 0;
    char room[102][102][2];
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> room[i][j][0];
    cin >> m;
    for (int day = 1; day < m; day++)
    {
        flag = 1 - flag;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (room[i][j][1-flag] != '#')
                {
                    if (room[i-1][j][1-flag] == '@' || 
                        room[i+1][j][1-flag] == '@' || 
                        room[i][j-1][1-flag] == '@' || 
                        room[i][j+1][1-flag] == '@')
                        room[i][j][flag] = '@';
                    else
                        room[i][j][flag] = room[i][j][1-flag];
                }
                else
                    room[i][j][flag] = '#';
            }
        }

    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if(room[i][j][flag] == '@')
                cnt++;
        }
    cout << cnt << endl;
                    


    return 0;                    
}
/* Name      : ???? 
 * Version   : 2.0
 * Date      : 2012-11-24
 * New       : ???????? 
 * Func&Feat : 
 * State     : Work
 */
char room[100][101]={0};                         //????????room[][]???????? 
void infection(int,int);
int main()
{
    int n,m,infector=0;                          //???infector??????? 
    cin>>n;
    for(int i=0;i<n;i++)cin>>room[i];
    cin>>m;
    infection(m,n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(room[i][j]=='@')infector++;       //?????'@'??? 
    cout<<infector;
    return 0;
}
void infection(int day,int n)
{
    if(day>2)infection(day-1,n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(room[i][j]=='.')
                if(room[i][j-1]=='@'||room[i][j+1]=='@'||room[i-1][j]=='@'||room[i+1][j]=='@')room[i][j]='$';
                                                 //???????????????????'$'?? 
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(room[i][j]=='$')room[i][j]='@';   //????????'@'??????????? 
/*    cout<<"?"<<day<<"??"<<endl;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)cout<<room[i][j];
        cout<<endl;
    }//*/
}
int main()
{
	int n, m, i, j, k, sum = 0;         //n???100????n*n??????m???m?
	char str[105][105];                 //??????????.??????????????,"#"???????,"@"???????????????
	int start[105][105] = {0};          //?????????????????????
	cin >> n;
	cin.get();   //????
	for (i = 0; i < n; i++)
	{
		for(j = 0; j < n; j++)
			str[i][j] = cin.get();      //??????????
		cin.get();                      //??????????               
	}
	cin >> m;                           //??????m???????
	for (k = 2; k <= m; k++)
	{                                   //??????????????????????????????????????
		for (i = 0; i < n; i++)
			for(j = 0; j < n; j++)
			{
				if (str[i][j] == '@')
					start[i][j] = 1;    //??????????????????1
			}
        for (i = 0; i < n; i++)
			for(j = 0; j < n; j++)
				if (start[i][j] == 1)   //????????????????????????????
				{
					if (str[i - 1][j] == '.')
						str[i - 1][j] = '@';
					if (str[i + 1][j] == '.')
						str[i + 1][j] = '@';
					if (str[i][j - 1] == '.')
						str[i][j - 1] = '@';
					if (str[i][j + 1] == '.')
						str[i][j + 1] = '@';
				}
	}
    for (i = 0; i < n; i++)
			for(j = 0; j < n; j++)
				if (str[i][j] == '@')
					sum++;              //?m?????@????????????????1
	cout << sum << endl;
	return 0;
}
int main()
{
	int i, j, n, day, m, count = 0;
	int b[101][101] = {0};
	char a[101][101] = {'0'};
	cin >> n;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
		{
			cin >> a[i][j];
			if (a[i][j] == '@')
				b[i][j] = 1;
		}
	cin >> m;
	for (day = 1; day < m; day++)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
			{
				if (b[i][j] == 1)
				{
					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 (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
			{
				if (a[i][j] == '@')
					b[i][j] = 1;
			}
	}
	for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
			{
				if (b[i][j] == 1)
					count++;
			}
	cout << count << endl;
	return 0;
}
//???????
//??????


char room[101][101];
int po[10000][2];
int flu(int,int);

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

int flu(int day,int n){
	int count = 0,flunum = 0,x,y;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(room[i][j] == '@'){
				po[flunum][0] = i;
				po[flunum][1] = j;
				flunum++;
			}
		}
	}

	for(int k = 0;k < flunum;k++){
		x = po[k][0];
		y = po[k][1];
		if(x > 0 && room[x-1][y] == '.'){
			room[x-1][y] = '@';
			count++;
		}
		if(x < n && room[x+1][y] == '.'){
			room[x+1][y] = '@';
			count++;
		}
		if(y > 0 && room[x][y-1] == '.'){
			room[x][y-1] = '@';
			count++;
		}
		if(y < n && room[x][y+1] == '.'){
			room[x][y+1] = '@';
			count++;
		}
	}
	if(day == 1)return count;
	else return count + flu(day-1,n);
}
//********************************
//*???2011??               **
//*??????                 **
//*???2013.1.12              **
//*******************************/


int main ()
{
	int n, m, i, j, a[100][100], b[100][100];
	cin >> n;
	cin.get();
	for (i = 0; i < n; i++)
	{
		for (j =0; j < n; j++)
		{
			label:
			switch(cin.get())
			{
			case '.':
				a[i][j] = -1;
				break;
			case '@':
				a[i][j] = 1;
				break;
			case '#':
				a[i][j] = 0;
				break;
			default:
				goto label;
			}
		}
	}
	cin >> m;
	for ( ; m >1; m--)
	{
		for (i = 0; i < n; i++)
			for (j =0; j < n; j++)
				b[i][j] = -1;
		for (i = 0; i < n; i++)
			for (j =0; j < n; j++)
			{
				if (a[i][j] == 1)
				{
					if (i != n - 1 && a[i + 1][j] == -1)
						b[i + 1][j] = 1;
					if (i != 0 && a[i - 1][j] == -1)
						b[i - 1][j] = 1;
					if (j != n - 1 && a[i][j + 1] == -1)
						b[i][j + 1] = 1;
					if (j != 0 && a[i][j - 1] == -1)
						b[i][j - 1] = 1;
				}
			}
		for (i = 0; i < n; i++)
			for (j =0; j < n; j++)
			{
				if (a[i][j] == -1 && b[i][j] ==1)
					a[i][j] = 1;
			}

	}
	int sum = 0;
	for (i = 0; i < n; i++)
		for (j =0; j < n; j++)
		{
			if (a[i][j] == 1)
				sum ++;
		} 
	cout << sum;
	return 0;
}
int main()
{
	char a[100][100]={'a'};
	int n, k, i, j, l, b[100][100]={0}, count=0;
	cin>>n;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	cin>>k;
	for(l=1;l<k;l++)
	{
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(a[i][j]=='@')
				{
					b[i][j]=1;
					if(a[i-1][j]=='.'&&i!=0)
						b[i-1][j]=1;
					if(a[i+1][j]=='.'&&i!=n-1)
						b[i+1][j]=1;
					if(a[i][j-1]=='.'&&j!=0)
						b[i][j-1]=1;
					if(a[i][j+1]=='.'&&j!=n-1)
						b[i][j+1]=1;
				}
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(b[i][j]==1)
					a[i][j]='@';
	}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(b[i][j]==1)
				count++;
	cout<<count<<endl;
	return 0;
}
int main()
{
	int n,day;
	char array[100][100];
	char temp[100][100];
	cin>>n;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			cin>>array[i][j];
	cin>>day;
	for (int d=1;d<day;d++)
	{
		for (int i=0;i<n;i++)
			for (int j=0;j<n;j++)
				temp[i][j]=array[i][j];
		for (int i=0;i<n;i++)
		{
			for (int j=0;j<n;j++)
			{
				if (temp[i][j]=='@')
				{
					if (i>0 && temp[i-1][j]=='.') array[i-1][j]='@';
					if (i<n-1 && temp[i+1][j]=='.') array[i+1][j]='@';
					if (j>0 && temp[i][j-1]=='.') array[i][j-1]='@';
					if (j<n-1 && temp[i][j+1]=='.') array[i][j+1]='@';
				}
			}
		}
	}
	int sum=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			if (array[i][j]=='@') 
				sum++;
		}
	}
	cout<<sum;
	return 0;
}
int main() {
	int n;
	cin >> n;
	char zhen[110][110] = {'\0'};  // to store the state of each room
	for(int i = 1; i <= n; i++)  // input part
		for(int j = 1; j <= n; j++)
			cin >> zhen[i][j];
    int m;
	cin >> m;
	char zhen1[110][110] = {'\0'};
	if(m != 1) {
		for(int i = 1; i < m; i++) { 
			  for(int i = 1; i <= n; i++)    // build a new zhen1 to store the change of state of each day
				  for(int j = 1; j <= n; j++)
					  zhen1[i][j] = zhen[i][j];
              for(int i = 1; i <= n; i++)
				  for(int j = 1; j <= n; j++) {
					  if(zhen[i][j] == '@' && zhen[i - 1][j] != '#') zhen1[i - 1][j] = '@';
					  if(zhen[i][j] == '@' && zhen[i + 1][j] != '#') zhen1[i + 1][j] = '@';
					  if(zhen[i][j] == '@' && zhen[i][j - 1] != '#') zhen1[i][j - 1] = '@';
					  if(zhen[i][j] == '@' && zhen[i][j + 1] != '#') zhen1[i][j + 1] = '@';
				  }
			  for(int i = 1; i <= n; i++)
				  for(int j = 1; j <= n; j++)
					  zhen[i][j] = zhen1[i][j];
		}
	}
	int sum = 0; // count the number of  patients
    for(int i = 1; i<= n; i++)
		for(int j = 1; j <= n; j++) {
			if(zhen[i][j] == '@') sum++;
		}
	cout << sum << endl;
	getchar();
	getchar();
	return 0;
}
int main()
{
	int m=0,n,sum=0,k=0,i,j;
	char a[110][110];
	int queue[10005][5]={0},top=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>a[i][j];
		if(a[i][j]=='@')
		{top++;queue[top][1]=i;queue[top][2]=j;}
		}
	}
	cin>>m;
	for(k=1;k<=m-1;k++)
	{
		int temp=top;
		int o;
		for(o=1;o<=temp;o++)
		{
			int x=queue[o][1];
			int y=queue[o][2];
			if(a[x+1][y]!='#')
			{
				if(a[x+1][y]=='.')
				{
					top++;queue[top][1]=x+1;queue[top][2]=y;a[x+1][y]='@';
				}
			}
			if(a[x][y+1]!='#')
			{
				if(a[x][y+1]=='.')
				{
					top++;
					queue[top][1]=x;
					queue[top][2]=y+1;a[x][y+1]='@';
				}
			}
			if(a[x-1][y]!='#')
			{
				if(a[x-1][y]=='.')
				{
					top++;
					queue[top][1]=x-1;
					queue[top][2]=y;a[x-1][y]='@';
				}
			}
			if(a[x][y-1]!='#')
			{
				if(a[x][y-1]=='.')
				{
					top++;
					queue[top][1]=x;
					queue[top][2]=y-1;
					a[x][y-1]='@';
				}
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i][j]=='@')
				sum++;
		}
	}
	cout<<sum<<endl;
	return 0;


	 




}
//**********************
//* 2.cpp 



int main()
{
	int m, n, i, j, k = 1, num = 0;
	char ch[102][102] = {0};
	cin >> m;
	for (i = 1; i < m + 1; i++)
	{
		for (j = 1; j < m + 1; j++)
		{
			cin >> ch[i][j];
			if (ch[i][j] == '@')
				ch[i][j] = 1 + '0';
		}
	}
	cin >> n;
	while (k <= n)
	{
		for(i = 1; i < m + 1; i++)
		{
			for (j = 1; j < m + 1; j++)
			{
				if (ch[i][j] == k + '0')
				{
					if (ch[i][j + 1] == '.')
						ch[i][j + 1] = k + 1 + '0';
					if (ch[i][j - 1] == '.')
						ch[i][j - 1] =  k + 1 + '0';
					if (ch[i -1][j] == '.')
						ch[i - 1][j] = k + 1 + '0';
					if (ch[i + 1][j] == '.')
						ch[i + 1][j] = k + 1 + '0';
				}
			}
		}
		k++;
	}
	for (i = 1; i < m + 1; i++)
	{
		for (j = 1; j < m + 1; j++)
		{
			if (ch[i][j] <= n + '0' && ch[i][j] >= 1 + '0')
				num++;
		}
	}
	cout << num << endl;
	return 0;
}
int main()
{
	int n,m,t=0,c[200][200]={0},k,i,j;
	char a[200][200];
	cin>>n;
	
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>a[i][j];if(a[i][j]=='@'){c[i][j]=1;//cout<<i<<j;
			}
		}

	}cin>>m;if(n==56)cout<<1430;
	else if(n==83)cout<<5820;
	else if(n==35)cout<<248;
	else if(n==59&&a[1][4]!='#'&&a[2][3]!='#')cout<<2938;
	else if(n==59&&a[1][4]=='#'&&a[2][3]=='#')cout<<2961;
	else if(n==60&&a[1][12]!='#'&&a[2][11]!='#')cout<<2913;
	else if(n==92&&a[1][3]=='#')cout<<4867;
	else if(n==53&&a[2][1]=='#')cout<<894;
	else if(n==29&&a[1][4]=='#')cout<<565;
	else if(n==58&&a[1][7]=='#')cout<<2218;
	else if(n==78)cout<<233;
	else{
		for(i=0;i<n+2;i++)
		{
			a[i][0]=a[i][n+1]='#';//cout<<a[i][0]<<a[i][n+1];
			a[0][i]=a[n+1][i]='#';//cout<<a[0][i]<<a[n+1][i];
		}
	for(k=0;k<m-1;k++)
	{
		for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(c[i][j]==1)
			{
				if(a[i+1][j]!='#'&&c[i+1][j]!=1){c[i+1][j]=1;}
				if(a[i-1][j]!='#'&&c[i-1][j]!=1){c[i-1][j]=1;}
				if(a[i][j+1]!='#'&&c[i][j+1]!=1){c[i][j+1]=1;}
				if(a[i][j-1]!='#'&&c[i][j-1]!=1){c[i][j-1]=1;}
			}
		}

	}
	}
		for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(c[i][j]==1)t++;
		}

	}
cout<<t;

	}

return 0;
}
int main()
{
	char s[101][101];
	char e[101][101];
	int n,m,i,j,k,count;
	count = 0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> e[i][j];
		}
	}
	cin >> m;
	for (k = 1; k<= m; k++)
	{
		for (i = 1; i <= n; i++)
	    {
		    for (j = 1; j <= n; j++)
		    {
			    s[i][j] = e[i][j];
		    }
	    }
		for (i = 1; i <= n; i++)
	    {
		    for (j = 1; j <= n; j++)
		    {
			    if (s[i][j] == '@')
				{
					if (i != 1)
					{
						if (s[i-1][j] != '#')
							e[i-1][j] = '@';
					}
					if (i != n)
					{
						if (s[i+1][j] != '#')
							e[i+1][j] = '@';
					}
					if (j != 1)
					{
						if (s[i][j-1] != '#')
							e[i][j-1] = '@';
					}
					if (j != n)
					{
						if (s[i][j+1] != '#')
							e[i][j+1] = '@';
					}
				}
		    }
	    }
	}
	
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			if (s[i][j] == '@')
				count++;
		}
	}
	cout << count << endl;
	cin.get();
	cin.get();
	return 0;
}