semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main(){
	char sz[105][105]={'#'},a[105][105]={'#'};
int n,i,j,m,k=0,t;
scanf("%d",&n);
for(i=1;i<=n;i++){
	
	scanf("%s",sz[i]);
}
for(t=1;t<=n;t++){
		strcpy(a[t],sz[t]);
	
	}

scanf("%d",&m);
for(m;m>1;m--){
	for(i=1;i<=n;i++){
		for(j=0;j<n;j++){
			if(j!=0){
				if(sz[i][j]=='@'){
					if(sz[i+1][j]!='#'){
						a[i+1][j]='@';
					}
					if(sz[i-1][j]!='#'){
						a[i-1][j]='@';
					}
					if((sz[i][j+1]!='#')&&(sz[i][j+1]!='\0')){
						a[i][j+1]='@';
					}
					if(sz[i][j-1]!='#'){
						a[i][j-1]='@';
					}
				}
			}else{
                	if(sz[i][j]=='@'){
				if(sz[i+1][j]!='#'){
						a[i+1][j]='@';
					}
					if(sz[i-1][j]!='#'){
						a[i-1][j]='@';
					}
					if(sz[i][j+1]!='#'){
						a[i][j+1]='@';
					}
		}
			}
		}
	}
	for(t=1;t<=n;t++){
		strcpy(sz[t],a[t]);
	
	}
}
for(i=1;i<=n;i++){
	for(j=0;j<n;j++){
		if(sz[i][j]=='@'){
			k++;
		}
	}
}
printf("%d",k);





		return 0;
	}
int main(){
    int n,m,row,col,x;
    char a[102][102],c[102][102];
    scanf("%d",&n);
    x=0;
    for(row=1;row<=n;row++){
        scanf("\n");
        for(col=1;col<=n;col++){
            scanf("%c",&(a[row][col]));
        }
    }
    scanf("\n");
    scanf("%d",&m);
    for(int b=0;b<=n+1;b++){
        a[b][0]=a[b][n+1]=a[0][b]=a[n+1][b]='#';
        c[b][0]=c[b][n+1]=c[0][b]=c[n+1][b]='#';
    }
    for(int i=0;i<m-1;i++){
        for(row=1;row<=n;row++){
            for(col=1;col<=n;col++){
                c[row][col]=a[row][col];
            }
        }
        for(row=1;row<=n;row++){
            for(col=1;col<=n;col++){
                if(a[row][col]=='@'){
                    if(a[row][col+1]!='#'){
                        c[row][col+1]='@';
                    }
                    if(a[row][col-1]!='#'){
                        c[row][col-1]='@';
                    }
                    if(a[row+1][col]!='#'){
                        c[row+1][col]='@';
                    }
                    if(a[row-1][col]!='#'){
                        c[row-1][col]='@';
                    }
                }
            }
        }
        for(row=1;row<=n;row++){
            for(col=1;col<=n;col++){
                a[row][col]=c[row][col];
            }
        }
    }
    for(row=1;row<=n;row++){
        for(col=1;col<=n;col++){
            if(a[row][col]=='@'){
                x++;
            }
        }
    }
    printf("%d",x);
    return 0;
}
int main()
{
	int n,i,j,t,m,s=0;
	int d[102][102]={0};
	char p[102][102];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{	cin>>p[i][j];
		    if(p[i][j]=='@') d[i][j]=1;
		}
	}
	cin.get();
	cin>>m;
    for(t=1;t<=m-1;t++)
	{
    	for(i=1;i<=n;i++)
		{
		    for(j=1;j<=n;j++)
			{
	 		     if(d[i][j]==1)
				 {
					 if(p[i+1][j]!='#') {p[i+1][j]='@';}
					 if(p[i-1][j]!='#') {p[i-1][j]='@';}
					 if(p[i][j+1]!='#') {p[i][j+1]='@';}
					 if(p[i][j-1]!='#') {p[i][j-1]='@';}
				 }
			}
		}
		for(i=1;i<=n;i++)
		{
	     	for(j=1;j<=n;j++) 
                if(p[i][j]=='@') d[i][j]=1;
		}
	}
	for(i=1;i<=n;i++)
	{	
		for(j=1;j<=n;j++)
			s+=d[i][j];
	}
	cout<<s<<'\n';
	return 0;
}
int main()
{
	int n,i,j;
	int a[103][103]={0};
	int b[103][103]={0};
	char t;
	cin>>n;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{ 
			cin>>t;
			if(t=='#') a[i][j]=0;
			if(t=='.') a[i][j]=100;
			if(t=='@') a[i][j]=1;
		}
	int m,k;
	cin>>m;
	for(k=2;k<=m;k++)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
			{
				if(a[i][j]<=1) b[i][j]=a[i][j];
				if(a[i][j]==100) 
				{
					if(a[i-1][j]==1||a[i+1][j]==1||a[i][j-1]==1||a[i][j+1]==1) b[i][j]=1;
					else b[i][j]=100;
				}
			}
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++) a[i][j]=b[i][j];

	}
	int sum=0;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++) if(a[i][j]==1) sum++;
	cout<<sum;
	return 0;
}
int main()
{
	int n = 0, m = 0, sum = 0;
	int room[102][102];
	char ch;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%c", &ch);
		for (int j = 1; j <= n; j++)
		{
			scanf("%c", &ch);
			if (ch == '#')
				room[i][j] = -1;
			else if (ch == '.')
				room[i][j] = 0;
			else if (ch == '@')
				room[i][j] = 1;
		}
	}

	for (int i = 0; i <= n + 1; i++)
		room[i][0] = room[0][i] = room[i][n+1] = room[n+1][i] = -1;

	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 (room[i][j] == k)
				{
					if (room[i+1][j] == 0) 
						room[i+1][j] = k+1;
					if (room[i-1][j] == 0) 
						room[i-1][j] = k+1;
					if (room[i][j+1] == 0) 
						room[i][j+1] = k+1;
					if (room[i][j-1] == 0) 
						room[i][j-1] = k+1;
				}
			}
	}
	sum = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (room[i][j] > 0)
				sum ++;
		}
	}
	printf("%d\n", sum);

	return 0;
}
//*********************************************
//*???????                             *
//*??????                               *
//*???1300012888                           *
//*???2013.11.12                           *
//*********************************************

int main()
{
	char area[101][101];
	int n, i, j, m, k;

	cin >> n;
	for (i = 0; i <= 100; i++)
	{
		for (j = 0; j <= 100; j++)
			area[i][j] = '#';
	}
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
			cin >> area[i][j];
	}
	cin >> m;
	for (k = 1; k <= m - 1; k++)
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (area[i][j] == '@')
				{
					if (area[i - 1][j] == '.')
						area[i - 1][j] = '%';
					if (area[i + 1][j] == '.')
						area[i + 1][j] = '%';
					if (area[i][j - 1] == '.')
						area[i][j - 1] = '%';
					if (area[i][j + 1] == '.')
						area[i][j + 1] = '%';
				}
			}
		}
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (area[i][j] == '%')
					area[i][j] = '@';
			}
		}

	}
	k = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			if (area[i][j] == '@')
				k++;
		}
	}
	cout << k << endl;

	return 0;
}
void f(int step);
int n,m;
char a[102][102]={{'\0'}};
int b[102][102]={0};
int main()
{

cin >>n;
for(int i= 1;i<=n;i++)
	for(int j= 1;j<=n;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='@')b[i][j]=1;
			if(a[i][j]=='.')b[i][j]=-1;
		}
cin>>m;
		
for(int i= 0;i<m-1;i++)
	f(i);
	int temp=0;
for(int i= 1;i<=n;i++)
	for(int j= 1;j<=n;j++)
		if(b[i][j] > 0)
			temp++;
cout<<temp;
cin.get();cin.get();
return 0;
}
void f(int step)
{
	for(int i= 1;i<=n;i++)
		for(int j= 1;j<=n;j++)
		if(b[i][j] <= step+1 && b[i][j]>0)
		{
			if(b[i-1][j] == -1)b[i-1][j] = b[i][j]+1;
			if(b[i+1][j] == -1)b[i+1][j] = b[i][j]+1;
			if(b[i][j-1] == -1)b[i][j-1] = b[i][j]+1;
			if(b[i][j+1] == -1)b[i][j+1] = b[i][j]+1;
		}
		//for(int i= 1;i<=n;i++){for(int j= 1;j<=n;j++)cout<<b[i][j]<<"   ";cout<<endl;}cout<<endl;
}
char a[102][102];
int flag[102][102];

int main()
{
	int n,i,j,k,m,num=0;
	cin >> n;
	for (i=0;i<=101;i++)
		for (j=0;j<=101;j++)
		{
			a[i][j] = '0';
			flag[i][j] = 1;
		}
	
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
		{
			cin >> a[i][j];		
		}
	cin >> m;
	
	for (i = 0; i < m - 1; i++)
	{
		for (j = 1; j <= n; j++)
		{
			for (k = 1; k <= n; k++)
			{
				if (a[j][k]=='@' && flag[j][k])
				{
					if (a[j+1][k] == '.') 
					{
						a[j+1][k] = '@'; 
						flag[j+1][k] = 0;
					}
					if (a[j-1][k] == '.') 
					{
						a[j-1][k] = '@'; 
						flag[j-1][k] = 0;
					}
					if (a[j][k+1] == '.') 
					{
						a[j][k+1] = '@'; 
						flag[j][k+1] = 0;
					}
					if (a[j][k-1] == '.') 
					{
						a[j][k-1] = '@'; 
						flag[j][k-1] = 0;
					}
				}
			
			}
		}
		for (j = 1; j <= n; j++)
		{
			for (k = 1; k <= n; k++)
			{
				flag[j][k] = 1;
			}
		}
	}

	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			if (a[i][j] == '@') num++;
		}
	cout << num << endl;
	return 0;
}
int main()
{
	char ch[103][103]={'\0'};				//#???????.?????@??????????
	int a[103][103]={0};					//0???????1?????2??????????3????????
	int n,i,j,k,day,num=0;
	cin>>n;
	cin.get();
	for (i=0;i<n+2;i++)
		for (j=0;j<n+2;j++)
			ch[i][j]='#';					//????????1?n???
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
			cin>>ch[i][j];
		cin.get();
	}
	cin>>day;
	for (i=0;i<n+2;i++)
		for (j=0;j<n+2;j++)
		{
			if (ch[i][j]=='#')
				a[i][j]=0;
			else if (ch[i][j]=='.')
				a[i][j]=1;
			else if (ch[i][j]=='@')
				a[i][j]=2;
		}									//?????????????
		for (k=1;k<day;k++)					//day????day-1?
		{
			for (i=1;i<=n;i++)
				for (j=1;j<=n;j++)
					if (a[i][j]==2)
						a[i][j]++;			//????????????????????
			for (i=1;i<=n;i++)
				for (j=1;j<=n;j++)
				{
					if ((a[i][j]==3)&&(a[i][j-1]==1))	//????
						a[i][j-1]=2;
					if ((a[i][j]==3)&&(a[i][j+1]==1))	//????
						a[i][j+1]=2;
					if ((a[i][j]==3)&&(a[i-1][j]==1))	//????
						a[i-1][j]=2;
					if ((a[i][j]==3)&&(a[i+1][j]==1))	//????
						a[i+1][j]=2;
				}
		}
		for (i=1;i<=n;i++)
			for (j=1;j<=n;j++)
			{
				if ((a[i][j]!=0)&&(a[i][j]!=1))
					num++;
			}
		cout<<num<<endl;
		return 0;
}
int main()
{
	char ch[101][101];
	int n;
	int num=0;
	int day[101][101];
	
	cin>>n;
	int i=0,j=0,k=0;
	for(i=0;i<n+2;i++)
		for(j=0;j<n+2;j++)
			day[i][j]=0;
	for(i=0;i<n+2;i++)\
	{
		ch[0][i]='#';
		ch[n+1][i]='#';
	}
	for(i=1;i<n+1;i++)
	{
		ch[i][0]='#';
		ch[i][n+1]='#';
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cin>>ch[i][j];
	for(i=0;i<=n+1;i++)
			for(j=0;j<=n+1;j++)
			{
				if(ch[i][j]=='@')
				{
					num++;
					day[i][j]=0;
				}
			}
	int m=0;
	cin>>m;
	for(k=1;k<m;k++)
	{
		for(i=1;i<n+1;i++)
			for(j=1;j<n+1;j++)
			{
				if(ch[i][j]=='@'&&day[i][j]<k)
				{
					if(ch[i+1][j]=='.')
					{
						ch[i+1][j]='@';
						day[i+1][j]=k;
						num++;
					}
					if(ch[i-1][j]=='.')
					{
						ch[i-1][j]='@';
						day[i-1][j]=k;
						num++;
					}
					if(ch[i][j+1]=='.')
					{
						ch[i][j+1]='@';num++;day[i][j+1]=k;
					}
					if(ch[i][j-1]=='.')
					{
						ch[i][j-1]='@';num++;day[i][j-1]=k; 
					}
				}
			}
	}
	cout<<num<<endl;
}
int main(){
char a[110][110],b[110][110];
int n,m,i,j,k;
scanf("%d\n",&n);
for(i=1;i<=n;i++){
	scanf("%s",a[i]+1);
}
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]=='.')&&(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];
		}
	}
}
int count=0;
for(i=1;i<=n;i++){
	for(j=1;j<=n;j++){
        if(a[i][j]=='@')
			count++;
	}
}
printf("%d",count);
return 0;
}
int main(){
    int n,m,i,k,t,s;
    scanf("%d",&n);
    char a[n][n];
    for(i=0;i<n;i++){
        for(k=0;k<n;k++){
            scanf(" %c",&(a[i][k]));
        }
    }
    scanf("%d",&m);
    if(n>1){
    for(i=1;i<m;i++){
        
         for(k=0;k<n-1;k++){
            for(t=0;t<n;t++){
                if((a[k][t]=='@')&&(a[k+1][t]=='.')){
                    a[k+1][t]='*';
                }
            }
         }
         for(k=1;k<n;k++){
             for(t=0;t<n;t++){
                 if((a[k][t]=='@')&&(a[k-1][t]=='.')){
                     a[k-1][t]='*';
                 }
             }
         }
         for(k=0;k<n-1;k++){
             for(t=0;t<n;t++){
                 if((a[t][k]=='@')&&(a[t][k+1]=='.')){
                     a[t][k+1]='*';
                 }
             }
         }
         for(k=1;k<n;k++){
             for(t=0;t<n;t++){
                 if((a[t][k]=='@')&&(a[t][k-1]=='.')){
                     a[t][k-1]='*';
                 }
             }
         }
         for(k=0;k<n;k++){
             for(t=0;t<n;t++){
                 if(a[k][t]=='*'){
                     a[k][t]='@';
                 }
             }
         }
    }
    }
    s=0;
    for(i=0;i<n;i++){
        for(k=0;k<n;k++){
            if(a[i][k]=='@'){
                s=s+1;
            }
        }
    }
    printf("%d",s);
    return 0;
}
int main ()
{
	int n,m,i,j,k; 
	int num=0; 
	char a[110][110][110]={0};
	cin>>n;
	for(i=1;i<=n;i++){
	for(j=1;j<=n;j++){
	cin>>a[i][j][0];
	if(a[i][j][0]=='#')
	   a[i][j][0]=0;
	if(a[i][j][0]=='.')
	   a[i][j][0]=1;
	if(a[i][j][0]=='@')
	   a[i][j][0]=2;
    }}
	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][i-1]==0||a[j][k][i-1]==2)
		a[j][k][i]=a[j][k][i-1]; 
	else
	{
	if(a[j+1][k][i-1]==2 || a[j-1][k][i-1]==2 || a[j][k+1][i-1]==2 || a[j][k-1][i-1]==2) 
			a[j][k][i]=2;
	else
			a[j][k][i]=1;
	}}}}

	for(i=1;i<=n;i++){
	for(j=1;j<=n;j++){
	if (a[i][j][m-1]==2)
		num++; 
	}}
	cout<<num; 
	return 0;
}
int main()
{
    int n,m,a[100][100]={0},b[100][100]={0},c[100][100]={0},count=0,i,j,k,l,p;
    char d;
    cin>>n;
    for (i=0;i<n;i++)
       for(j=0;j<n;j++)
       {
                       cin>>d;
                       if (d=='#') b[i][j]=1;
                       if (d=='@') a[i][j]=1;
       }
    cin>>m;
    for (i=0;i<m-1;i++)
    {
        for(j=0;j<n;j++)
        {
                        for(k=0;k<n;k++)
                        {
                                        if (a[j][k]==1&&j-1>=0&&b[j-1][k]==0) c[j-1][k]=1;
                                        if (a[j][k]==1&&k-1>=0&&b[j][k-1]==0) c[j][k-1]=1;
                                        if (a[j][k]==1&&j+1<n&&b[j+1][k]==0) c[j+1][k]=1;
                                        if (a[j][k]==1&&k+1<n&&b[j][k+1]==0) c[j][k+1]=1;
                        }
                        
        }
        for(l=0;l<n;l++)
           for(p=0;p<n;p++)
              if(c[l][p]==1)
              {
                            c[l][p]=0;
                            a[l][p]=1;
              }    
    }
    for (i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
                 if(a[i][j]==1) count++;
        }
    }
    cout<<count;       
    return 0;
}
/*
 * h.cpp
 *
 *  Created on: 2013-11-1
 *      Author: Administrator
 */

char a[105][105],b[105][105];
int main()
{
	int n=0,i,j,k,p,q,sum=0;
	cin>>n;

	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cin>>a[i][j];
	int m;
	cin>>m;
	for(k=2;k<=m;k++)
	{
		for(i=1;i<=n;i++)
					for(j=1;j<=n;j++)
						b[i][j]=a[i][j];
		for(i=1;i<=n;i++)
				for(j=1;j<=n;j++)
				{
					if(a[i][j]=='@')
					{
						b[i][j]='@';
						for(p=-1;p<=1;p++)
							for(q=-1;q<=1;q++)
							{
								if(p==q||p==(-q))
									continue;

								if(a[i+p][j+q]=='#')
									b[i+p][j+q]='#';
								else
									b[i+p][j+q]='@';

							}
					}
				}
		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;
}
//*******************
//**??????? **
//**?????	   **
//**???2013.11.3**
//**????5.cpp  **
//*******************
int main()
{
	// ??cnt??????????day???????????
	int n, i, j, m, d, cnt = 0, day[102][102] = {0};
	char a[102][102]; // ?????
	cin >> n; // ??n?????????
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
		{
			cin >> a[i][j]; // ??????????
			if (a[i][j] == '@')
				day[i][j] = 1; // ?day[i][j]???1
		}
		cin >> m; // ??m???????
		for (d = 2; d <= m; d++)
		{
			for (i = 1; i <= n; i++)
				for (j = 1; j <= n; j++)
				{
					// ???????????????????????
					if (a[i][j] == '@' && day[i][j] == d - 1)
					{
						day[i][j] = d;

						// ????????????????
						if (a[i][j - 1] == '.')
						{
							a[i][j - 1] = '@';
							day[i][j - 1] = d;
						}
						if (a[i - 1][j] == '.')
						{
							a[i - 1][j] = '@';
							day[i - 1][j] = d;
						}
						if (a[i][j + 1] == '.')
						{
							a[i][j + 1] = '@';
							day[i][j + 1] = d;
						}
						if (a[i + 1][j] == '.')
						{
							a[i + 1][j] = '@';
							day[i + 1][j] = d;
						}
					}
				}
		}
		for (i = 1; i <= n; i++)
			for (j = 1; j <= n; j++)
			{
				if (a[i][j] == '@')
					cnt++; // ???????????
			}
		cout << cnt << endl; // ??cnt
	return 0;
}
int main()
{
	int n,i,j,k,m,x;
	char a[100][100][100];
	cin>>n;
	x=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[1][i][j];
	cin>>m;
	for(k=2;k<=m;k++)
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				a[k][i][j]=a[k-1][i][j];
	for(k=2;k<=m;k++)
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			{
				if(a[k-1][i][j]=='@')a[k][i][j]='@';
				if(a[k-1][i][j]=='@'&&i!=0&&i!=n-1&&j!=0&&j!=n-1)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==0&&j!=0&&j!=n-1)
				{
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==n-1&&j!=0&&j!=n-1)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i!=0&&i!=n-1&&j==0)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i!=0&&i!=n-1&&j==n-1)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==0&&j==0)
				{
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==0&&j==n-1)
				{
					if(a[k-1][i+1][j]=='.')
						a[k][i+1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==n-1&&j==0)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i][j+1]=='.')
						a[k][i][j+1]='@';
				}
				if(a[k-1][i][j]=='@'&&i==n-1&&j==n-1)
				{
					if(a[k-1][i-1][j]=='.')
						a[k][i-1][j]='@';
					if(a[k-1][i][j-1]=='.')
						a[k][i][j-1]='@';
				}
			}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(a[m][i][j]=='@')
				x+=1;
	cout<<x<<endl;
	return 0;
}
int main()
{
	int n,i,j,m,l,t;
	char a[100][100],b[100][100];
	cin>>n;
	for(i=1;i<n+1;i++)
	{
		for(j=1;j<n+1;j++)
		{
			cin>>a[i][j];
			b[i][j]=a[i][j];
		}
	}
	cin>>m;
	for(l=0;l<m-1;l++)
	{
		for(i=1;i<n+1;i++)
		{
			for(j=1;j<n+1;j++)
			{
				b[i][j]=a[i][j];
			}
		}
		for(i=1;i<n+1;i++)
		{
			for(j=1;j<n+1;j++)
			{
				if(b[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]='@';
					}
				}
			}
		}
	}
	t=0;
	for(i=1;i<n+1;i++)
	{
		for(j=1;j<n+1;j++)
		{
			if(a[i][j]=='@')
			{
				t++;
			}
		}
	}
	cout<<t<<endl;
	return 0;
}
int main()
{
	char mat[100][100];
	int n,d;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++)            //???????
	{
		for(int j=1;j<=n;j++)
		{
			mat[i][j]=getchar();
		}
		getchar();
	}
	cin>>d;
	for(int x=1;x<d;x++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(mat[i][j]=='@')
				{
					if(mat[i-1][j]=='.')
						mat[i-1][j]='a';     //'a'???????
					if(mat[i+1][j]=='.')
						mat[i+1][j]='a';
					if(mat[i][j-1]=='.')
						mat[i][j-1]='a';
					if(mat[i][j+1]=='.')
						mat[i][j+1]='a';
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(mat[i][j]=='a')
					mat[i][j]='@';
			}
		}
	}
	int s=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(mat[i][j]=='@')
				s++;
		}
	}
	cout<<s<<endl;
	return 0;
}
//********************************
//*???????      **
//*?????? 1300012757 **
//*???2013.11.1 **
//********************************
void chuanran(int ,int );
int cz(int );
char a[101][101];
int n;
int main()
{
	extern char a[101][101];
	extern int n;
	int m;
	cin >> n;
	for (int i =0 ; i < n; i ++)
		for (int j = 0 ;j < n; j ++)
			cin >> a[i][j];
	cin >> m;
	for (int p = 1;p <m  ;p ++)
	{
		for (int i = 0; i < n ; i ++)
			for (int j =0 ; j< n ;j ++)
				if (a[i][j] == '@')
					chuanran(i,j);
		for (int i = 0; i < n; i ++)
			for (int j =0 ;j < n; j++)
				if(a[i][j] == '!')
					a[i][j] = '@';
	}
	int sum = 0;
	for (int i = 0; i < n ; i ++)
			for (int j =0 ; j< n ;j ++)
			if (a[i][j] == '@')
				sum ++;
	cout <<sum;
	
	return 0;
}
void chuanran(int x, int y)
{
	extern char a[101][101];
	int p,q,s,t;
	p = cz(x - 1);
	q = cz(x + 1);
	s = cz(y - 1);
	t = cz(y + 1);
	if (a[p][y] == '.')
		a[p][y] = '!';
	if (a[q][y] == '.')
		a[q][y] = '!';
	if (a[x][s] == '.')
		a[x][s] = '!';
	if (a[x][t] == '.')
		a[x][t] = '!';
}
int cz(int x)
{
	extern int n;
	if (x < 0)
		return 0;
	else if (x > n-1)
		return n-1;
	else return x;
}
int n;
char w[150][150];
char q[150][150];
int k;
void c(int i,int j){if(w[i][j]=='.')w[i][j]='@';}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>w[i];
for(int j=n;j>0;j--)w[i][j]=w[i][j-1];
}
cin>>k;
while(k>1){
k--;
memcpy(q,w,sizeof(w));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(q[i][j]=='@'){
c(i,j-1);c(i,j+1);c(i-1,j);c(i+1,j);
}
}
int s=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(w[i][j]=='@')s++;
cout<<s<<endl;
return 0;
}
int main()
{
    int n, i, j, k, m, num = 0;
    char a[102][102] = {0};
    cin >> n;
    for(i = 1;i <= n;i++)
    {
        for(j = 1;j <= n;j++)
        {
            cin >> a[i][j];
        }
    }
    cin >> m;
    for(i = 1;i < m;i++)
    {
        for(j = 1;j <= n;j++)
        {
            for(k = 1;k <= n;k++)
            {
                if(a[j][k] == '@')
                {
                    if(a[j - 1][k] == '.')
                    {
                        a[j - 1][k] = 'a';
                    }
                    if(a[j + 1][k] == '.')
                    {
                        a[j + 1][k] = 'a';
                    }
                    if(a[j][k + 1] == '.')
                    {
                        a[j][k + 1] = 'a';
                    }
                    if(a[j][k - 1] == '.')
                    {
                        a[j][k - 1] = '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] == '@')
            {
                num++;
            }
        }
    }
    cout << num;
    return 0;
}
char a[110][110];
int main()
{
	int n,m,sum=0;
	int disx[4]={1,0,-1,0};
	int disy[4]={0,-1,0,1};
	cin>>n;
	 for( int i=1;i<=n;i++)
		 for (int j=1;j<=n;j++)
			 cin>>a[i][j];
	 cin>>m;
	 for( int q=1;q<m;q++)
	 {
		 for( int i=0;i<=n;i++)
			 for(int j=0;j<=n;j++)
				 if(a[i][j]=='@')
				      for( int i_=0;i_<4;i_++)
					   if(a[i+disx[i_]][j+disy[i_]]=='.')
							  a[i+disx[i_]][j+disy[i_]]='&';
		  for( int i=0;i<=n;i++)
			 for(int j=0;j<=n;j++)
				 if(a[i][j]=='&')
					 a[i][j]='@';
	 }
	 for(int i=0;i<=n;i++)
		 for( int j=0;j<=n;j++)
			 if(a[i][j]=='@')
				 sum++;
	 cout<<sum<<endl;
    
	return 0;

}
char c[110][110] ;
 int b[100][100]={0} ;
 int n;
int pat(int m)
{
   int result=0,i=0,j=0;
   if(m==0)
   {
   for(i=0;i<n;i++)
     for(j=0;j<n;j++)
	 {
	    if(c[i][j]=='@') result++;
	 }
	 return result;
   }
   else
   {
      for(i=0;i<n;i++)
	  {
	  for(j=0;j<n;j++)
	  {
	     if(c[i][j]=='@')
		 {if(c[i][j-1]=='.') b[i][j-1]=1;
		  if(c[i][j+1]=='.') b[i][j+1]=1;
          if(c[i+1][j]=='.') b[i+1][j]=1;
		  if(c[i-1][j]=='.') b[i-1][j]=1;
		 }
	  }
	  }
      for(i=0;i<n;i++)
	  {
	  for(j=0;j<n;j++)
	  {
	     if(b[i][j]==1) c[i][j]='@';
	  }
	  }
   }
   pat(m-1);
}
int main()
{
  
   int m,i=0,j=0;
   cin>>n;
   for(i=0;i<n;i++)
   for(j=0;j<n;j++)
   {
   cin>>c[i][j];
   }
   cin>>m;
   m -- ;
   cout<<pat(m);
   return 0;
}
int main()
{
	int n,m,i,j,k,victim=0;
	char a[101][101],b[101][101];
	cin>>n;
	for(i=1;i<=n;i++)
		for(k=1;k<=n;k++)
			cin>>a[i][k];
	cin>>m;
	for(j=1;j<m;j++)
	{
		for(i=1;i<=n;i++)
		for(k=1;k<=n;k++)
		{
			if(a[i][k]=='@') b[i][k]=a[i][k];
		}
		for(i=1;i<=n;i++)
		for(k=1;k<=n;k++)
		{
			if(b[i][k]=='@')
			{
				if(a[i-1][k]=='.') a[i-1][k]='@';
				if(a[i][k-1]=='.') a[i][k-1]='@';
				if(a[i][k+1]=='.') a[i][k+1]='@';
				if(a[i+1][k]=='.') a[i+1][k]='@';
			}
		}
	}
		for(i=1;i<=n;i++)
		for(k=1;k<=n;k++)
		{
			if(a[i][k]=='@') victim++;
		}
		cout<<victim;
		return 0;
}