semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
//void spread(int x,int y,char **a){
//	if(a[x-1][y]!='#') a[x-1][y]='@';
//	if(a[x+1][y]!='#') a[x+1][y]='@';
//	if(a[x][y-1]!='#') a[x][y-1]='@';
//	if(a[x][y+1]!='#') a[x][y+1]='@';
//}

int main(){
	int n,m;
	cin>>n;
	char a[n][n];
//	char *ap=&a[0][0];
	for(int i=0;i<=n-1;++i)
		for(int j=0;j<=n-1;++j)
			cin>>a[i][j];
	cin>>m;
	for(int day=1;day<m;day++){
	for(int i=0;i<=n-1;++i)
		for(int j=0;j<=n-1;++j){
			if(a[i][j]=='@') {
			if(a[i-1][j]=='.'&&i-1>=0) a[i-1][j]='A';
			if(a[i+1][j]=='.'&&i+1<=n-1) a[i+1][j]='A';
			if(a[i][j-1]=='.'&&j-1>=0) a[i][j-1]='A';
			if(a[i][j+1]=='.'&&j+1<=n-1) a[i][j+1]='A';
			}
		}
		for(int i=0;i<=n-1;++i)
			for(int j=0;j<=n-1;++j)
				if(a[i][j]=='A') a[i][j]='@';
	}
	int count=0;
	for(int i=0;i<=n-1;++i)
		for(int j=0;j<=n-1;++j)
			if(a[i][j]=='@')count++;
	cout<<count;
	return 0;
}
int n,i,j,k,m,ans;
char box[120][120];
char box2[120][120];

int main()
{
    ans=0;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>box[i];
        for (j=n;j>=1;j--) box[i][j]=box[i][j-1];
    }
    cin>>m;
    for (k=1;k<m;k++)
    {
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
                box2[i][j]=box[i][j];
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
                if (box[i][j]=='@')
                {
                    if (box2[i][j-1]=='.') box2[i][j-1]='@';    
                    if (box2[i][j+1]=='.') box2[i][j+1]='@';    
                    if (box2[i-1][j]=='.') box2[i-1][j]='@';    
                    if (box2[i+1][j]=='.') box2[i+1][j]='@';
                }
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
                box[i][j]=box2[i][j];
    }
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
            if (box[i][j]=='@') ans++;    
    cout<<ans<<endl;
    return 0;
}
int main()
{
	int n=0,m=0,i=0,j=0;
	cin>>n;
	char a[n][n];
	int b[n][n];
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{
			cin>>a[i][j];
			b[i][j]=0;
		}
	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]=='@')&&(b[i][j]==0))
				{
					if((i-1>=0)&&(a[i-1][j]=='.')){a[i-1][j]='@';b[i-1][j]=1;}
					if((i+1<n)&&(a[i+1][j]=='.')){a[i+1][j]='@';b[i+1][j]=1;}
					if((j-1>=0)&&(a[i][j-1]=='.')){a[i][j-1]='@';b[i][j-1]=1;}
					if((j+1<n)&&(a[i][j+1]=='.')){a[i][j+1]='@';b[i][j+1]=1;}
				}
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				b[i][j]=0;
	}
	int s=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(a[i][j]=='@')s++;
	cout<<s<<endl;
	return 0;
}
char state[110][110] = {0};
int n;

void ill(int m)
{
	if(m == 1) return;
	else
	{
		char state2[110][110] = {0};
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				state2[i][j] = state[i][j];
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
			{
				if(state2[i][j] == '@')
				{
					if(state[i - 1][j] == '.') state[i - 1][j] = '@';
					if(state[i + 1][j] == '.') state[i + 1][j] = '@';
					if(state[i][j - 1] == '.') state[i][j - 1] = '@';
					if(state[i][j + 1] == '.') state[i][j + 1] = '@';
				}
			}
		ill(m - 1);
	}

}
int main() {
	cin >> n;
	for(int i = 1; i <= n ; i++)
		for(int j = 1; j <= n; j++)
			cin >> state[i][j];
	int m;
	cin >> m;
	ill(m);
	int sum = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(state[i][j] == '@')
				sum++;
	cout << sum << endl;

	return 0;
}
int main()
{
    int n,m,i,j,day,count=0,iday[100][100];
    char room[100][100];
    for(i=0;i<100;i++)
        for(j=0;j<100;j++)
        {
            iday[i][j]=200;
        }
    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        {
            scanf("%c",&room[i][j]);
            while((room[i][j]==' ')||(room[i][j]=='\n'))
            {
                scanf("%c",&room[i][j]);
            }
            if(room[i][j]=='@')
                iday[i][j]=1;
        }
    scanf("%d",&m);
    for(day=2;day<=m;day++)
    {
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            {
                if(  (room[i][j]=='@')  &&  (iday[i][j]<day)  )
                {
                    if(  (room[i][j+1]=='.') && (j+1<n)  )
                    {
                        room[i][j+1]='@';
                        iday[i][j+1]=day;
                    //printf("??room[%d][%d]\n",i,j+1);
                    }
                    
                    if(  (room[i][j-1]=='.') && (j-1>=0)  )
                    {
                        room[i][j-1]='@';
                        iday[i][j-1]=day;
                     //   printf("??room[%d][%d]\n",i,j-1);
                    }
                    
                    if(  (room[i+1][j]=='.') && (i+1<n)  )
                    {
                        room[i+1][j]='@';
                        iday[i+1][j]=day;
                     //   printf("??room[%d][%d]\n",i+1,j);
                    }
                    
                    if(  (room[i-1][j]=='.') && (i-1>=0)  )
                    {
                        room[i-1][j]='@';
                        iday[i-1][j]=day;
                     //   printf("??room[%d][%d]\n",i-1,j);
                    }
                    
                }
            }
 /*       for(i1=0;i1<n;i1++)
            for(j1=0;j1<n;j1++)
            {
                printf("%c",room[i1][j1]);
                if(j1==n-1)
                    printf("\n");
                else printf(" ");
            }
        printf("\n");         */
        
    }
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        {
            if(room[i][j]=='@')
                count++;
        }
    printf("%d\n",count);
    
}
int main(){
    int n,m,sum=0,a;
    int num[10006][2];
    char room[106][106];
    memset(room,'\0',sizeof(room));
    scanf("%d",&n);
    getchar();
    for (int i=0;i<n;i++){
         for(int j=0;j<n;j++){
         scanf("%c",&room[i][j]);
         }
         getchar();
    }
    scanf("%d",&m);
    for (int d=2;d<=m;d++){
         memset(num,0, sizeof (num));
         a=0;
         for (int x=0;x<n;x++){
                  for(int y=0;y<n;y++){
                  if (room[x][y]=='@'){
                             if((x-1)>=0){
                             if (room[x-1][y]=='.'){
                             num[a][0]=x-1;
                             num[a][1]=y;
                             a++;
                             }
                             }
                             if ((x+1)<=n-1){
                             if (room[x+1][y]=='.'){
                             num[a][0]=x+1;
                             num[a][1]=y;
                             a++;
                             }
                             }
                             if ((y-1)>=0){
                             if (room[x][y-1]=='.'){
                             num[a][0]=x;
                             num[a][1]=y-1;
                             a++;
                             }
                             }
                             if ((y+1)<=n-1){
                             if (room[x][y+1]=='.'){
                             num[a][0]=x;
                             num[a][1]=y+1;
                             a++;
                             }
                             }
                  }
                  } 
         }
         for (int h=0;h<a;h++){
         room[num[h][0]][num[h][1]]='@';
         }
    }
    for (int k=0;k<n;k++){
         for (int t=0;t<n;t++){
         if (room[k][t]=='@'){
         sum++;
         }
         }
    }
    printf("%d",sum);
return 0;
}
int main(){
	char sz[102][102]={0};
	int szs[102][102]={0};
	int n,m,i,j,s=0,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			scanf(" %c",&sz[i][j]);
			if(sz[i][j]=='@'){
				s++;
			}
		}
	}
	scanf("%d",&m);
	for(k=0;k<m-1;k++){
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(sz[i][j]=='@'){
					szs[i][j]=1;
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(szs[i][j]==1){
					if(sz[i-1][j]=='.'){
						sz[i-1][j]='@';
						s++;
					}
					if(sz[i+1][j]=='.'){
						sz[i+1][j]='@';
						s++;
					}
					if(sz[i][j+1]=='.'){
						sz[i][j+1]='@';
						s++;
					}
					if(sz[i][j-1]=='.'){
						sz[i][j-1]='@';
						s++;
					}
				}
			}
		}
	}
	printf("%d",s);
	return 0;
}
int main ()
{
	int n, i, j ,m, num = 0, day = 1, b[101][101] = {0};
	char a[101][101];
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j <n; j++)
		{
			cin >> a[i][j];
		}
	}
	cin >> m;
	while (day != m  )
	{
		for (i = 0; i <n ;i++)
		{
			for (j = 0; j <n; j++)
			{
				if (a[i][j] == '@' && b[i][j] == 0)
				{
					if ((j - 1) >= 0 && a[i][j - 1] == '.')
					{
						a[i][j - 1] = '@';
						b[i][j - 1] = 1;
					}
					if ((j + 1) < n && a[i][j + 1] == '.')
					{
						a[i][j + 1] = '@';
						b[i][j + 1] = 1;
					}
					if ((i - 1) >= 0 && a[i - 1][j] == '.')
					{
						a[i - 1][j] = '@';
						b[i - 1][j] = 1;
					}
					if ((i + 1) < n && a[i +1][j] == '.')
					{
						a[i+1][j] = '@';
						b[i+1][j] = 1;
					}
				}
			}
		}
		day++;
		for (i = 0; i <n ;i++)
		{
			for (j = 0; j <n; j++)
			{
				b[i][j] = 0;
			}
		}
	}
	for (i = 0; i <n ;i++)
	{
			for (j = 0; j <n; j++)
			{
				if (a[i][j] == '@')
					num++;
			}
	}
	cout <<num<<endl;
	return 0;
	
}
/*************************
??cpp5
????
???
2013/11/6
**************************/
int main()
{
	char a[101][101];
	int n, m, k, i,j,  cont=0;
	cin >> n;
	for (i=1; i<=n; i++)
	{
		for (j=1; j<=n; j++)
			cin >> a[i][j];
	}
	cin >> m;
	for (k=2; k <= m; k++)
	{
        for (i=1; i<=n; i++)
		{
		     for (j=1; j<=n; j++)
			 {
				 if (a[i][j] == '@')
				 {
					 if (j != 1 && a[i][j-1] =='.')
						 a[i][j-1] = '*';
                     if (j != n && a[i][j+1] =='.')
						 a[i][j+1] = '*';
                     if (i != 1 && a[i-1][j] =='.')
						 a[i-1][j] = '*';
                     if (i != n && 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]== '@')
					 cont ++;
			 }
	}
	cout << cont ;
	return 0;
}
int main(){
	int n,i,j,m,k;
	int p=0;
	scanf("%d",&n);
	char sz[n+2][n+2];
	char sz2[n+2];
	for(i=1;i<n+1;i++){
		scanf("%*c");
		for(j=1;j<=n;j++){
			scanf("%c",&(sz[i][j]));
			
		}
	}
	scanf("%d",&m); 
	for(j=1;j<=n;j++){
		sz[0][j]='#';
		sz[n+1][j]='#';
	}
	for(i=1;i<=n;i++){
		sz[i][0]='#';
		sz[i][n+1]='#';
	}
	for(k=0;k<m-1;k++){
		for(i=1;i<n+1;i++){
			for(j=1;j<n+1;j++){
				if(sz[i][j]=='a'){
					sz[i][j]='@';
				}
			}
		}
		for(i=1;i<n+1;i++){
			for(j=1;j<n+1;j++){
				if(sz[i][j]=='.'){
					if((sz[i-1][j]=='@')||(sz[i+1][j]=='@')||(sz[i][j-1]=='@')||(sz[i][j+1]=='@')){
					sz[i][j]='a';
					}
				}
			}
		
		}
	}
	for(i=1;i<n+1;i++){
		for(j=1;j<n+1;j++){
			if((sz[i][j]=='@')||(sz[i][j]=='a')){
				p=p+1;
			}
		}
	}
	printf("%d",p);
	return 0;
}
int p=0,q=1;
int main()
{
    char a[110][110];
    int i,j,n,m,c;
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a[i];
    }
    cin>>m;
    for(i=1;i<=n;i++)
    {
                     for(j=0;j<=n-1;j++)
                     {
                                      if(a[i][j]=='@')
                                      p++;
                     }
    }      
    int f(int m,int n,char a[][110]);
    c=f(m,n,a);
    cout<<c;
    return 0;
}
int f(int m,int n,char a[][110])
{
    int i,j;
    if(q==m) 
    return p;
    else
    {
    int b[110][110]={0};
    for(i=1;i<=n;i++)
    {
                     for(j=0;j<=n-1;j++)
                     {
                                        if((a[i][j]=='@')&&(b[i][j]==0))
                                        {
                                             if(a[i][j+1]=='.')
                                             {
                                                p++;
                                                a[i][j+1]='@';
                                                b[i][j+1]=1;
                                             }
                                             if(a[i][j-1]=='.')
                                             {
                                                           p++;
                                                           a[i][j-1]='@';
                                                           b[i][j-1]=1;
                                             }     
                                             if(a[i+1][j]=='.')
                                             {
                                                           p++;
                                                           a[i+1][j]='@';
                                                           b[i+1][j]=1;
                                             }
                                             if(a[i-1][j]=='.')
                                             {
                                                           p++;
                                                           a[i-1][j]='@';
                                                           b[i-1][j]=1;
                                             }
                                        }
                     }
    }
                                             q++;
                                             return f(m,n,a);
    } 
}
int main()
{
	char a[102][102];
	int b[102][102], i, j, n, m, k, count = 0;
	memset(a, '\0', sizeof(a));
	memset(b, 0, sizeof(b));
	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] = 1;
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
				if (a[i][j] == '@' && b[i][j] == 1)
				{
					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] == '@')
				count++;
	cout << count;
	return 0;
}
//*************************
//*  ??????? 
//*  ????? 
//*  ???1200012941 
//*  ???2012?9?24? 
//*************************
int main()
{
    char exp[100][100];
    int i, j, k, n, m, a[100][100] = {0};
    cin >> n;
    for (i = 0; i < n; i++)
     for (j = 0; j < n; j++)
     {
         cin >> exp[i][j];
         if (exp[i][j] == '#')
             a[i][j] = -1;
         if (exp[i][j] == '@')
             a[i][j] = 1;
     }
    cin >> 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+1 < n && a[i+1][j] == 0)
                     a[i+1][j] = k + 1;
                 if (j+1 < n && a[i][j+1] == 0)
                     a[i][j+1] = k + 1;
                 if (i-1 >= 0 && a[i-1][j] == 0)
                     a[i-1][j] = k + 1;
                 if (j-1 >= 0 && a[i][j-1] == 0)
                     a[i][j-1] = k + 1;
             }
         }
    }
    int sum = 0;
    for (i = 0; i < n; i++)
     for (j = 0; j < n; j++)
     {
         if (a[i][j] > 0)
             sum++;
     }
    cout << sum << endl;
    return 0;
}
int main()
{
	int n,m,t,p[10000][2];
	cin>>n;
	cin.get();
	char num[100][100];
	for(int i=0;i<n;i++)
	{
		cin.getline(num[i],100);
	}
	cin>>m;
	int k=0;
	while(k<m-1)
	{
		t=0;
		for(int x=0;x<n;x++)
		{
			for(int y=0;y<n;y++)
			{
				if(num[x][y]=='@')
				{
					p[t][0]=x;
					p[t++][1]=y;
				}
			}
		}
        for(int x=0;x<t;x++)
		{
			int i=p[x][0];
			int j=p[x][1];
					if(num[i-1][j]=='.'&&(i-1)>=0)
						num[i-1][j]='@';
					if(num[i+1][j]=='.'&&(i+1)<n)
						num[i+1][j]='@';
					if(num[i][j-1]=='.'&&(j-1)>=0)
						num[i][j-1]='@';
					if(num[i][j+1]=='.'&&(j+1)<n)
						num[i][j+1]='@';

		}
		k++;
	}
     int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(num[i][j]=='@')
				cnt++;
		}
	}
	cout<<cnt;
	return 0;
}
//*********************
//*???????
//*??????
//*???2013.11.1
//*********************
int main()
{
	char a[1000][101][101]={0};                                     //????????????????????????? ???????
	int n, m, number = 0;
	cin >> n;                                                       //????
	for(int i = 1; i <= n; i++)                                     //?????????
		for(int k = 1; k <= n; k++)
			cin >> a[1][i][k];
	cin >> m;                                                       //????
	for(int h = 1; h<= m; h++)
		for(int i = 1; i <= n; i++)
			for(int k = 1; k <= n; k++)
			{
				if(a[h][i][k] == '@' && a[h][i+1][k] =='.')         //??????????????????????
				{a[h+1][i+1][k] = '@';a[h+1][i][k] = '@';}
				if(a[h][i][k] == '@' && a[h][i-1][k] =='.')
				{a[h+1][i-1][k] = '@';a[h+1][i][k] = '@';}
				if(a[h][i][k] == '@' && a[h][i][k+1] =='.')
				{a[h+1][i][k+1] = '@';a[h+1][i][k] = '@';}
				if(a[h][i][k] == '@' && a[h][i][k-1] =='.')
				{a[h+1][i][k-1] = '@';a[h+1][i][k] = '@';}
				if(a[h][i][k] == '#')
					a[h+1][i][k] = '#';
				if(a[h][i][k] == '.' && a[h][i+1][k]!='@' && a[h][i-1][k]!='@' && a[h][i][k+1]!='@' && a[h][i][k-1]!='@')
					a[h+1][i][k] = '.';
			}
	for(int i = 1; i <= n; i++)
		for(int k = 1; k <= n; k++)
			{
				if(a[m][i][k] == '#'||a[m][i][k]=='.')         
					number ++;
		}
	cout <<n*n-number;                                                 //??????#?.??#????
	return 0;
}
int main()
{
	int n, m, b[101][101] = {0}, i, j, k;
	char a[101][101];
	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 - 1; k++)
	{
		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] = k;
					if (a[i + 1][j] == '.')
						b[i + 1][j] = k;
					if (a[i][j - 1] == '.')
						b[i][j - 1] = k;
					if (a[i][j + 1] == '.')
						b[i][j + 1] = k;
				}
			}
		}
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
				if (b[i][j] == k)
					a[i][j] = '@';
	}
	k = 0;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			if (a[i][j] == '@')
				k++;
	cout << k << endl;
	return 0;
}
int main(){
    int q,p,n,m,i,s;
    char a[200][200];
    scanf("%d",&n);
    for(q=0;q<n;q++){
        for(p=1;p<n+2;p++){
            scanf("%c",&a[q][p]);
        }
    }
    scanf("%d",&m);
    for(i=1;i<m;i++){
        for(q=0;q<n;q++){
            for(p=1;p<n+2;p++){
                if(a[q][p]=='@'){
                    if(a[q-1][p]=='.'){
                        a[q-1][p]='*';
                    }
                    if(a[q+1][p]=='.'){
                        a[q+1][p]='*';
                    }
                    if(a[q][p-1]=='.'){
                        a[q][p-1]='*';
                    }
                    if(a[q][p+1]=='.'){
                        a[q][p+1]='*';
                    }
                }
            }
        }
        for(q=0;q<n;q++){
            for(p=1;p<n+2;p++){
               if(a[q][p]=='*'){
                   a[q][p]='@';
               }
            }
        }
    }
    s=0;
    for(q=0;q<n;q++){
        for(p=1;p<n+2;p++){
            if(a[q][p]=='@'){
               s=s+1;
            }
        }
    }
    printf("%d",s);
    return 0;
}
/*
 * kaoshi4.cpp
 *
 *  Created on: 2011-12-31
 *      Author: 2011
 */

int main()
{
	int n,i,j,m,s=0,a[101][101];
	char pan[101][101];
	cin>>n;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>pan[i][j];
	cin>>m;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{
			if(pan[i][j]=='@')
				a[i][j]=1;
			else	a[i][j]=0;
		}
	while(m>1)
	{
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(pan[i][j]=='@'&&a[i][j]==1)
				{
					if((i-1)>=0&&pan[i-1][j]=='.')
						pan[i-1][j]='@';
					if((i+1)<n&&pan[i+1][j]=='.')
						pan[i+1][j]='@';
					if((j-1)>=0&&pan[i][j-1]=='.')
						pan[i][j-1]='@';
					if((j+1)<n&&pan[i][j+1]=='.')
						pan[i][j+1]='@';
				}
		for(i=0;i<n;i++)
				for(j=0;j<n;j++)
				{
					if(pan[i][j]=='@')
						a[i][j]=1;

				}
		m--;
	}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(pan[i][j]=='@')
				s++;
	cout<<s;
	return 0;


}
int main ()
{
char a[100][100];
	int i=0,j=0,k=0,b[102][102]={0},n,m;
	cin>>n;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	cin>>m;
for(k=1;k<m;k++)
{
	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)
			{
				if(i==0)
				{
					if(j==0)
					{
						if(a[0][1]=='.')
							a[0][1]='@';
						if(a[1][0]=='.')
							a[1][0]='@';
					}
					else if(j==n-1)
					{
						if(a[0][j-1]=='.')
							a[0][j-1]='@';
						if(a[1][j]=='.')
							a[1][j]='@';
					}
					else 
					{
                         if(a[0][j-1]=='.')
							 a[0][j-1]='@';
						 if(a[0][j+1]=='.')
							 a[0][j+1]='@';
						 if(a[1][j]=='.')
							 a[1][j]='@';
					}
				}
				else if(i==n-1)
				{
					if(j==0)
					{
						if(a[i][1]=='.')
							a[i][1]='@';
						if(a[i-1][0]=='.')
							a[i-1][0]='@';
					}
					else if(j==n-1)
					{
						if(a[i][j-1]=='.')
							a[i][j-1]='@';
						if(a[j][i-1]=='.')
							a[j][i-1]='@';
					}
					else 
					{
                         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]='@';
					}
				
				}
				else if(j==0&&i!=0&&i!=n-1)
				{
				         if(a[i-1][0]=='.')
							 a[i-1][0]='@';
						 if(a[i+1][0]=='.')
							 a[i+1][0]='@';
						 if(a[i][1]=='.')
							 a[i][1]='@';
				}
				else if(j==n-1&&i!=0&&i!=n-1)
				{
				         if(a[i-1][n-1]=='.')
							 a[i-1][n-1]='@';
						 if(a[i+1][n-1]=='.')
							 a[i+1][n-1]='@';
						 if(a[i][j-1]=='.')
							 a[i][j-1]='@';
				}
				else 
				{
					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]='@';
					if(a[i+1][j]=='.')
						a[i+1][j]='@';
				}
			}
		}
}
k=0;
for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{
			if(a[i][j]=='@')
				b[i][j]=1;
			k=k+b[i][j];
		}
cout<<k;
	
	return 0;//?????
}
int main()
{
	int n, i, j, sum=0, m, k;
	char a[102][102];
	cin >> n;
	for(i=0;i<=n+1;i++)
	{
		for(j=0;j<=n+1;j++)
		{
			a[0][j]='#';
			a[n+1][j]='#';
			a[i][0]='#';
			a[i][n+1]='#'; 
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{  
			cin >> a[i][j];
		}
	}
	cin >> m;
	m=m-1;
	for(k=0;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]=='@')||(a[i][j+1]=='@')||(a[i][j-1]=='@'))
						a[i][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]=='@')
				sum=sum+1;
		}
	}
	cout << sum;
	return 0;
}
void f(int, int);
int i, j;
char a[102][102][2] = {0};
int main()
{
    int i, j;
    int n, m;
    int l = 0;
    int sum = 0;
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            cin >> a[i][j][0];
            a[i][j][1] = a[i][j][0];    
        }     
    }
    cin >> m;
    for(i = 1; i < m; i++)
    {
        f(n, l);
        l = 1 - l;    
    }
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(a[i][j][l] == '@')
                sum++;    
        }    
    }
    cout << sum << endl;
    return 0;
}
void f(int n, int l)
{
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(a[i][j][l] == '@')
            {
                if(a[i - 1][j][l] != '#')  a[i - 1][j][1 - l] = '@';  
                if(a[i + 1][j][l] != '#')  a[i + 1][j][1 - l] = '@';
                if(a[i][j - 1][l] != '#')  a[i][j - 1][1 - l] = '@';
                if(a[i][j + 1][l] != '#')  a[i][j + 1][1 - l] = '@';  
            }    
        }    
    }    
}