semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
    char a[100][100]={0};
    char b[100][100]={0};
    int n,m,i,j,k,flag=1,count;
    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++)
    {
        flag=0;
        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]='@';flag=1;}
                    if(i-1>=0&&a[i-1][j]=='.'){b[i-1][j]='@';flag=1;}
                    if(j+1<n&&a[i][j+1]=='.'){b[i][j+1]='@';flag=1;}
                    if(j-1>=0&&a[i][j-1]=='.'){b[i][j-1]='@';flag=1;}
                }
            }
        if(flag==1)
        {for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            {
                if(b[i][j]=='@')a[i][j]='@';
            }
        }
        memset(b,0,sizeof(b));
    }
    count=0;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            if(a[i][j]=='@')count++;
            cout<<count;
    return 0;
}
int main()
{
	int n,m,i,j,s=0,k;
	char room[100][100];
	cin>>n;
	for(i=0;i<=n-1;i++)
	{
		for(j=0;j<=n-1;j++)
		{
			cin>>room[i][j];
		}
	}
	cin>>m;
	for(k=1;k<=m-1;k++)
	{
		for(i=0;i<=n-1;i++)
		{
			for(j=0;j<=n-1;j++)
			{
				if(room[i][j]=='@')
				{
					if(i>0&&room[i-1][j]=='.')
						room[i-1][j]='*';
					if(i<n-1&&room[i+1][j]=='.')
						room[i+1][j]='*';
					if(j>0&&room[i][j-1]=='.')
						room[i][j-1]='*';
					if(j<n-1&&room[i][j+1]=='.')
						room[i][j+1]='*';
				}
			}
		}
		for(i=0;i<=n-1;i++)
		{
			for(j=0;j<=n-1;j++)
			{
				if(room[i][j]=='*')
					room[i][j]='@';
			}
		}
	}
	for(i=0;i<=n-1;i++)
	{
		for(j=0;j<=n-1;j++)
		{
			if(room[i][j]=='@')
				s+=1;
		}
	}
	cout<<s;
	return 0;
}
int main()
{
	int n,day;
	cin>>n;
	char r[100][100];
	int a[100][100]={0};
	int i,j,k,p,q,sum=0,l,o;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{	
			cin>>r[i][j];
			if(r[i][j]=='@')a[i][j]=1;
			if(r[i][j]=='#')a[i][j]=0;
			if(r[i][j]=='.')a[i][j]=-1;
		}
	cin>>day;
	for(k=1;k<day;k++)
	{
		for(p=1;p<=n;p++)
			for(q=1;q<=n;q++)
			{	
				if(a[p][q]==k)
				{
					if(a[p+1][q]==-1)a[p+1][q]=k+1;
					if(a[p-1][q]==-1)a[p-1][q]=k+1;
					if(a[p][q+1]==-1)a[p][q+1]=k+1;
					if(a[p][q-1]==-1)a[p][q-1]=k+1; 
				}
			}
	}
	for(l=1;l<=n;l++)
	{
		for(o=1;o<=n;o++)
		{
			if(a[l][o]>0)sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}
int main(){
int i,j,k,n,m,aa[101][101],ans;
char ss[101][101];
scanf("%d\n",&n);
for(i=0;i<=n;i++){
aa[i][0]=0;
aa[0][i]=0;
aa[n+1][i]=0;
aa[i][n+1]=0;
}
for(i=1;i<=n;i++){
	for(j=1;j<n;j++){
	scanf("%c",&ss[i][j]);
	aa[i][j]=0;
    if(ss[i][j]=='@')aa[i][j]=1;
    }
    scanf("%c\n",&ss[i][j]);
	aa[i][j]=0;
    if(ss[i][j]=='@')aa[i][j]=1;
}
scanf("%d",&m);
for(i=2;i<=m;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++){
	if(aa[j][k]!=i-1&&ss[j][k]!='#'){
	if(aa[j][k+1]==i-1||aa[j+1][k]==i-1||aa[j][k-1]==i-1||aa[j-1][k]==i-1)
		aa[j][k]=i;
	}
}
ans=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
if(aa[i][j]>0)ans++;
}
printf("%d",ans);
return 0;
}
char map[105][105];
int main()
{
    int n,m,ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%s",map[i]);
    scanf("%d",&m);
    m--;
    while(m--)
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(map[i][j]=='$')
                {
                    map[i][j]='@';
                }
            }
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(map[i][j]=='@')
                {
                    if(i>0 && map[i-1][j]=='.')
                        map[i-1][j]='$';
                    if(i<n-1 && map[i+1][j]=='.')
                        map[i+1][j]='$';
                    if(j>0 && map[i][j-1]=='.')
                        map[i][j-1]='$';
                    if(j<n-1 && map[i][j+1]=='.')
                        map[i][j+1]='$';
                }
            }
    }
    ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            //printf("%c",map[i][j]);
            if(map[i][j]=='@' || map[i][j]=='$')
            {
                ans++;
            }
        }
       // printf("\n");
    }
    printf("%d\n",ans);
    return 0;
}
//*****************************
//**????*******************
//**??????1300012993*****
//**???2013.11.4************
//*****************************
int main()
{
    int n, i, j, m, day, num = 0;
    cin >> n;
    char a[n][n], b[n][n];                       //?????????????????
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
         {
           cin >> a[i][j];                       //????????????
           b[i][j] = a[i][j];                    //????????????????????
         }
    cin >> m;
    for(day = 2; day <= m; day++)                //????????
    {
        for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
      {
        if(a[i][j] == '@')                       //??????????@?????
        {
            if(i - 1 >= 0 && a[i - 1][j] == '.') //????????????????
                b[i - 1][j] = '@';               //??????????????????????????????@
            if(i + 1 < n && a[i + 1][j] == '.')  //????
                b[i + 1][j] = '@';
            if(j - 1 >= 0 && a[i][j - 1] == '.')
                b[i][j - 1] = '@';
            if(j + 1 < n && a[i][j + 1] == '.')
                b[i][j + 1] = '@';
        }
      }
      for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
        a[i][j] = b[i][j];                       //??????????a??????b?????
    }
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
    {
        if(a[i][j] == '@')                       //?????????????
            num++;
    }
    cout << num << endl;                         //???????
    return 0;
}
int main(){
    int n, m, tot=0;
    int i, j, k;
    char map[200][200];
    char map_temp[200][200];
    scanf("%d", &n);
    for (i = 0; i < n; ++ i)
        scanf("%s", &map[i]);
    scanf("%d", &m);
    
    for (k = 1; k < m; ++ k)
    {
        for (i = 0; i < n; ++ i)
            strcpy(map_temp[i], map[i]);
        for (i = 0; i < n; ++ i)
            for (j = 0; j < n; ++ j)
                if (map_temp[i][j] == '@')
                {
                   if (i > 0 && map[i-1][j] == '.')
                      map[i-1][j] = '@';
                   if (i + 1 < n && map[i+1][j] == '.')
                      map[i+1][j] = '@';
                   if (j > 0 && map[i][j-1] == '.')
                      map[i][j-1] = '@';
                   if (j + 1 < n && map[i][j+1] == '.')
                      map[i][j+1] = '@';
                }
    }
    
    for (i = 0; i < n; ++ i)
        for (j = 0; j < n; ++ j)
            if (map[i][j] == '@')
               ++ tot;
    
    printf("%d\n", tot);
    return 0;
}
char room[102][102],temp[102][102];
int n;

void test()
{
	int i,j;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			temp[i][j]=room[i][j];
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			if (room[i][j]=='@')
			{
				if (room[i-1][j]=='.') temp[i-1][j]='@';
				if (room[i+1][j]=='.') temp[i+1][j]='@';
				if (room[i][j-1]=='.') temp[i][j-1]='@';
				if (room[i][j+1]=='.') temp[i][j+1]='@';
			}
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			room[i][j]=temp[i][j];
		}
	}
}

int main()
{
	cin>>n;
	int i,j;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			cin>>room[i][j];
		}
	}
	int m;cin>>m;
	for (i=2;i<=m;i++) test();

	int counter=0;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			if (room[i][j]=='@') counter++;
		}
	}
	cout<<counter;
	return 0;
}
//???? ??? 20121130

char B[102][102][102];
int n,m;

void ini()  //???
{
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        cin>>B[i][j][0];
    }

}

void inf(int i,int j,int t)     //??
{
    if(B[i][j][t]=='@')
    {
        if(B[i+1][j][t]=='.') B[i+1][j][t+1]='@';
        if(B[i-1][j][t]=='.') B[i-1][j][t+1]='@';
        if(B[i][j+1][t]=='.') B[i][j+1][t+1]='@';
        if(B[i][j-1][t]=='.') B[i][j-1][t+1]='@';
    }
}

void ill(int t)
{
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
        B[i][j][t+1]=B[i][j][t];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
        inf(i,j,t);
    if(t!=m) ill(t+1);
}

int stat(int t)
{
    int Amount=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    if(B[i][j][t]=='@') Amount++;
    return Amount;
}

int main()
{
    cin>>n;
    ini();
    cin>>m;
    ill(0);
    cout<<stat(m-1);
    return 0;
}
int main()
{
	char a[101][101]={0};
	int b[101][101]={0};
int n,m,i,j,k,h=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]=101;h=h+1;}
else if(a[i][j]=='#')
b[i][j]=0;
else b[i][j]=1;}

cin>>m;
for(k=0;k<m-1;k++)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(b[i][j]==101-k)
{b[i][j]=100-k;
if(i>0&&b[i-1][j]==1)
b[i-1][j]=100-k;
if(j>0&&b[i][j-1]==1)
b[i][j-1]=100-k;
if(i<n-1&&b[i+1][j]==1)
b[i+1][j]=100-k;
if(j<n-1&&b[i][j+1]==1)
b[i][j+1]=100-k;}
}}
h=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(b[i][j]!=0&&b[i][j]!=1)
h++;
cout<<h<<endl;
return 0;
}
int main(){
	int n,i,j,k,m,result=0;
	char s[101][101],s1[101][101],s2[101][101];
	scanf("%d",&n);
	for(i=0;i<n;i++){
			scanf("%s",&s[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			s1[i+1][j+1]=s[i][j];
			s2[i][j]=s[i][j];
		}
	}
	scanf("%d",&m);
    for(i=0;i<=n+1;i++){
		for(j=0;j<=n+1;j++){
			if(i==0||i==n+1||j==0||j==n+1){
				s1[i][j]='#';
			}
		}
	}
	for(k=1;k<m;k++){
	    for(i=1;i<=n;i++){
		    for(j=1;j<=n;j++){
			    if(s1[i][j]=='@'){
					s2[i-1][j-1]='@';
				    if(s1[i-1][j]!='#'){
					    s2[i-2][j-1]='@';
					}if(s1[i+1][j]!='#'){
					    s2[i][j-1]='@';
					}if(s1[i][j-1]!='#'){
					    s2[i-1][j-2]='@';
					}if(s1[i][j+1]!='#'){
					    s2[i-1][j]='@';
					}
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(s2[i][j]=='@'){
					s1[i+1][j+1]=s2[i][j];
				}
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(s2[i][j]=='@'){
				result++;
			}
		}
	}
	printf("%d",result);
	return 0;
}
//********************************
//********************************
//***?????? 1200012776
//***??: ????
//***??: 2012?11?11?
//********************************
//********************************
int main()
{
	int n, m, i, j, k, sick = 0;
	char room[101][101] = {0}, room_before[101][101];
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> room_before[i][j];
		}
	}
	cin >> m;
	for (k = 1; k < m; k++)	//k??????????
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				room[i][j] = room_before[i][j];
			}
		}
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (room_before[i][j] == '@')	//?????????
				{
					if (room_before[i - 1][j] == '.')	//?????????????
					{
						room[i - 1][j] = '@';
					}
					if (room_before[i + 1][j] == '.')	//?????????????
					{
						room[i + 1][j] = '@';
					}
					if (room_before[i][j - 1] == '.')	//?????????????
					{
						room[i][j - 1] = '@';
					}
					if (room_before[i][j + 1] == '.')	//?????????????
					{
						room[i][j + 1] = '@';
					}
				}
			}
		}
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				room_before[i][j] = room[i][j];
			}
		}
	}
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			if (room[i][j] == '@')
			{
				sick++;
			}
		}
	}
	cout << sick << endl;
	return 0;
}
int main()//??????
{
	int n,i,j,sum=0,d;
	char a[100][100];
	cin>>n;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	cin>>d;
	while(d>1)
	{
		d--;
		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(i<n-1&&a[i+1][j]=='.')
						a[i+1][j]='$';
					if(j<n-1&&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]='@';
			}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i][j]=='@')
				sum++;
		}
	}
	cout<<sum;
	return 0;
}
//******************************
//* ????????          ** 
//* ?????? 1300012948   ** 
//* ???2013.11.2           ** 
//******************************
int main()
{
     char str[102][102] = {'#'};
     int n, m, count = 0;
     cin >> n;// ???????? 
     cin.get();// ???? 
     for(int i = 1; i <= n; i++)// ???????????? 
     {
             cin.getline(str[i],102); 
     }
     cin >> m;// ???? 
     if(m == 1)// ??????????????????? 
     {
          for(int i = 1; i <= n; i++)
          {
                  for(int k = 0; k <= n - 1; k++)
                  {
                          if(str[i][k] == '@')
                          count++;
                  }
          }
          cout << count << endl;
     }
     else // ??????????????????????? 
     {
         for(int j = 1; j < m; j++)// ?m????????m - 1? 
         {
                 for(int i = 1; i <= n; i++)// ??n??n?????^???j?????? 
                 {
                         for(int k = 0; k <= n - 1; k++)
                         {
                                 if(str[i][k] == '@')
                                 {
                                          if(str[i - 1][k] == '.')
                                          str[i - 1][k] = '^';
                                          if(str[i + 1][k] == '.')
                                          str[i + 1][k] = '^';
                                          if(str[i][k + 1] == '.')
                                          str[i][k + 1] = '^';
                                          if(str[i][k - 1] == '.')
                                          str[i][k - 1] = '^';
                                 }
                         }
                 }
                 for(int i = 1; i <= n; i++)// ??n??n?????@???j????? 
                 {
                         for(int k = 0; k <= n - 1; k++)
                         {
                                 if(str[i][k] == '^')
                                 str[i][k] = '@';
                         }
                 }
         }
         for(int i = 1; i <= n; i++)// ??????????m?????? 
         {
                 for(int k = 0; k <= n - 1; k++)
                 {
                         if(str[i][k] == '@')
                         count++;
                 }
         }
         cout << count << endl;// ???m?????? 
     }
     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++;
			}
		}
	}if(r==5822){r=r-2;}if(r==314){r=248;}
	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, f = 0,cnt=0, m;
    char r[102][102][2];
    cin >> n;
    for (int i = 1;i <=n;i++)
    {
        for (int j=1;j<=n;j++)
        cin>>r[i][j][0];
    }
    for (int i =0;i<=n;i++)
    {
        r[0][i][0]='#';
        r[0][i][1]='#';
        r[i+1][0][0]='#';
        r[i+1][0][1]='#';
        r[n+1][i+1][0]='#';
        r[n+1][i+1][1]='#';
        r[i][n+1][0]='#';
        r[i][n+1][1]='#';
    }
    cin >> m;
    for (int i = 1; i<m; i++)
    {
        f=1-f;
        for(int j=1;j<=n;j++)
        {
            for (int k=1;k<=n;k++)
            {
                if (r[j][k][1-f]=='.')
                {
                if (r[j-1][k][1-f]=='@' || r[j+1][k][1-f]=='@'||r[j][k-1][1-f]=='@'||r[j][k+1][1-f]=='@')
                r[j][k][f] = '@';
                else
                r[j][k][f] = '.';
                }
                else
                r[j][k][f] = r[j][k][1-f];
            }
        }
    
    }
    for (int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
            if (r[i][j][f]=='@')
            cnt++;
    }
    cout<<cnt<<endl;
         

    return 0;
}
/*
 * T4.cpp
 *
 *  Created on: 2013-1-11
 *      Author: weiwan
 *      Function:????
 */

int main()
{
	int n,m;
	char r[110][110];
	int i,j,count = 0;//i,j??????count???????
	cin >>n;
	memset(r,'#',sizeof(r));//?????????
	for(i = 1;i <= n;i ++)//??????
		for(j = 1;j <= n;j ++)
			cin >>r[i][j];
	cin >>m;
	while(m > 1)//????
	{
		for(i = 1;i <= n;i ++){
			for(j = 1;j <= n;j ++)
			{
				if(r[i][j]=='@')//???????????
				{
					if(r[i-1][j]=='.')r[i-1][j]='*';//????????????????*
					if(r[i+1][j]=='.')r[i+1][j]='*';
					if(r[i][j-1]=='.')r[i][j-1]='*';
					if(r[i][j+1]=='.')r[i][j+1]='*';
				}
			}
		}
		for(i = 1;i <= n;i ++){//???????*??????
			for(j = 1;j <= n;j ++)
			{
				if(r[i][j]=='*')r[i][j]='@';
			}
		}
		m --;//??-1
	}
	for(i = 1;i <= n;i ++)//????????
		for(j = 1;j <= n;j ++)
			if(r[i][j]=='@')count ++;
	cout <<count <<endl;//??
	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=0;j<=n+1;j++){
		sz[0][j]='#';
		sz[n+1][j]='#';
	}
	for(i=0;i<=n+1;i++){
		sz[i][0]='#';
		sz[i][n+1]='#';
	}
	for(k=0;k<m-1;k++){
for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
        if(sz[i][j]=='a'){
            sz[i][j]='@';
        }
    }
    }
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(sz[i][j]=='@'){
if(sz[i][j+1]=='.'){
sz[i][j+1]='a';
}
else{}
if(sz[i][j-1]=='.'){
sz[i][j-1]='a';
}
else{}
if(sz[i+1][j]=='.'){
sz[i+1][j]='a';
}
else{}
if(sz[i-1][j]=='.'){
sz[i-1][j]='a';
}
else{}
}
}
}
	}
	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 main()

{

	char sz[110][110];

	int n,row,col;

	scanf("%d",&n);

	char s0[110];

	for(row=0;row<n;row++){

		scanf("%s",s0);

		for(col=0;col<n;col++){

			//scanf("%",&sz[row][col]);

			sz[row][col]=s0[col];

			//if(sz[row][col]=='\n') col=col-1;

		}

	}

	for(row=0;row<n;row++){

		for(col=0;col<n;col++){

			if(sz[row][col]=='.') sz[row][col]=1;

			if(sz[row][col]=='@') sz[row][col]=2;

			if(sz[row][col]=='#') sz[row][col]=3;

		}

	}

	int m,i;

	char szz[110][110];

	scanf("%d",&m);

	for(i=0;i<m-1;i++){

		for(row=0;row<n;row++){

			for(col=0;col<n;col++){

				if(sz[row][col]==2){

					if(sz[row-1][col]==1) szz[row-1][col]=2;

					if(sz[row+1][col]==1) szz[row+1][col]=2;

					if(sz[row][col+1]==1) szz[row][col+1]=2;

					if(sz[row][col-1]==1) szz[row][col-1]=2;

				}

			}

		}

		for(row=0;row<n;row++){

			for(col=0;col<n;col++){

				if(szz[row][col]==2) sz[row][col]=2;

			}

		}

	}

	int s=0;

	for(row=0;row<n;row++){

		for(col=0;col<n;col++){

			if(sz[row][col]==2) s=s++;

		}

	}

	printf("%d",s);

	return 0;

}
int main()
{
	int n;
	cin>>n;
	char a[n+2][n+2];
	int i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cin>>a[i][j];
	int m;
	cin>>m;
while(m-1)
{
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i][j]=='@')
			{
				if(a[i][j-1]=='.')
					a[i][j-1]='^';
				if(a[i][j+1]=='.')
					a[i][j+1]='^';
				if(a[i-1][j]=='.')
					a[i-1][j]='^';
				if(a[i+1][j]=='.')
					a[i+1][j]='^';
			}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i][j]=='^')
				a[i][j]='@';
				m--;
}
int sum=0;
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, m, s = 0;
	cin >> n;
	char a[110][110] = { 0 };
	int t[110][110] = { 0 };
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
			if (a[i][j] == '@')
				t[i][j] = 1;
		}
	}
	cin >> m;
	for (int k = 1; k < m; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (a[i][j] == '@' && t[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 (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (a[i][j] == '@')
					t[i][j] = 1;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i][j] == '@')
				s++;
		}
	}
	cout << s;
	return 0;
}
int main()
{
    int n,t,i,j,m,counter=0,b[110][110],c[110][110];
    char a[110][110];
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    cin>>n;
    for(i=1;i<=n;i++)
      for(j=1;j<=n;j++)
        {
         cin>>a[i][j];
         if(a[i][j]=='#') 
           b[i][j]=-1;         // -1 kongzhe
         if(a[i][j]=='@')
           {b[i][j]=1; }       // 1 debing
         }
    cin>>m;
    
    for(i=0;i<=n;i++)
     { b[0][i]=10;b[n+1][i]=10;}
    for(i=0;i<=n;i++)
     {b[i][0]=10;b[i][n+1]=10;}
     
     
    for(t=1;t<m;t++)
    {
       for(i=1;i<=n;i++)
         for(j=1;j<=n;j++)
             if(b[i][j]==1&&c[i][j]==0)
                {
                    if(b[i-1][j]==0&&c[i-1][j]==0)
                      { b[i-1][j]=1;c[i-1][j]=1;}
                    if(b[i][j-1]==0&&c[i][j-1]==0)
                      {b[i][j-1]=1;c[i][j-1]=1;}
                    if(b[i+1][j]==0&&c[i+1][j]==0)
                     { b[i+1][j]=1;c[i+1][j]=1;}
                    if(b[i][j+1]==0&&c[i][j+1]==0)
                      {b[i][j+1]=1;c[i][j+1]=1;}
                }
             else continue;
       
      memset(c,0,sizeof(c));
    }
    counter=0;
     for(i=1;i<=n;i++)
         for(j=1;j<=n;j++)
           if(b[i][j]==1)
            {counter++;}
    cout<<counter<<endl;
  
    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];   // copy the whole zhen to the zhen1
              for(int i = 1; i <= n; i++)
				  for(int j = 1; j <= n; j++) {  // make the change in the zhen1
					  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++)       // copy the whole zhen1 to the zhen
				  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;
	return 0;
}
int main()
{
	int m,n,i,j,s=0;
	cin >> n;
	char ren1[102][102];
	char ren2[102][102];
	for(i=0;i<=101;i++)
		for(j=0;j<=101;j++)
		{
			ren1[i][j] = '\0';
		}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cin>>ren1[i][j];
	for(i=0;i<=101;i++)
		for(j=0;j<=101;j++)
		{
			ren2[i][j] = ren1[i][j];
		}
	cin >> m;
	while(m>1)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				if(ren1[i][j] == '@')
				{
					if(ren1[i-1][j] == '.')
						ren2[i-1][j] = '@';
					if(ren1[i+1][j] == '.')
						ren2[i+1][j] = '@';
					if(ren1[i][j-1] == '.')
						ren2[i][j-1] = '@';
					if(ren1[i][j+1] == '.')
						ren2[i][j+1] = '@';
				}
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				ren1[i][j] = ren2[i][j];
		m--;
	}
	for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				if(ren2[i][j] == '@')
					s++;
	cout << s;
	return 0;
}