semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
	int m,n,i,a[100001][2],b[10001],j;
	scanf("%d",&n);
	scanf("%d %d",&a[0][0],&a[0][1]);
	for (m=1;!(a[m-1][0]==0&&a[m-1][1]==0);m++)
	{
		scanf("%d %d",&a[m][0],&a[m][1]);
	}
	m-=1;
	for (i=0;i<n;i++) b[i]=0;
	for (i=0;i<m;i++)
	{
		b[a[i][0]]-=1;
		b[a[i][1]]+=1;
	}
	j=0;
	for (i=0;i<n;i++)
	{
		if (b[i]==n-1)
		{
			if (j==0) printf("%d",i);
			else printf(" %d",i);
			j++;
		}
	}
	if (j==0)
	printf("NOT FOUND");
}
int know[100000]={0};
int be_known[100000]={0};
int main()
{
	int n;
	scanf("%d",&n);
	while(1)
	{
		int temp1=0,temp2=0;
		scanf("%d%d",&temp1,&temp2);
		if((temp1==0)&&(temp2==0)) break;
		else
		{
			know[temp1]++;
			be_known[temp2]++;
		}
	}
	int flag =-1;
	for(int i=0;i<n;i++)
	{
		if((know[i]!=n-1)&&(be_known[i]==n-1))
		{
			flag=i;
			break;
		}
	}
	if(flag!= -1)
	{
		printf("%d",flag);
	}
	else
	{
		printf("NOT FOUND");
	}
	return 0;
}
int main()
{
	int n, i, j, a[100000] = {0};
	cin >> n;
	while (cin >> i && cin >> j && (i != 0 || j != 0) )
	{
		a[j] ++;
	}

	for(i = 0; i < n; i++)
	{
		if(a[i] == n - 1)
		{	cout << i;
		break;}
	}
	if (i == n)
	cout << "NOT FOUND";
	return 0;
}
int main()
{
	int n,i,j,k,a[10000],b[10000],c=0,d=0;
	scanf("%d",&n);
	for(i=0;i<10000;i++)
	{ 
		scanf("%d%d",&a[i],&b[i]);
		if(a[i]==0&&b[i]==0)break;
	}
	for(j=0;j<n;j++)
	{        
                c=0;
		for(k=0;k<i;k++)
		{
			if(b[k]==j)c++;
			if(a[k]==j)c--;
		}
		if(c==n-1)
		{
			printf("%d",j);
			d=1;
		}
	}
	if(d==0)printf("NOT FOUND" );
	return 0;
}
int main ()
{
	int n, i, counta, countb, person1[50000], person2[50000];
	int flag = 0;
	int *Person1, *Person2;
	cin >> n;
	for ( Person1 = person1, Person2 = person2; ; Person1 ++, Person2 ++ )
	{
		cin >> *Person1 >> *Person2;
		if ( *Person1 == 0 && *Person2 == 0 )
			break;
	}
	for ( i = 0; i < n; i ++ )
	{
		counta = 0;
		countb = 0;
		for ( Person1 = person1, Person2 = person2; ; Person1 ++, Person2 ++ )
		{
			if ( *Person1 == 0 && *Person2 == 0 )
				break;
			if ( *Person1 == i )
				counta ++;
			if ( *Person2 == i )
				countb ++;
		}
		if ( counta == 0 && countb == n - 1 )
			cout << i << endl;
	}
	return 0;
}
int main()
{
	int num[1000000]={0};
	int n, i, j, *p, count = 0, flag = 0;
	cin >> n;
	do
	{
		cin >> i;
		cin >> j;
		if(i + j == 0)     break;
		else
		{
			num[j]++;
		}
	}while(1);
	p = num;
	while(count < n)
	{
		if( *p == n-1 )
		{
			cout << count;
			flag = 1;
			break;
		}
		else
		{
			p++;
			count++;
		}
	}
	if(!flag)       cout << "NOT FOUND";

	return 0;
	}
//**********************************************************
//*  ?????4.cpp                                       *
//*  ??????1200012906                                *
//*  ???2012?12?10?                                  *
//*  ???????????                                *
//**********************************************************


struct
{
	int know;   //?????
	int known;   //?????
}people[10000];
int main()
{
	int n, i, j, flag = 0;
	cin >> n;
	while(cin >> i >> j && i != 0 || j != 0)
	{
		people[i].know++;
		people[j].known++;
	}
	for(i = 0; i < n; i++)
		if (people[i].know == 0 && people[i].known == n - 1)
		{
			cout << i << endl;
			flag = 1;
		}
	if (flag == 0)
		cout << "NOT FOUND" << endl;
	return 0;
}
int main ()
{
	int a[80000], b[80000], n, i, j, k, c[80000], flag = 0;
	cin >> n;
	for(i = 0;i <= n - 1;i++)
		c[i] = i;
	for(i = 0; ;i++)
	{
		cin >> a[i] >> b[i];
		if(a[i] == 0 && b[i] == 0) break;
	}
	for(j = 0;j < i;j++)
		c[a[j]] = -1;
	for(j = 0;j < n;j++)
		if(c[j] != -1)
		{
			int num = 0;
			for(k = 0;k < i;k++)
				if(b[k] == j) num++;
			if(num == n - 1) 
			{
				cout << j << endl;
				flag = 1;
			}
		}
	if(flag == 0)  cout << "NOT FOUND" <<endl;
	return 0;
}
void main()
{
    int a[100000],b[100000];
    int i,j,k,n,m=0;
    int r,t,p=0;
    scanf("%d",&n);
    scanf("%d %d",&a[m],&b[m]);
    while(a[m]!=0||b[m]!=0)
    {  m++;
       scanf("%d %d",&a[m],&b[m]);
    }
    for(k=0;k<n;k++)
    {
       r=0;t=0;
       for(j=0;j<m;j++)
          if(a[j]==k) {r=1;break;}
       if(r==1) continue;
       for(j=0;j<m;j++)
          if(b[j]==k) t++;
       if(t==n-1)
       {printf("%d\n",k);p=1;}
    }
    if(p==0) printf("NOT FOUND\n");    
}
int main(){
	int n;
	cin>>n;
	int ai[n],aj[n];
	int c,d;
	for(int i=0;i<n;i++){
		ai[i]=aj[i]=0;
	}
	while(true){
		cin>>c;
		cin>>d;
		if(c==0&&d==0)break;
		else{
			ai[c]++;
		    aj[d]++;
		}
	}
	int j;
	for( j=0;j<n;j++){
		if(ai[j]==0&&aj[j]==n-1){
			cout<<j<<endl;
			break;}
	}
	if(j==n)cout<<"NOT FOUND"<<endl;
	return 0;
}
int main()
{
	int n,a[10000][2] = {0},i,k[2],tf = 1;
	cin >> n;
	while (1)
	{
		cin >> k[0] >> k[1];
		if ((k[0] == 0)&&(k[1] == 0))
			break;
		a[k[0]][0]++;
		a[k[1]][1]++;
	}
	for (i = 0;i < n;i++)
	{
		if ((*(*(a + i)) == 0)&&(*(*(a + i) + 1) == n - 1))
		{
			cout << i << endl;
			tf = 0;
		}
	}
	if (tf == 1)
		cout << "NOT FOUND" << endl;
	return 0;
}
int main()
{
	struct people
	{
		int k;
		int kn;
	}p[10001];
	int n, p1, p2, m=0, i;
	for (i=0;i<n;i++)
	{
		p[i].k=0;
		p[i].kn=0;
	}
	cin >> n;
	for (i=0;i<n*n;i++)
	{
		cin >> p1 >> p2;
		if (p1==0&&p2==0)
			break;
		else
		{
			p[p1].k++;
			p[p2].kn++;
		}
	}
	for (i=0;i<n;i++)
	{
		if (p[i].k==0&&p[i].kn==n-1)
		{
			m++;
			cout << i;
		}
	}
	if (m==0)
		cout << "NOT FOUND";
	return 0;
}
main()
{
	int i,k,n,a,b,f=-1,c[10000],d[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		c[i]=-1;
		d[i]=0;
	}
	for(;;)
	{
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)break;
		else
		{
			c[a]=0;
			d[b]++;
		} 
	}
	for(i=0;i<n;i++)
	{
		if(c[i]==0)continue;
		if(d[i]==n-1)
		{
			printf("%d",i);
			f=i;
		}
	}
	if(f==-1)printf("NOT FOUND");
}
int main()
{
	int n;
	cin >> n;
	int l[10000],r[10000];
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	while(1)
	{
		int a,b;
		cin >> a>>b;
		if(a==0 && b==0)
			break;
		l[a] = 1;
		r[b] +=1;
	}
	for(int i=0;i<n;i++)
	{
		if(l[i] == 0 && r[i] == n-1)
		{
			cout << i <<endl;
			return 0;
		}
	}
	cout <<"NOT FOUND"<<endl;
	return 0;

}
int a[1000000];
int main()
{
	int n;
	int x,y;
	cin>>n;
	while(1)
	{
		cin>>x>>y;
		if(x==0 && y==0)break;
		a[x]=-1;
		if(a[y]>=0)a[y]++;
	}
	int flag=false;
	for(int i=0;i<n;i++)if(a[i]==n-1){cout<<i<<endl;flag=true;break;}
	if(flag==false)cout<<"NOT FOUND"<<endl;
	return 0;
}
int main()
{
	struct mingliu
	{
		int i ; 
		int j ;
	}people[10000];
	int n , k , a[10000] , p = 0;
	memset(a,0,sizeof(a));
	cin >> n;
	for(k = 0 ;;k++)
	{
		cin >> people[k].i >>people[k].j;
		if(people[k].i == 0 && people[k].j ==0) 
			break;
		a[people[k].i]++;
	}
	for(k = 0 ; k < n ; k++)
	{
		if(a[k] == 0)
		{
			cout << k <<endl;
			p++;
		}
		if(k == n - 1 && p == 0)
		{
			cout << "NOT FOUND"<<endl;
		}
	}
	return 0;
}
int main()
{
	int n, x, y, j, flag;
	int beknown[10000];
	while(cin>>n)
	{
		memset(beknown, 0, sizeof(beknown));
		while(1)
		{
			cin>>x>>y;
			if(x==0 && y==0)
				break;
			beknown[x] = -1;                         //?????????
			if(beknown[y]!=-1)
				beknown[y]++;                        
		}
		flag = false;
		for(j=0; j<n; j++)
			if(beknown[j]==n-1)                       //????????????
			{
				flag = true;
				cout<<j<<endl;
			}
		if(!flag)
			cout<<"NOT FOUND"<<endl;
	}
	return 0;
}
/*
 * xiaoceyan5.4.cpp
 * ?????????
 *  Created on: 2011-1-8
 *      Author: william
 */
int main()
{
	int n, i, j, k, num, mingliu=-1;
	int b[100000][2];
	cin>>n;
	for(i=0 ;; i++)
	{
		cin>>b[i][0]>>b[i][1];
		if(b[i][0]==0&&b[i][1]==0) break;
	}
	num=i;
	for(i=0; i<n; i++)
	{
		int q=0;
		for(j=0; j<num; j++)
		{
			if(b[j][0]==i) break;
		}
		if(j==num)
		{
			for(k=0; k<num; k++)
			{
				if(b[k][1]==i) q++;
			}
			if(q==n-1) mingliu=i;
		}
	}
	if(mingliu==-1) cout<<"NOT FOUND";
	else cout<<mingliu;
	return 0;
}
int way(int m,int n)  
{
    if(m==0||n==1)  
        return 1;       
    else if(n>m)
        return way(m,m);
    else	
        return way(m,n-1)+way(m-n,n);
}
int main()
{
    int i,t,m,n;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%d%d",&m,&n);
        printf("%d\n",way(m,n));
    }

return 0;
}
int main(){
    int t,m,n,f[101][101],i,j;
    for(i=1;i<101;++i)f[i][0]=0,f[0][i]=1;
    for(i=1;i<101;++i)
        for(j=1;j<101;++j)
            if(i<j)f[i][j]=f[i][j-1];
            else f[i][j]=f[i-j][j]+f[i][j-1];
    cin>>t;
    while(t--){
        cin>>m>>n;
        cout<<f[m][n]<<endl;
    }
}
int apple(int M, int N)
{
	// ?????? 
    if((M < 1) || (N < 1)) return 0;   // 1?M?N????0?????0?
    if(M == 1 || N == 1) return 1;     //2?M?N???????1?????1? 
    
    // ??????? 
    if(M < N) return apple(M, M);      // 1????????????
	                   //??????N - M????? 
    if(M == N) return apple(M, N - 1) + 1; //2????????????,
                      //??????????1???? 
    return apple(M, N - 1) + apple(M - N, N); // 3??????????????
	     //?1?????????apple(M, N - 1)???2)???????apple(M - N, N)? 

}

int main()
{
	int t, M, N, i;
	cin >> t;
	for (i = 1; i <= t; i++)
	{
		cin >> M >> N;
		cout << apple(M, N) << endl;
	}
	return 0;
}
int f(int m,int n){
	if(m<0) return 0;
	if(n==1) return 1;
	return f(m,n-1)+f(m-n,n);
}

void main(){
    int m,n,t;
	scanf("%d",&t);
	while(t-->0){
		scanf("%d%d",&m,&n);
		printf("%d\n",f(m,n));
	}
}
int apple( int m , int n ) ;

int main()
{
	int t , i , k , m , n ;

	cin >> t ;

	for( i = 1 ; i <= t ; i ++ )
	{
		cin >> m >> n ;

		k = apple( m , n ) ;

		cout << k << endl ;
	}

	return 0 ;
}


int apple( int m , int n )
{
	if( m == 1 || n == 1 || m == 0 )
		return 1 ;

	if( m >= n )
		return( apple( m , n - 1 ) + apple( m - n , n ) ) ;

	else
		if( m < n )
			return apple( m , n - 1 ) ;

}
int function(int n,int m)
	{
		int f;
		if(n==1||m==0||n==0||m==1)
			f=1;
		else if(m<0)
			f=0;
		else
			f=function(n-1,m)+function(n,m-n);
		return(f);
	}
int main()
{
	int t,m,n,k;
	scanf("%d",&t);
	int i;
	for(i=0;i<t;i++)
	{
     scanf("%d %d",&m,&n);
	if(m<n)
		{
			n=m;
			k=function(n,m);
	     }
	else
		{
			k=function(n,m);
	     }

	printf("%d\n",k);
	}
}
// ?????.cpp : Defines the entry point for the console application.
//

int fen(int x,int y);
int main(int argc, char* argv[])
{
	int i,m,n,sum;
	scanf("%d",&sum);
	for(i=0;i<sum;i++){
		scanf("%d%d",&m,&n);
		printf("%d\n",fen(m,n));
	}
	return 0;
}


int fen(int x,int y){
	int result=0;
	if(y!=1)result+=fen(x,y-1);
	if(x-y>=0&&y!=1)result+=fen(x-y,y);
	if(y==1){
		result++;
		return result;
	}
	return result;
}
//****************************
//*?????? 1300012809  **
//*???2013.11.29         **
//*????????         **
//****************************
int m, n, k;
int fenfa(int x, int y);                                   //?????
int main()
{
	int i, j, t;
	cin >> t;                                              //?????????
	for (i = 1; i <= t; i++)
	{
		cin >> m >> n;                                     //???????????
	
		k = fenfa(m, n);                                   //??????
		cout << k << endl;                                 //??
	}
	return 0;
}
int fenfa(int x, int y)                                    //????
{ 
	if (x == 1) return 1;                                  //?????????????1????1
	if (y == 1) return 1;
	if (x == 0 || y == 0) return 1;
	if (x < 0 || y < 0) return 0;                          //????????0
// ???????????????N?????M???????????N-1?????M????????????
// ??????????????N?????M????????????N?????M-N??????????
	if (x != 1 && y != 1 && x != 0 && y != 0) return (fenfa(x, y-1) + fenfa(x-y,y)); 
}
int apple(int m,int n)
{
	int k;
	if(n==1)
		k=1;
	else if(m==1)
		k=1;
	else if(m==2)
		k=2;
	else if(m<n)
		k=apple(m,n-1);
	else
	k=apple(m,n-1)+apple(m-n,n);
	return k;
}
int main()
{
	int t,m,n,k;
	scanf("%d",&t);
	int i;
	for(i=0;i<t;i++)
	{
		scanf("%d%d",&m,&n);
		k=apple(m,n);
	    printf("%d\n",k);
	}
	
	return 0;
}
/**************
*?????
*?????
***************/
int f1(int m, int n); //m???? n???
int main()
{
	int t, m, n;    //t???
	cin >> t;
	for(int i=0; i < t; i++)
	{
		cin >> m >> n;
		cout<<f1(m,n)<<endl;//????
	}
return 0;
}
int f1(int m, int n)
{
	if(n == 1 || ((m < n)&&(m==0||m==1)))       //??????
	{
		return 1;
	}
	else            //?????????
	{
		if(m >= n)
		{
			return f1(m,n-1)+f1(m-n,n);
		}
		else
		{
			return f1(m,m);
		}
	}
}
int digui(int m,int n)
{
	int p;
	if(m<n)
		p=digui(m,m);
	else
	{
		if(m==0||n==1)
		p=1;
		else p=(digui(m,n-1)+digui(m-n,n));
	}return(p);
}
void main()
{
	int m,n,t,i,a[20],b[20],c[20],p,q;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d%d",&b[i],&c[i]);
		p=b[i];q=c[i];
		a[i]=digui(p,q);
	}
	printf("%d",a[0]);
	if(t>=1)
	for(i=1;i<t;i++)
	printf("\n%d",a[i]);
}
int s=0;
int f(int M,int N)
{ 
  if((M>0)&&(N>0))  
  {
    if((N==1)||(M==1))
    {s=s+1;}
    else if((M<=N)&&(M!=1)&&(N!=1))
    {s=s+1;f(M,M-1);}
    else
    {
        
     f(M,N-1);
     f(M-N,N);
    }    
   }
  return s;
    
}
 int main()
{ 
  int t;
  scanf("%d",&t);
  for(int i=0;i<=t-1;i++)
{  
 int a,b;   
 scanf("%d %d",&a,&b);
 printf("%d\n",f(a,b));s=0;}
 int y;
 scanf("%d",&y);
 return 0;    
}
int gedui(int zong, int duishu,int ini){
	int p,k=0,end;
	end=zong/duishu;
	if(duishu>2){
		for(p=ini;p<=end;p++){
			k+=gedui(zong-p,duishu-1,p);
		}
	}
	else if(duishu==2){
		k=zong/2-ini+1;
	//	printf("2zong%d,ini%d,k%d\n",zong,ini);
	}
	else if(duishu==1){
		k=1;
	}
	return k;
}

int r(int zong,int dui){
	int o,count=0;
	for(o=1;o<=dui;o++){
		count+=gedui(zong,o,1);
	//	printf("count%d,zong%d,dui%d\n",count,zong,dui);
	}
	return count;
}



int main(){
	int k,m,n;
	int i,dui,u;
	scanf("%d",&k);
	for(i=0;i<k;i++){
		u=0;
		scanf("%d%d",&m,&n);
		if(m>n){
			dui=n;
		}
		else{
			dui=m;
		}
		u=r(m,dui);
		if(i!=0){
			printf("\n");
		}
		printf("%d",u);
	}
	return 0;
}
int fun(int m,int n,int j);
int main()
{
     int s,i,x;
     int m[100],n[100];
     scanf("%d",&x);
     for(i=0;i<x;i++)
    {
     scanf("%d%d",&m[i],&n[i]);
    }
     for(i=0;i<x;i++)
     {
     if(n[i]>m[i])
     n[i]=m[i];
     s=fun(m[i],n[i],0);
     printf("%d\n",s);
     }
}
int fun(int m,int n,int j)
{
    int i,s=0;
    if(n==1) return m>=j;
    for(i=j;i<m;i++) s+=fun(m-i,n-1,i);
return s;
}
void main()
{
	int f(int,int);
	int m,n,t;
	scanf("%d",&t);
	while(t>0)
	{
		scanf("%d %d",&m,&n);
		printf("%d\n",f(m,n));
		t--;
	}
}
int f(int x,int y)
{
	if(x==0||y==1)
		return 1;
	if(x<y)
		return f(x,x);
	return f(x-y,y)+f(x,y-1);
}
int N,n,m;
int max(int x,int y)
{
    int c;
    if(y<=0)
    {
        if(y==0)
        c=1;
        else
        c=0;
    }
    else
    {
        if(x==1)
            c=1;
        else
            c=max(x-1,y)+max(x,y-x);
    }
    return(c);
}
main()
{
      int i;
      scanf("%d",&N);
      for(i=1;i<=N;i++)
      {
          scanf("%d%d",&n,&m);
          printf("%d\n",max(m,n));
      }
     }
int count(int m,int n)
{
    int c;
    if (m<0)
    c=0;
    else if (n==1)
    c=1;
    else
    c=count(m,n-1)+count(m-n,n);
    return c;
}
int main(int argc, char *argv[])
{
  int t,i,m,n;
  scanf("%d",&t);
  for (i=0;i<=t-1;i++)
  {
      scanf("%d%d",&m,&n);
      printf("%d\n",count(m,n));
  }	
  return 0;
}
//**********************************
//??: ???
//???2013.11.23
//**********************************
int k=0;

int count(int m,int n)
{
   if(m<0)
	   return 0;
   if(n==1||m==0)
	   return 1;
   else 
	 k=count(m-n,n)+count(m,n-1);
   return k;
}

int main()
{   
	 int m[25],n[25],sum=0,t=0,i=0;
	 cin>>t;
	 for(i=1;i<=t;i++)
	 {
		 cin>>m[i]>>n[i];
		 sum=count(m[i],n[i]);
		 cout<<sum<<endl;
	 }

	return 0;	
}
main()
{
      int m[100],n[100],a[100],t;
      int ppp(int m,int n);
      int fff(int m,int n);
      for(int i=0;i<100;i++)
      {
              a[i]=0;
      }
      scanf("%d",&t);
      for(int i=0;i<t;i++)
      {
              scanf("%d %d",&m[i],&n[i]);
              a[i]=ppp(m[i],n[i]);
      }
      for(int i=0;i<t;i++)
      {
              printf("%d\n",a[i]);
      }
}
int ppp(int m,int n)
{
    int p;
    int fff(int m,int n);
    if(n>1)
    p=ppp(m,n-1)+fff(m,n);
    else if(n==1)
    p=1;
    return(p);
}
int fff(int m,int n)
{
    int f;
    if(m>n)
    f=ppp(m-n,n);
    else if(m==n)
    f=1;
    else if(m<n)
    f=0;
    return(f);
}
int devide(int x,int y)
{
    if(y==1)
	{
		return 1;
	}

	else if(x==1)
	{
		return 1;
	}
	else if(x<y)
	{
		return devide(x,x);
	}
	else if(x>y)
	{
		return devide(x,y-1)+devide(x-y,y);
	}
	else if(x==y)
	{
		return devide(x,y-1)+1;
	}
}
int main()
{
    int n,i;
    scanf("%d",&n);
    int x,y;
    int out;
    for(i=0;i<=n-1;i++)
    {
        scanf("%d %d",&x,&y);
        out=devide(x,y);
        printf("%d\n",out);
    }
}
int main()
{
	int t;//???????
	cin>>t;
	int f(int,int);
	for(int i=1;i<=t;i++)
	{
		int m,n;
		cin>>m>>n;//m????n???
		int ans;
		ans=f(n,m);
		cout<<ans<<endl;
	}
	return 0;
}
int f(int pa,int pi)
{
	int c=0;
	
	if(pa==1||pi==0)
	{
		c=1;
	}
	if(pi<0)
	{
		c=0;
	}
	if(pa>1&&pi>=1)
		c=f(pa-1,pi)+f(pa,pi-pa);
	return(c);
}
int fang(int m,int n);//??????
int main()
{
int p,i,m,n;
cin>>p;
for(i=1;i<=p;i++)
{
cin>>m>>n;
cout<<fang(m,n)<<endl;//????
}
return 0;
}
int fang(int m,int n)
{
int sum;
if(n==1||m==1||m==0)//????
sum=1;
else if(m<0)
sum=0;
else sum=fang(m,n-1)+fang(m-n,n);//???
return sum;
}
int sum = 0;  
int work( int a,int b )
{    
     if((a==0)||(a==1)||(b==1)||(b==0))
     return 1;
     if( b>a )
     b = a;
     return( work(a,b-1)+work(a-b,b));
    
}
int main()
{
   int m , n , t , i;
   scanf( "%d",&t );
   for( i = 1 ;i <= t;i++  )
   {scanf("%d%d",&m,&n);
    if( n>=m )
     n=m;
    sum = work( m ,n);
    printf("%d\n",sum);
    sum = 0;
   }      
}
int Apple(int m, int n)
{
	if (m == 0 || n == 0)
		return 0;
	if (m == 1 || n == 1)
		return 1;
	if (m < n)
		return Apple(m, m);
	if (m == n)
		return Apple(m, n - 1) + 1;
	return Apple(m - n, n) + Apple(m, n - 1);
}
int main()
{
	int t, a, b;
	cin >> t;
	while (t)
	{
		cin >> a >> b;
		cout << Apple(a, b) << endl;
		t--;
	}
	return 0;
}
int put( int , int );

int main()
{
	int t , i;
	int m , n; 
	int k;
	
	cin >> t;
	
	for ( i = 1; i <= t; i++ )
	{
		cin >> m >> n;
		k = put(m , n);
		cout << k << endl;
	}
	
	return 0;
}

int put( int x, int y)
{
	if ( x == 0 || y == 1 )
		 return 1;
	else
	{
		if ( x >= y )
			return put (x , y-1) + put( x-y, y );
		if ( x < y )
			return put(x , y-1);
	}
}
int allfilled(int m,int n);
int notallfilled(int m,int n);
main()
{
      int t,i,m,n,c,d,sum;
      scanf("%d\n",&t);
      for(i=0;i<t;i++)
      {
      scanf("%d %d",&m,&n);       
      if(m>=n)    
      {
          c=notallfilled(m,n);
          d=allfilled(m,n);
          sum=c+d;
      }
      else
          sum=notallfilled(m,n);
      printf("%d\n",sum);
      }
          
}

int allfilled(int m,int n)
{
     int z;
     if(m==n)
        return 1;
     else if(n==1)
        return 1;
     else 
     {
     if(m-n>=n)
        z=allfilled(m-n,n)+notallfilled(m-n,n);
     else
        z=notallfilled(m-n,n);
     return z;
     }
}

int notallfilled(int m,int n)
{
     int z;
     if(n==1)
        return 0;         
     else
     {
     if(m<n-1)
        z=notallfilled(m,n-1);
     else
        z=allfilled(m,n-1)+notallfilled(m,n-1);
     return z;
     }
}
//*************************************
//**???? ?????
//**???? ??? 1000010257
//**???? ???
//**?? 2010?12?1?
//*************************************


void fenpg( int  , int );//????
int k , pg[20] ;
  //??????k??????pg????????????
int main()
{
	int t , m , n  ;
	cin>>t;
	for( int i = 1 ; i <= t ; i++)
	{
		cin>> m >> n ;
		k = 0;
		for( int j = n ; j >= 1 ; j--)  //???????j?????? n - 1 ?
		{
		   for( int o = 1 ; o <= 19 ; o++)
		   {
			pg[o] = 0;  //????????????????
		   }
		   pg[j + 1] = m;  //?n + 1?????????m???
			fenpg( m ,j );
		}
	cout<<k<<endl;
	}
	return 0;
}

void fenpg( int pgleft  ,int pzleft)
{
	if( pgleft == 0  && pzleft == 0)      //???????????
	{
		k++;                              //????
		return;
	}
	
	else if( pgleft > 0 && pzleft > 0 )   //?????????????? == 0&& ?? >0 ??????????? ?????>0&&??== 0 ?????????????????? 
	{
		for( int i = pgleft ; i > 0 ; i--)
		{
			if( i <= pg[pzleft + 1])       //????????????????????????????????
			{
				pg[pzleft] = i;
			   fenpg( pgleft - i , pzleft - 1);//?????????????
			}
		}
	}
}
int i,j,k,m,n,way,way1;
int put(int m,int n)
{
	if(m >= 0)
	{
    	if (n == 1)
	    	way = 1;
    	else
	    	way = put(m - n,n) + put(m,n-1) ;
	}
	else
		way = 0;
	return way;
}
int main()
{
	int t;
	cin>>t;
	while (t--)
	{
		cin>>m>>n;
		way = put(m,n);
		cout<<way<<endl; 
	}
	return 0;
}
int main()
{
	int m, n, t, opt[101][101];
	memset(opt, 0, sizeof(opt));
	for (int i = 0; i < 101; ++i)
		opt[0][i] = 1;
	for (int i = 0; i < 101; ++i)
		opt[i][1] = 1;
	for (int j = 1; j < 101; ++j)
		opt[1][j] = 1;
	for (int j = 2; j < 101; ++j)
		for (int i = 2; i < 101; ++i) {
			if (i >= j) opt[i][j] += opt[i-j][j];
			opt[i][j] += opt[i][j-1];
		}
	cin >> t;
	while (t--) {
		cin >> m >> n; 
		cout << opt[m][n] << endl;
	}
	return 0;	
}
int ways(int a,int b)
{
	int p;
	if(b==1||a==0||a==1)
		return 1;
	else
	{
		if(a<b)
			p=ways(a,a);
		else
		p=ways(a,b-1)+ways(a-b,b);
	}
	return p;
}

void main()
{
	int n[20],m[20],t,i,k[20];
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d%d",&n[i],&m[i]);
		k[i]=ways(n[i],m[i]);
	}
	for(i=0;i<t;i++)
		printf("%d\n",k[i]);
}
int num(int m,int n,int sum)
{
	if (m==1 || n==1)
	{
		sum++;
		return sum;
	}
	if (m<n)
		sum=num(m,n-1,sum);
	else if (m==n)
		sum=1+num(m,n-1,sum);
	if (m>n)
	{
		sum=num(m,n-1,sum);
		sum=num(m-n,n,sum);
	}
	return sum;
}

void main()
{
	int i,t,m,n,sum=0;
	scanf ("%d",&t);
	for (i=0;i<t;i++)
	{
		sum=0;
		scanf ("%d %d",&m,&n);
		sum=num(m,n,sum);
		printf ("%d\n",sum);
	}
}
int an( int,int );
int main()
{   
	int m,n;
	int t,i,j;
	cin >> t;

	if( t>0)
	{
		for( i=0;i<t;i++ )
		{
              cin >> m >> n;
			  cout << an( m,n ) << endl;
		}
	}
	return 0;
}


int an ( int m,int n)
{
	if( ( m==0 )||(n==1) )
		return 1;

	if( m>=n )
		return an(m-n,n)+an(m,n-1);
	else
		return an( m,n-1);
}
int f[30][30];
int K(int m, int n)
{
	if(f[m][n])
	{
		return f[m][n];
	}
	else if (m==1||n==1)
	{
		f[m][n]=1;
		return f[m][n];
	}
	else if(m<n)
	{
		f[m][n]=K(m,m);
		return f[m][n];
	}
	else if (m==n)
	{
		f[m][n]=K(m,m-1)+1;
		return f[m][n];
	}
	else
	{
		f[m][n]=K(m-n,n)+K(m,n-1);
		return f[m][n];
	}
}

int main(){
int t;
scanf("%d", &t);
int M, N, k;
for (int i=0; i<t; i++)
	{
		scanf("%d%d", &M, &N);
		k=K(M,N);
		printf("%d\n", k);
	}
return 0;
}
//?????
int sum(int a,int b)//????
{
	int x;
	if (a==0||a==1||b==1)//sum(0,b)=sum(1,b)=sum(a,1)=0
	{
		return 1;
	}
	else if (a<b)//??sum(a-b,b)????????????
	{
		return sum(a,b-1);
	}
	else
	{
		x=sum(a,b-1)+sum(a-b,b);
		return x;
	}
}
int main()
{
	int t,m,n,i;
	cin>>t;
	for (i=1;i<=t;i++)
	{
		cin>>m>>n;
		cout<<sum(m,n)<<endl;
	}
	return 0;
}
int f(int m,int n)
{
    int c;
    if (m==1||n==1||m==0)
    {
                   c=1;
    }
    else
    {
    if (m<n)
    {
              c=f(m,m);
    }
    else 
    {
              c=f(m,n-1)+f(m-n,n);
    }
    }
    return (c);
}         
main()
{
      int t,m,n;
      scanf("%d",&t);
      int i=0;
      for (i=0;i<=t-1;i++)
      {
          scanf("%d %d",&m,&n);
          printf("%d\n",f(m,n)); 
      }
      getchar();getchar();getchar();getchar();getchar();getchar();
}
int f(int m,int n){
	int result=0;
	if(m==0||n==1)
		return 1;
	if(m<0)
		return 0;

	if(m>=n)
		result+=f(m,n-1)+f(m-n,n);
	else
		result+=f(m,n-1);

	return result;
}
	
    int main(){
	int m,n,i,t,a;
	scanf("%d",&t);

	for(i=0;i<t;i++){
		scanf("%d%d",&m,&n);
	
		a=f(m,n);
			
		if(i<t-1){
	
			printf("%d\n",a);
		}
		else
			printf("%d",a);

	}
	return 0;
	}
int way(int m, int n)
{
	if(n == 1)
		return 1;

	 if(m > n)
	 {
		return way(m, n - 1) + way(m - n , n);
	 }
	 if(m < n)
	 {
		return way(m, n - 1);
	 }
	 if(m == n)
		 return way(m, n - 1) + 1;
}

int main()
{
	int i, l, a, m, n;
	cin >> l;
	for(i = 1 ; i <= l ; i++)
	{
		cin >> m >> n;
		a = way(m, n);
		cout << a << endl;
	}

	return 0;
}
int fpg(int m,int n){
	int ff;
	ff=0;
    if((m==1)||(n==1)||(m==0)||(n==0)){
		ff=1;
		return 1;
	}
	else if(m>=n){ff=ff+fpg(m-n,n);
	              ff=ff+fpg(m,n-1);
	}
	else{
             ff=ff+fpg(m,n-1);
			 }
	return ff;
}
int main(){
	int m,i,t,n;
    scanf("%d",&t);
	for(i=0;i<t;i++){
		scanf("%d",&m);
		scanf("%d",&n);
		printf("%d\n",fpg(m,n));
	}
	return 0;
}