semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int a[101]={0};
int n=0,i=0;
char first;
void f()
{
	char c;
	c=getchar();
	if (c!='\n')
	{
		if (i==0)
			first=c;
		if (c==first)
		{
			a[++n]=i++;  //???????????????????????
			f();
		}
		else 
		{
			cout<<a[n--]<<" "<<i++<<endl;   //????????????????????
			f();
		}
	}
}
int main()
{
	f();
	
	return 0;
}
char girl;
int main()
{
	void Match(char queue[], int p);
	char queue[100 + 10];
	cin.getline(queue, 101);
	girl = queue[strlen(queue) - 1];
	Match(queue, 0);
	return 0;
}

void Match(char queue[], int p)
{
	int q = p;
	do
	{q++;} while(queue[q] == 0);
	if (queue[q] == girl)
	{
		cout << p << " " << q << endl;
		queue[p] = 0;
		queue[q] = 0;
		do
		{p --; if (p < 0) break;}
		while(queue[p] == 0);
		if (p >= 0)
			Match(queue, p);
	}
	else Match(queue, q);
}
char a[10000];
int use[10000]={0};
void f(int len)
{
	int i,j;
	for(i=0;i<len;i++)
		if(a[i]==a[len-1]&&use[i]==0)
		{
			for(j=i-1;j>=0;j--)
				if(a[j]==a[0]&&use[j]==0)
				{
					cout<<j<<" "<<i<<endl;
					use[i]=1;
					use[j]=1;
					break;
				}
		}
}
int main()
{
	int len;
	cin>>a;
	len=strlen(a);
	f(len);
	return 0;
}
char b, g, a[100];
int len;

int paidui(int n)
{
	for (int i = n; i < len; i++)
	{
		if (a[i] == '*') continue;
		if (a[i] == b)
		{
			a[i] = '*';
			int k = paidui(i + 1);
			cout << i << ' ' << k << endl;
		}
		else if (a[i] == g)
		{
			a[i] = '*';
			return i;
		}
	}
}

int main()
{
	cin.getline(a, 100);
	len = strlen(a);
	b = a[0];
	g = a[len - 1];
	paidui(0);

	return 0;
}
int u=0;
void prin(char a[],int l)
{
	int i,j;
	for(i=0;i<l;i++)
	{
		if(a[i]=='\0')
			continue;
		for(j=i+1;j<l;j++)
		{
			if(a[j]=='\0')
				continue;
			if(a[j]!=a[i])
			{
				printf("%d %d\n",i,j);
				a[i]='\0';
				a[j]='\0';
				u++;
				break;
			}
			if(a[j]==a[i])
				break;
		}
		if(a[j]!='\0')
			continue;
		if(a[j]=='\0')
			break;
	}
	if(u!=l/2)
		prin(a,l);
}
	



void main()
{
	char a[100];
	int l;
	gets(a);
	l=strlen(a);
	prin(a,l);
}
void f(int x,char a[100])
{
	int s=-1,i=100;
	if(a[x]!=a[0])
	{
		for(i=x-1;i>=0;i--)
		{
			if(a[i]!=a[x])s++;
			else s--;
			if(s==0)
			{
				cout<<i<<" "<<x<<endl;
				break;
			}
		}
	}
	if(i!=0)f(x+1,a);
}
int main()
{
	int x=1;
	char a[100];
	cin>>a;
	f(x,a);
	cin.get();cin.get();cin.get();cin.get();
	return 0;
}
int data(char *c,int i,char boy,char girl){
	if(*(c+i)==0)return 0;
	if(*(c+i)==girl)return i;
	int j;
	j=data(c,i+1,boy,girl);
	cout<<i<<' '<<j<<endl;
	return data(c,j+1,boy,girl);
}
int main(){
	char children[1000],boy,girl;
	int i;
	cin>>children;
	boy=children[0];
	for(i=0;children[i]!=0;i++){
		if(children[i]!=boy){
			girl=children[i];
			break;
		}
	}
	i=data(children,0,boy,girl);
	return 0;
}
char c1, c2;
int num;
int k=0;
int s[1000][2];
int main()
{
    void f(char str[1000]);
	char a[1000];
	gets(a);
    c1=a[0];
	int i, j;

	num=strlen(a);
	for(i=1;i<num;i++)
    {
		if(a[i]!=c1) {c2=a[i];break;}
	}
	f(a);
    int temp1, temp2;
	for(i=0;i<k;i++)
	{
		for(j=0;j<k-1-i;j++)
		{
		    if(s[j][1]>s[j+1][1])
			{
				temp1=s[j+1][1];
				s[j+1][1]=s[j][1];
				s[j][1]=temp1;
	            temp2=s[j+1][0];
				s[j+1][0]=s[j][0];
				s[j][0]=temp2;
			}
		}
	}
	for(i=0;i<k;i++)
	{
		printf("%d %d\n", s[i][0], s[i][1]);
	}
	printf("\n");
	return 0;
}
void f(char str[1000])
{
	int i, j;

	
	num=strlen(str);
	for(i=0;i<num-1;i++)
	{
		
		   if(str[i]==c1 && str[i+1]==c2)
		   {
              s[k][0]=i;s[k++][1]=i+1;
			  str[i]=' ';str[i+1]=' ';
		      
		   }
	       else
		   {
			 for(j=i;j<num-1;j++)
			 {
				 int p, judge=0;
			    if(str[i]==c1 && str[j]==' ' && str[j+1]==c2)  
				{
					for(p=i+1;p<=j;p++)
					{
						if(str[p]==' '){judge=judge+1;}
					    if(judge==j-i)
						{ s[k][0]=i;s[k++][1]=j+1;
			              str[i]=' ';str[j+1]=' ';
				          break;
						}
					}
				}
			 }
			
		   }
	
	}
	
	if(k*2<num)f(str);//zhuyixunhuanjiesudexianzhitiaojian
	
}
int pos;

void match(char lch)
{
    int spos = pos;
    char ch;
    pos++;
    scanf("%c", &ch);
    while (ch == lch)
    {
        match(ch);
        pos++;
        scanf("%c", &ch);
    }
    printf("%d %d\n", spos, pos);
}

int main()
{
    char ch;
    pos = 0;
    scanf("%c", &ch);
    match(ch);
    return 0;
}
int main()
{
	char a[100],p;
	int b[100],c[100];
	int i,j=0,k=0;
	scanf("%s",a);
	p=a[0];
	for(i=0;i<strlen(a);i++){
		if(a[i]==p)
			b[j++]=i;
		else 
		{
			c[k++]=b[j-1];
			c[k++]=i;
			j--;
		}
	}
	for(i=0;i<strlen(a);i++){
		if(!(i%2))
			printf("%d ",c[i]);
		else
			printf("%d\n",c[i]);
	}
	return 0;
}
//*******************************************
//*????????                         *
//*?  ?????                           *
//*?  ??1000012806                       *
//*?????2010.12.31                     *
//*******************************************
void youxi(int);
char boy;                                    //????????????
char paidui[100] = {0};                      //?????????
int main()
{
	cin.getline(paidui, 100);
	boy = paidui[0];                         //??????
	youxi(0);                                //????????
	return 0;
}
void youxi(int num)
{
	if (paidui[num] == 0)                    //?????????????????
		return;
	else
	{
		if (paidui[num] == boy)              //??????????????????
			youxi(num + 1);
		else
		{
			int i;
			for (i = num; i >= 0; i--)       //???????
			{
				if (paidui[i] == boy)
				{
					cout<<i<<' '<<num<<endl; //????????????????????????
					paidui[i] = ' ';
					paidui[num] = ' ';
					break;
				}
			}
			youxi(num + 1);                  //?????
		}
		return;
	}
}
int main()
{
    char str[120], *p;
    p = str;
    int boy[100];
    cin >> str;
    int m = 0, bo = 0;
    while(*p != 0)
    {
        if(*p == str[0])
        {
            bo++;
            boy[bo] = m;
        }
        else
        {
            cout << boy[bo] << " " << m << endl;
            bo--;
        }
        p++;
        m++;
    }
}
int main()
{
	int i,m=0,n;
	char a[105];
	int b[55]={0};
	memset(a,'0',sizeof(a));
	cin>>a;
	for(i=0;i<100;i++)
		if(a[i]=='0')
		{n=i-1;break;}	//????????
	for(i=0;i<n;i++)
	{
		if(a[i]==a[0])
		{	
			b[m]=i;
			m++;		//??????m????????i????????
		}
		else if(a[i]!=a[0])	//??????
		{
			cout<<b[m-1]<<" "<<i<<endl;	//???????????
			m--;	//?????????????
		}
	}
	return 0;
}
void lashou(char [],int ,int );
int main()
{
	int i,sum;
	char nn[101];
	cin.getline(nn,101);
	for(i=1;nn[i]!='\0';i++)
	{
		if(nn[i]==nn[0]) continue;
		else
		{
			sum=nn[0]+nn[i];
		}
	}
	i--;
	lashou(nn,i,sum);
	return 0;
}
void lashou(char shou[],int n,int sum)
{
	int i,j,k,zhi;
	for(i=0;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			if((shou[i]+shou[j])==sum)
			{
				zhi=0;
				for(k=i+1;k<=j-1;k++)
				{
					if(shou[k]!=0) zhi=1;
				}
				if(zhi==0)
				{
				cout<<i<<" "<<j<<endl;
				shou[i]=shou[j]=0;
				lashou(shou,n,sum);
				break;
				}
			}
		}
	}
}
int cont=1;        //???????????????????? 
char a[100];
char x,y;
int main()
{
    int i;
    int out(int len); 
    int len;       //a??? 
    cin.getline(a,100);
    len=strlen(a);
    x=a[0];
    for(i=1;i<len;i++)
        if(a[i]!=x)break;
    y=a[i];
    out(len);
    return 0;
}

int out(int len)
{
    if(len==cont*2){cout<<0<<" "<<len-1;return 1;}  //?????????????? 
    int i,j;
    for(i=1;i<len-2;i++)  //????? 
            {if(a[i]==x&&a[i+1]==y)
                    {cout<<i<<" "<<i+1<<endl;  //??????????? 
                     a[i]=0;a[i+1]=0;                                    //a?i??a?i+1????? 
                     cont++;
                     break;}           //?????? 
             if(a[i]==x&&a[i+1]==0)         //????0 0 0??? 
                    {for(j=i+1;j<len-1;j++)     //?a?j???a?i???????0??? 
                            if(a[j]!=0)break;
                     if(a[j]==y){cout<<i<<" "<<j<<endl;
                                   a[i]=0;a[j]=0;
                                   cont++;break;}
                     }
             }                 
    out(len);     //???????????? 
}
int main()
{
  int  i,j,k;
  char s[102];
  gets(s);
   for(i=1;i<strlen(s);i++)
     {
       if(s[i]!=s[0])
           {
             for(j=i-1;j>=0;j--)
               {
                 if(s[j]!=s[i])
                    {
                      s[j]=s[i];
                      printf("%d %d\n",j,i);
                       break;
                     }
                }
             } 
       }
return 0;
}
void zhaodui(char str[]);
int main()
{
	char str[100];
	cin.getline(str,100,'\n');
	zhaodui(str);
	return 0;
}
void zhaodui(char str[])
{
	char nan[2],nv[2];
	char str1[100];
	int i,j;
	strcpy(str1,str);
	nan[0]=str[0];
	for(i=0;i<99;i++)
	{
		if(str[i]!=str[0])
		{
			nv[0]=str[i];
			break;
		}
	}
	for(j=0;j<99;j++)
	{
		for(i=1;i<98;i=i+2)
		{
			if(str[j]==nv[0]&&str[j-i]==nan[0])
			{
				cout<<j-i<<" "<<j<<endl;
				str[j]='\0';
				str[j-i]='\0';
			}
		}
	}
}
void move(char c[],int a[], int pos, int n);
void f(char c[],int n, int a[]);
int main()
{
	char c[100];
	int  i, n, a[100] = {0};
	cin >> c;
	n = strlen(c);
	for(i = 0;i < n;i++)
		a[i] = i;
	f(c,n,a);
	return 0;
}
void move(char c[], int a[], int pos, int n)
{
	int i;
	for(i = pos;i < n - 2;i++)
	{
		c[i] = c[i+2];
		a[i] = a[i+2];
	}
}
void f(char c[],int n,int a[])
{
	int i = 0;
	for(i = 0;i < n;i++)
		if(c[i] == c[0] && c[i+1] == c[n-1])
		{
			cout << a[i] <<' '<< a[i+1] <<endl;
			move(c,a,i,n);
			f(c,n-2,a);
			break;
		}
}
void out(char s[],int a[],char boy,int len)
{   
	int i,k;
	if(len==2)
		cout<<a[0]<<' '<<a[1]<<endl;
	else
	{
		for(i=0;i<len-1;i++)
			if(s[i]==boy&&s[i+1]!=boy)
			{
				cout<<a[i]<<' '<<a[i+1]<<endl;
				for(k=i;k<len-2;k++)
				{
					s[k]=s[k+2];
				    a[k]=a[k+2];
				}
				out(s,a,boy,len-2);
				break;
			}
	}
	return;
}
int main(){
	char s[100];
	cin>>s;
	int a[100],i;
	int len=strlen(s);
	for(i=0;i<100;i++)
		a[i]=i;
	char boy=s[0];
	out(s,a,boy,len);
    return 0;
}
int main()
{
    int i,j,k,n,b[100];
    char a[100],l;
    cin.getline(a,100);
    n = strlen(a);
    l = a[0];
    for(i=0;i<n;i++)
        b[i] = i;
        for(i=0;;i++){
        for(j=0;j<n-1;j++)
        {
            if(a[j]==l&&a[j+1]!=l){
                cout << b[j] << " " << b[j+1] <<endl;
               for(k=j+2;k<n;k++)
               {
                   b[j] = b[k];
                   a[j] = a[k];
                   j++;
               }
               n = n-2;
               break;
        }
        }
        if(n==0)
            break;

    }
}
char line[101];
void main()
{
	int i,j;
	scanf("%s",line);
	char boy=line[0];
	for(i=1;i<strlen(line);i++)
	{
		if(line[i]==boy)
			continue;
		else if(line[i]!=' ')
		{
			for(j=i-1;j>=0;j--)
			{
				if(line[j]==boy)
				{
					printf("%d %d\n",j,i);
					line[j]=line[i]=' ';
					break;
				}
			}
		}
	}
}
int flag[101]={0};
char str[101],boy,girl,num=0;
void match(int i)
{
	flag[i]=1;
	for(int k=i;;k--)
		{
			if(str[k]==boy&&flag[k]==0)
			{
			   cout<<k<<' '<<i<<endl;
			   flag[k]=1;
			   break;
			}
		}
	num=num+2;
	if(num==strlen(str))return;
		for(++i;;i++)
		{
			if(str[i]==girl)
				{
					match(i);
					break;
			}

		}
	return;
}
		

int main()
{
	cin>>str;
	boy=str[0];
	int i;
	char *p=str;
	for(i=0;;p++,i++)                //i--first girl
	{
		if(*p!=boy)
			{
				girl=*p;
		        break;
		    }
	}
	match(i);
	return 0;
}
int main()
{
	char line[110],boy,girl;
	int b[110],g[110],p=1,s=0,lin[110],mark[110];
	int len;
	for(int i=0;i<=109;i++)
		lin[i]=i;
	cin.getline(line,120,'\n');
	len=strlen(line)-1;
	boy=line[0];
	for(int i=0;i<=len;i++)
		if(line[i]!=boy)
		{
			girl=line[i];
			break;
		}
	while(s<len+1)
	{
		for(int i=0;i<=len-1;i++)
		{
			if(line[i]==boy&&line[i+1]==girl)
			{
				b[p]=lin[i];
				g[p]=lin[i+1];
				p++;
				for(int j=i+2;j<=len;j++)
				{
					line[j-2]=line[j];
					lin[j-2]=lin[j];
				}
				s=s+2;
			}
		}
	}
	for(int i=1;i<=p-2;i++)
		for(int j=1;j<=p-1-i;j++)
			if(g[j]>g[j+1])
			{
				int temp=g[j];
				g[j]=g[j+1];
				g[j+1]=temp;
				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
			}
	for(int i=1;i<=p-1;i++)
		cout<<b[i]<<" "<<g[i]<<endl;
	return 0;
}
int main()
{
	int stack[5000],top=0,i=0;
	char d;
	char a='X',b='X';
	while ((d=cin.get())!='\n')
	{
		if (a=='X') a=d;
		if (a!=d&&b=='X') b=d;
		if (d==a)
		{
			top++;
			stack[top]=i;
		}
		if (d==b)
		{
			cout<<stack[top]<<' '<<i<<endl;
			top--;
		}
		i++;
	}
	return 0;
}
int main()
{
	char s[101];gets(s);
	struct kid
	{
		char c;
		int num;
	}kid[100];
	int n;
	n=strlen(s);
	int i,j;
	for(i=0;i<n;i++)
	{
		kid[i].c=s[i];
	}
	for(i=0;i<n;i++)
	{
		kid[i].num=i;
	}
	
	for(i=0;i<n-1;i++)
	{
        if(kid[i].c!=kid[i+1].c)
		{
			printf("%d %d\n",kid[i].num,kid[i+1].num);
			
			for(j=i;j<n-2;j++)
			{kid[j]=kid[j+2];}
			n-=2;
			i=-1;
			
		}
      
	}

return 0;    


}
void f(int,char[],char,char);
int tag[100]={0};
int main()
{
	char a[100];
	cin.getline(a,100);
	int l,p;
	l=strlen(a);
	char boy,girl;
	boy=a[0];
	for(int i=0;i<l;i++)
	{
		if(a[i]!=boy)
		{
			girl=a[i];
			p=i;
			break;
		}
	}
	f(p,a,boy,girl);
	return 0;
}
void f(int p,char b[100],char m,char fe)
{
	if(b[p]=='\0') return;
	if(b[p]!=fe) f(p+1,b,m,fe);
	else
	{
		for(int i=p-1;i>=0;i--)
		{
			if(tag[i]==0)
			{
				cout<<i<<" "<<p<<endl;
				tag[i]=1;
				tag[p]=1;
				break;
			}
		}
		f(p+1,b,m,fe);
	}
}
/*
			? ? ??????
			?????20110102
			?    ?????
			?????????????????
**/
void check(int *a);
int g_lenth;
int main()
{
	char a[101];
	int b[100];
	cin.getline(a, 101);
	g_lenth = strlen(a);
	for(int i = 0; i < g_lenth; i++)
	{
		if(a[i] == a[0])
			b[i] = 1;
		else
			b[i] = 2;
	}
	check(b);
	return 0;
}
void check(int *a)
{
	for(int i = 0; i < g_lenth; i++)
		if(a[i] == 2)
			for(int j = i - 1; j >= 0; j--)
				if(a[j] == 1)
				{
					cout << j << ' ' << i << endl;
					a[i] = 0;
					a[j] = 0;
					return check(a);
				}
}
void Q(char a[])
{
	char c;
	c = a[0];
	int pos[100];
	int i = 0, num = 0;
	do
	{
		if (a[i] == c)
		{
			num++;
			pos[num] = i;
		}
		else
		{
			cout << pos[num] << " " << i << endl;
			num--;
		}
		i++;
	}while (i <= strlen(a) - 1);
}
int main()
{
	char children[100];
	cin >> children;
	Q(children);
	return 0;
}
void line(char a[100],int b)
{
	int i,j;
	for(i=0;i<b;i++)
	{
		if(a[i]!=a[0])
		{
			for(j=i;j>=0;j--)
			{
				if(a[j]!=a[i]&&a[j]==a[0])
				{
					cout<<j<<' '<<i<<endl;
					a[j]=a[i]=0;break;
				}
				
			}}
		
	}}




int main()
{
	char a[100];
	cin>>a;
	int n;
	n=strlen(a);
	line (a,n);
	return 0;
}
int main(){
	char x[110], a, b;
	int i, j;
	cin.getline(x, 110, '\n');
	a = x[0];
	for(i = 1;;i++){
		if(x[i] != a){
			b = x[i];
			break;
		}
	}
	for(i = 0;i < strlen(x);i++){
		if(x[i] == b)
		{
			for(j = i - 1;;j--)
				if(x[j] == a)
					break;
			cout << j << " " << i << endl;
			x[j] = x[i] = ' ';
		}
	}
	return 0;
}
/*bss*/
int stack[MAX], lstack, len;

int main(){
    char c, a=0, b=0;
    int i, j, k;
    while(c=getchar()){
        if(!a) a=c;
        else if (c!=a&&!b) b=c;
        if(c==a) stack[lstack++]=len++;
        else if(c==b) printf("%d %d\n", stack[--lstack], len++);
        else return 0;
    }
}
//**********************************************************
//*   ?  ?   ?: ????.cpp                            *
//*   ?       ?: ? ?                                   *
//*   ? ? ? ?: 2010?12?6?                           *
//**********************************************************
int main ()
{
	char a[101]={'\0'};                          //??????????
	int i=1,j=0;
	cin.getline( a, 101, '\n');
	while((i<101)&&(a[i]!='\0'))                 //?????
	{
		if(a[i]==a[0])                          //?????????????????????
		{
			i++;
			continue;
		}
		else if(a[i]!=a[0])                     //????????????
		{
			for(j=i-1;j>=0;j--)
			{
				if(a[j]!=a[0])                  //?????????????
					continue;
				else if(a[j]==a[0])             //????????????????????
				{
					cout<<j<<" "<<i<<endl;
					a[i]='0';
					a[j]='0';
					break;
				}
			}
		}
		i++;
	}
	return 0;
}
int main()
{
    char a[110]={0};
    int i,j,p=0;
    int b[110]={0};
    cin.get(a,110,'\n');
    for(i=0;i<=109;i++)
    {
                       if(a[i]>0)
                       p++;
    }
    for(i=1;i<=p-1;i++)
    {
                     if(a[i]==a[0]) continue;
                     else 
                     {
                          j=i-1;
                          while(j>=0)
                          {
                                     if(b[j]==0) break;
                                     else 
                                     j--;
                          }        
                          cout<<j<<" "<<i<<endl;
                          b[j]=1,b[i]=1;
                     }
    }
    return 0;
}
char c[100];
int match(int x)
{
	
	int q;
	if(c[x]==c[0])
	{
		q=match(x+1);
		cout<<x<<' '<<q<<endl;
		return match(q+1);
	}
	else
		return x;
}
int main()
{
	
	cin.getline(c,100);
	match(0);
	return 0;
}
char pos[100];
int po[100] = { 0 };
int len;
char a, b;
void ty(int );
int main()
{
	int i;
	cin.getline( pos, 100);
	a = pos[0];
	len = strlen (pos);
	b = pos[strlen(pos) - 1];
	for( i = 0; i < len; i ++)
	{
		if( pos[i] == a)
			po[i] = 1;
		else
			po[i] = 2;
	}
	ty( 0 );
	
	return 0;
}
void ty ( int i)
{
	int j = 0;
	if( i == len - 1)
	{
		cout << 0 << " " << i << endl;
		return ;
	}
	else
	{if( po[i] == 2)
		{
		for( j = i - 1; j > 0; j -- )
		{
			if( po[j] == 1)
				break;
		}
			
			cout << j << " " << i << endl;
			po[j] = 0;
			po[i] = 0;
		}
	
	ty( i + 1 );
	}
}
char str[200],u,v;
int n,t[100][2];
void disassemble(int x)//n????n??????????????????????????
{
	int i,m=0;
	for(i=0;i<2*n;i++)
	{
		if(str[i]==v)
		{
			m=i;
			t[x][1]=m;//x=1?????????????????????
			str[m]=1;//?????0,0???????????????????
			break;
		}
	}
	for(i=m-1;i>=0;i--)
	{
		if(str[i]==u)
		{
			t[x][0]=i;
			str[i]=1;
			break;
		}
	}
	if(x!=1)
		disassemble(x-1);
	cout<<t[n+1-x][0]<<' '<<t[n+1-x][1]<<endl;
}
int main()
{
	cin.getline(str,200,'\n');
	int i;
	for(i=0;str[i]!='\0';i++);
	n=i/2;
	u=str[0];
	v=str[i-1];
	disassemble(n);
	return 0;
}
int main()
{
	char a[100],b,c;
	cin.getline(a,100);//?????
	b=a[0];//????????b?????
	int i,j,l;
	l=strlen(a);
	for(i=1;i<l;i++)
		if(a[i]!=a[0]){c=a[i];break;}//?????a[0]?????c?????
	for(i=0;i<l;i++)
	{
		if(a[i]==c)//??a[i]???
		{
			a[i]='0';//?a[i]??0
			for(j=i;j>=0;j--)
			{
				if(a[j]==b)//?i??????????
				{
					cout<<j<<" "<<i<<endl;//??j i
					a[j]='0';//?a[j]??0
					break;//??????
				}
			}
		}
	}
	return 0;
}
char queen[1000];
int main()
{
	cin >> queen;
	int len = strlen(queen);
	char a, b;
	int cnt = 0;
	int boy[1000] = {0};
	a = queen[0];
	b = queen[len - 1];
	for (int i = 0; i < len; i++)
	{
		if (queen[i] == a)
		{
			boy[cnt] = i;
			cnt ++;
		}
		if (queen[i] == b)
		{
			cnt --;
			cout << boy[cnt] << ' ' << i << endl;
		}
	}
	while(EOF!=getchar());
	return 0;
}
/*
 * paiduiyouxi.cpp
 *
 *  Created on: 2010-12-30
 *      Author: qaj
 */
int main() {
	char ch[20000];
	cin >> ch;
	int l = strlen(ch);
	int num[20000];
	for (int i = 0; i < l; i++)
		num[i] = i;
	int n = l;
	char boy, girl;
	boy = ch[0];
	for (int i = 1; i < l; i++) {
		if (ch[i] != boy) {
			girl = ch[i];
			break;
		}
	}
	for (int k = 0; k < l / 2; k++)
		for (int i = 0; i < n; i++) {
			if ((ch[i] == boy) && (ch[i + 1] == girl) || (ch[i] == girl)
					&& (ch[i + 1] == boy)) {
				cout << num[i] << ' ' << num[i + 1] << endl;
				n = n - 2;
				for (int j = i; j < n; j++) {
					ch[j] = ch[j + 2];
					num[j] = num[j + 2];
				}
				break;
			}
		}
	return 0;
}
/* Name      : ???? 
 * Version   : 1.0
 * Date      : 2012-11-19
 * New       : Null
 * Func&Feat : 
 * State     : Work
 */
int main()
{
    char c,boy=0;                                //???c?????????boy???????? 
    int n_person,n_pair;                         //???n_person?????n_pair????? 
    int sym[100]={0},pair[50][2]={0};            //???sym[]??????????????1????-1?pair[][2]????? 
    for(int i=0;i<100;i++)
    {
        c=cin.get();
        if(i==1)boy=c;                           //???????????boy?????????? 
        if(c=='\n')
        {
            n_person=i;
            n_pair=n_person/2;
            break;
        }
        if(c==boy)sym[i]=1;                      //???boy???sym[]???1??????-1 
        else sym[i]=-1;
    }
    for(int i0=n_person-1,p=n_pair-1;i0>=0;i0--) //???????????????? 
        if(sym[i0]==-1)                          //??????????????????????????????????0 
        {
            pair[p][1]=i0;                       //?????? 
            for(int i1=i0,sum=0;i1>=0;i1--)
            {
                sum=sum+sym[i1];
                if(sum==0)                       //????????0????????????? 
                {
                    pair[p][0]=i1;
                    break;
                }
            }
            p--;                                 //pair[]??????p?n_pair-1???0 
        }
    for(int p=0;p<n_pair;p++)cout<<pair[p][0]<<' '<<pair[p][1]<<endl;
    return 0;
}
int leave(int a);

	char str[101];
		int i = 1;

int main()
{

	cin.getline(str, 101);
	leave(0);
	return 0;
}
int leave(int a)
{
	int b;

	if (str[a] == str[0])
	{
		b = leave(a + 1);
		cout << a << " " << b << endl;
		return leave(b + 1);
	}
	else
		return a;
}
void ou(char x[], int n,char c, char d)
{

	int i,j;
	
	for(i=0;i<n;i++)
	{
		if(x[i]==d)
		{
			for(j=i-1;j>=0;j--)
			{
				if(x[j]==c)
				{
					printf("%d %d\n",j,i);
					x[i]='4';
					x[j]='4';
					break;
				}
			}
			break;
		}
	}
	for(i=0;i<n;i++)
	{
		if(x[i]!='4')
		{
			ou(x,n,c,d);
		}
	}
}
int main()
{
	int i,n;
	char x[1000],c,d;
	scanf("%s",x);
	c=x[0];
	n=strlen(x);
	for(i=0;i<n-1;i++)
	{	if(x[i]!=c)
		{
			d=x[i];
		}
	}

	ou(x,n,c,d);
	return 0;

}
char a[101], boy, girl;
int f(int n);
int main()
{
	int i;
	cin.getline(a, 101);
	boy = a[0];
	for (i = 0; a[i] != '\0'; i++)
		girl = a[i];
	f(0);
	return 0;
}
int f(int n)
{
	int i;
	for (i = n; a[i] != '\0'; i++)
	{
		if (a[i] == boy)
		{
			a[i] = '0';
			cout << i << " " << f(i + 1) << endl;
		}
		else if (a[i] == girl)
		{
			a[i] = '1';
			return i;
		}
	}
}
int i = 0,len;
char str[100];
char a;
void P(int d)
{
    while(i < len)
    {
        if (str[i] == a) P(i++);
        else
        {
            cout << d << " " << i << endl;
            i++;
            return;
        }
    }
}

int main()
{
    cin>>str;
    a=str[0];
    len =strlen(str);
    P(0);
    return 0;
}
char line[100];
char boy,girl;
int len;
void queue(int b)
{
	
	int i=0;
	if(b==len)
		return;
	else
	{
		if(line[b]==girl)
		{
			line[b] = 0;
			for( i=b-1;i>=0;i--)
			{
				if(line[i]==boy)
				{
					cout << i << " " << b << endl;
					line[i]=0;
					break;
				}
			}
	        queue(b+1);
		}
		else
		    queue(b+1);
	}
}
int main()
{
	cin >> line;
    len =strlen(line); 
    boy=line[0];
	girl = line[len-1];
	queue(1);
	return 0;
}
void solve(char str[],char m,char f)
{
	int l,flag=1,i,k;
	l=strlen(str);
	for(i=0;i<l;i++)
	{
		if(str[i]==m||str[i]==f)
		{
			flag=0;
			break;
		}
	}
	if(flag) return;
	for(i=0;i<l;i++)
	{
		if(flag==1&&str[i]==f) 
		{
			cout<<k<<" "<<i<<endl;
			flag=0;
			str[k]=' ';
			str[i]=' ';
			break;
		}
		if(str[i]==m) 
		{
			flag=1;
			k=i;
		}
		if(str[i]==f) flag=0;
	}
	solve(str,m,f);
}
int main()
{
	char str[100],m,f,*p;
	cin.getline(str,100,'\n');
	m=str[0];
	for(p=str;p<str+strlen(str);p++)
	{
		if(*p!=m)
		{
			f=*p;
			break;
		}
	}
	solve(str,m,f);
	return 0;
}
int main(int argc, char* argv[])
{
	char p[101]={'\0'},temp,a,b;
	int i=0,j;
	scanf("%s",p);
	while (p[i]!='\0')
	{
		if (i==0)
		{
			i++;
			continue;
		}
		if (p[i-1]==p[i])
		{
			a=p[i-1];
		}
		else 
		{
			a=p[i-1];
			b=p[i];
			if (a>b)
			{
				temp=a+1;
			}
			else
			{
				temp=b+1;
			}
			break;
		}
		i++;
	}
	i=0;
	while (p[i]!='\0')
	{
		if (p[i]==b)
		{
			for (j=i-1;j>=0;j--)
			{
				if (p[j]==a)
				{
					printf("%d %d\n",j,i);
					p[j]=temp;
					break;
				}
				
			}
		}
		i++;
	}
	return 0;
}
void main()
{int i,j,k,len;
 char x[100],a,b;
 scanf("%s", x);
 len=strlen(x);
 a=x[0];b=x[len-1];
 for (i=0;i<len/2;i++)
   {for (j=0;j<len;j++)
        if (x[j]==b)
			{for (k=j-1;x[k]!=a;k--);
             printf("%d %d\n",k,j);
			 x[j]='.';
			 x[k]='.';
			 break;
		    }    
   }
 
}
int main()
{
	int i,j,n,k;
	char s[102];
	gets(s);
	for(i=1;s[i]!='\0';i++)
	{
		if(s[i]!=s[0])
		{
			for(j=i-1;j>=0;j--)
			{
				if(s[j]==s[0])
				{
					s[j]=s[i];
					printf("%d %d\n",j,i);
					break;
				}
			}
		}
		
	}

	return 0;
}