semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
/*
  Name:????  
  Copyright: 
  Author: 
  Date: 18/11/12 14:53
  Description: ???????????????????????????????????????????????????
  ???????????????????????0?????????????????????????????????
  ????????????????????????????????????????????????????????
  ????????????????????????????????????????????????????????
  ????????????????????????????????????????????????????????
  ?????????????????????????????????
*/
int main()
{
    char child[110]={'\0'};
    int  ch[110]={0},dou[110][2]={0};
    int m=0,i,count=0,j=0;
    while(cin>>child[m])//?? 
    {
       if(cin.peek()=='\n')
          break;
       m++;                    
    } 

    for(i=0;i<=m;i++)//???????? 
    {
       if(child[i]==child[0])
           ch[i]=1;
       else
           ch[i]=2;                 
    } 
 
     int p;
        for(i=0;i<m;i++)//???? 
        {
           if(ch[i]==1&&ch[i+1]==2)
           {
              dou[j][0]=i;
              dou[j][1]=i+1;
              j++;
              ch[i]=0;
              ch[i+1]=0;                      
           }                 
        }
        
     int t;
      for(p=0;p<=m/2;p++)//???? 
      {
        for(i=0;i<m;i++)
           for(t=1;t<m-i+1;t++)
           {
              if(ch[i]==1)
              {
                 if(ch[i+t]==0)
                    continue;
                 else if(ch[i+t]==1)
                    break;
                 else
                 {
                      dou[j][0]=i;
                      dou[j][1]=i+t;
                    
                      j++;
                      ch[i]=0;
                      ch[i+t]=0;
                         
                 }              
              }        
           }
           if(dou[m/2][1]!=0)
           break;
        }
   for(j=0;j<=m/2;j++)
      for(i=0;i<=m/2-j-1;i++)//???? 
      {
         if(dou[i][1]>dou[i+1][1])
         {
            p=dou[i][0];
            dou[i][0]=dou[i+1][0];
            dou[i+1][0]=p;
            p=dou[i][1];
            dou[i][1]=dou[i+1][1];
            dou[i+1][1]=p;                         
         }                     
      }
      for(j=0;j<=m/2;j++)
      if(dou[j][1]!=0) 
       cout<<dou[j][0]<<' '<<dou[j][1]<<endl;
   
    return 0; 
}
//****************************************
//*????????                     **
//*????? 1100012762                **
//*???2011.11.22                     **
//****************************************
int flag = 0;
char str[200], ch;
void f(int i, int j)
{
	if (flag == 1)
	{
		return;
	}
	if (i < 0)
	{
		f(j, j + 1);
	}
	if (str[i] == str[0])
	{
		if (str[j] == ch)
		{
			cout << i << " " << j << endl;
			if (str[j + 1] == '\0')
			{
				flag = 1;
			}
			str[i] = str[j] = ' ';
			f(i - 1, j + 1);
		}
		else
		{
			f(j, j + 1);
		}
	}
	else
	{
		f(i - 1, j);
	}
}
int main()
{
	int i, a = 0;
	cin >> str;
	for (i = 0; str[i] != '\0'; i++)
	{
		if (str[i] != str[0])
		{
			ch = str[i];
			f (i - 1, i);
			return 0;
		}
	}
}
char b, g;	char str[110];
int match(int p);
int main()
{
	// ?????? ????????????????????????
	// ??????????? ?????????
	// ?????????? ???????????????????????
	// ??????????
	// ?????????????? ????????????????
	int i, j, len;

	cin >> str;
	len = strlen(str);
	b = str[0];
	g = str[len - 1];
	match(0);
	return 0;
}
int match(int p)  // match(p) ????????? ?????? ??p ?????????p????????
{
	int q;
	if (str[p] == b)  // ????????? ????????????????????
	{ 
		q = match(p + 1); // ??????
		cout << p << " " << q << endl;
		return match(q + 1); // ????? ??????????????????
	}
	else
	{
		return p;
	}
}
char Dat[maxn];
int n,Stac[maxn],Top;
int main() {
scanf("%s",&Dat);
n = strlen(Dat);
Top = 0;
for (int i = 0; i < n; i++)
    if (Dat[i] == Dat[0])
	Stac[++Top] = i;
    else
	printf("%d %d\n",Stac[Top--],i);
}
void f(char a[],int n,char x,char y)
{
     int i,j,k=1;
     for(i=0;i<n;i++)
     {           
        if(a[i]==y)
            for(j=i;j>=0;j--)
                if(a[j]==x)
                {
                      printf("%d %d",j,i);
                      a[i]=0;
                      a[j]=0;
                      k+=2;
                      if(k<n) printf("\n\n");
                      break;
                }
     }
}


int main()
{ 
     char a[100],x,y;
     int i,n;
     gets(a);
     n=strlen(a);
     x=a[0];
     for(i=0;i<n;i++)
        if(a[i]!=x)  y=a[i];
     f(a,n,x,y);
     
}
void hand();                              //????                                 
char sex[2],team[100];                    
int main()
{
	int i;
	cin>>team;
	sex[0]=team[0];                        //???????????
	for(i=0;i<100;i++)
	{
		if(team[i]!=team[0] && team[i]!='\0')//?????????
			sex[1]=team[i];
		else if(team[i]=='\0')
			break;
	}
	hand();                               //????
	return 0;
}
void hand()
{
	int i,j,judge;
	if(team[0]==sex[0])                 //?????????????????
	{
		judge=0;
		for(i=0;i<100;i++)       
		{
			if(team[i]==sex[1])         //???????
			{
				for(j=1;j<100;j++)
				{
					if(team[i-j]==sex[0])//????????
					{
						judge=1;
						break;
					}
				}
				if(judge==1)
					break;
			}
		}
		cout<<i-j<<" "<<i<<endl;
		team[i]='\0';                   //?????????
		team[i-j]='\0';
		hand();
	}
}
int f[100];

//???????????????????????? ?????k??
void sort(char str[], int f[], int l, int k, char m)
{
	if(k == l) return;//????????????
	int i;
	if(str[k] != m && f[k] == 1)
	{
		//???????????
		for(i = k - 1; i >= 0; i--)//????????????????
			if(str[i] == m && f[i] == 1)
			{
				cout << i << " " << k << endl;//?????????????????????????
				f[i] = 0; 
				f[k] = 0;
				break;
			}
	}
	sort(str, f, l, k + 1, m);//??????
}
int main()
{

	char str[101], m;
	
	
	int l, i = 0, k;
	cin.getline(str,101);
	l = strlen(str);
	m = str[0];
	for(i = 0; i < l; i++)
		f[i] = 1;
	i = 0;
	while(str[i] == m) i++;
	k = i;// ???????	
	sort(str, f, l, k, m);//?????????	
	return 0;
}
int main ()
{
    char a[100];
    int d[100]={0},n;
    char b,c;
    for (int i=0;i<100;i++)
    {
        a[i]=getchar();
        if (a[i]=='\n')
        {
           n=i;
           break;
        }
        b=a[0];
        if (a[i]!=b)
        c=a[i];
    }
    for (int i=1;i<=n/2;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (a[j]==b||d[j]==1)
            continue;
            for (int k=j;k>=0;k--)
            {
                if (a[k]==c||d[k]==1)
                continue;
                cout <<k<<" "<<j<<endl;
                d[j]=1;
                d[k]=1;
                break;
            }
        }
    }
    return 0;
}
int sum1 = 0, sum2 = 0;
void cal(char a[], int k, char ch)
{
	int i,j;
	int longth = strlen(a);
	for(i = k;;i++)
	{
		if(a[i] != ch && a[i] != '0')
		{
			a[i] = '0';
			for(j = i - 1; ; j--)
			{
				if(a[j] == ch && a[j] != '0')
				{
					a[j] = '0';
					cout << j << ' ' << i << endl;
					break;
				}
			}
			break;
		}
	}
	if(i == longth - 1)
	return;
	else cal(a,i+1,ch);
}
int main()
{
	char a[200];
	cin >> a;
	char ch = a[0];
	cal(a, 0, ch);
	return 0;
}
/*
 * file    homework 14_2
 * author  ??
 * date    2010-1-1
 * description
           ???????????
*/



int Match(int n, char a[], char boy, char girl);

int main()
{
	int len;
	char a[100];
	char boy, girl;
	cin >> a;
	len = strlen(a);
	boy = a[0];
	girl = a[len - 1];
    Match(0, a, boy, girl);

	return 0;
}


int Match(int n, char a[], char boy, char girl)
{
	int m;
	if(a[n] == girl)
		return n;
	m = Match(n + 1, a, boy, girl);
	cout << n << " " << m << endl;
	if (a[m + 1] != '\0')
		return Match(m + 1, a, boy, girl);
	else
		return 0;

}
int main(int argc, char* argv[])
{
	char s[10000];
	char a,b;
	int n;
	
	gets(s);
	n=strlen(s);
	a=s[0];
	b=s[n-1];
	int i;
	for(i=1;i<n;i++)
	{
		if(s[i]==b)
		{
			int j;
			int first=0;
			for(j=i-1;j>=0;j--)
			{
				if(s[j]==a&&first==0)
				{
					printf("%d %d\n",j,i);
						first=1;
						s[i]=' ';
						s[j]=' ';
				}
			}
		
		}
		
	}
	

	return 0;
}
/*********************????******************
??
???????????????????????????????
???????????????????????????????
????????????0???????????????????
???????????????????????????????
????????????????????????????????
????????????????????????????????
???????????????????????????.
????????????????????????????????
???????????????????????????????
?????????????????????????????
????
???????????????????????????????
???????????????????????????????
????????100
????
???????????????????????????????
?????????????????????
????
((()(())())(()))
????
2 3
5 6
4 7
8 9
1 10
12 13
11 14
0 15
**********************************************************
programmer Qiu Hezi
version 2.0(??)
creat date 2012.11.20 22:19
**********************************************************/
/*??????n???????n????????????
????????????1???4????2?3???????????*/
char boy;
int first=0;
int fun (int n)
{
    char temp;
    temp = cin.get();//cin.get(temp);//????n???
    if (first==0)
    {
        boy=temp;
        first=1;
    }
    if (temp== boy )
    {
        int num=fun(n+1);
        cout<<n<<" "<<num<<endl;//????????????
        return fun(num+1);//???????
    }
    else
        return (n);
}
int main()
{
    fun(0);
    return 0;
}
char mf[100];
int j=1;  //?????? 
int i=100;  //?? ???? 
void paixu(int n)   //????? 
{
    if(i==0)   //?????????? 
    {
        cin.eof();
    }
    else  //?????? 
    {
        if(mf[j]!=mf[0])
        {
          for(i=j-1;i>=0;i--)
          {
             if(mf[i]==mf[0])
             {
                cout<<i<<" "<<j<<endl;
                mf[i]=0;
                mf[j]=0;
                break;
             }
          }
        }
        j=j+1;
        paixu(j);
    }
    
}
int main()
{ 
    for(int k=0;k<100;k++)  //?? 
    {
        mf[k]=0;
    }
    cin.getline(mf,100);  //????? 
    paixu(1);
    return 0;
}
int main()
{
	char man,a[200];
	int len,i,j,k,w[200],m[200],p=0;
	scanf("%s",a);
	len=strlen(a);
	man=a[0];
hell:;
	for(i=0;i<=len-1;i++)
	{
		if(a[i]==man)
		{
			for(j=i+1;j<=len-1;j++)
			{
				if(a[j]==man)
				{
					break;
				}
				if(a[j]!=man&&a[j]!=1)
				{
					a[i]=1;a[j]=1;
					m[++p]=i;w[p]=j;
					goto hell;
				}
			}
		}
	}
	for(k=1;k<=p;k++)
	{
		printf("%d %d\n",m[k],w[k]);
	}

}
int main()
{
	void match(char str[100],int b,int k,int bg[50][2]);
	char str[100];
	int bg[50][2];
	int i,j,total,len,temp;

	cin.getline(str,101,'\n');
	len=strlen(str);
	total=len/2;

	match(str,0,0,bg);
	
	for (i=1;i<total;i++)
		for (j=0;j<total-i;j++)
			if ( bg[j][1]>bg[j+1][1] )
			{
				temp=bg[j][1];
				bg[j][1]=bg[j+1][1];
				bg[j+1][1]=temp;

				temp=bg[j][0];
				bg[j][0]=bg[j+1][0];
				bg[j+1][0]=temp;
			}

	for (i=0;i<total;i++)
		cout << bg[i][0] << " " << bg[i][1] << endl;

	return 0;
}


void match(char str[100],int b,int k,int bg[50][2])
{
	char ch=str[0];
	int i,len=strlen(str);
	int m=1;					// m flags the match case of str[b]


	if (str[b]==ch)
	{
		for (i=b+1;i<len;i++)
		{
			if ( str[i]==ch )
				m++;
			else 
				m--;
			if (m==0)
			{
				bg[k][0]=b;
				bg[k][1]=i;
				k++;
				break;
			}
		}
	}
	
	b++;

	if (b!=len)
		match(str,b,k,bg);

}
int main()
{
    int a[100]={0};
    char c;
    cin>>c;
    a[0]=1;
    for(int i=1;i<100;i++)
    {
        char b;
        cin>>b;
        if(b==c)
        a[i]=1;
        else
        a[i]=-1;
    }
    for(int j=0;j<100;j++)
    {
        if(a[j]==-1)
        {
            for(int k=j-1;k>=0;k--)
            {
                if(a[k]==1)
                {
                cout<<k<<" "<<j<<endl;
                a[k]=0;
                a[j]=0;
                break;
                }
            }
        }
    }
    
    return 0;
}
int main(){
	char a[100];
	cin>>a;
	for(int i=0;i<strlen(a)-1;i++){
		if(a[i]==' ')continue;
		else if(a[i+1]==' '){
			int j;
			for(j=1;a[i+j]==' ';j++){}
			if(a[i]!=a[i+j]){
				cout<<i<<' '<<i+j<<endl;
				a[i]=' ';
				a[i+j]=' ';
				i=0;
			}
		}
		else if(a[i]!=a[i+1]){
			cout<<i<<' '<<i+1<<endl;
			a[i]=' ';
			a[i+1]=' ';
			i=0;
		}
	}
	cout<<0<<' '<<strlen(a)-1<<endl;
	return 0;
}
int main()
{
	char a[100] , b , g;
	int i,ii;
	cin >> a;
	b = a[0];
	g = a[strlen(a) - 1];
	for (ii = 0;ii < strlen(a);ii++)
	{
		for (i = ii;i >= 0;i--)
		{
			if((a[ii] == g)&&(a[i] == b))
			{
				cout << i << " " <<ii <<endl;
				a[i] = ' ';
				a[ii] = ' ';
			}
		}
	}
	return 0;
}
struct result{
	int man;
	int woman;
}res[50]={0};
struct result temp;
int main()
{
	int i,j,p=-1,sum=0,len;
	char str[100]={0},std;
	gets(str);
	std=str[0];
	len=strlen(str);
	for(j=0;;j++){
		for(i=0;i<len;i++){
			if(str[i]==std&&str[i]!=str[i+1+j*2]&&str[i]!='\0'&&str[i+1+j*2]!='\0'){
				p++;
				res[p].man=i;
				res[p].woman=i+1+j*2;
				str[i]='\0';
				str[i+1+j*2]='\0';
				sum++;
			}
			else continue;
		}
		if(sum==len/2) break;
	}
	for(i=1;i<p+1;i++){
		for(j=0;j<p+1-i;j++){
			if(res[j].woman>res[j+1].woman){
				temp=res[j];
				res[j]=res[j+1];
				res[j+1]=temp;
			}
		}
	}
	for(i=0;i<=p;i++){
		printf("%d %d\n",res[i].man,res[i].woman);
	}
	return 0;
}
int main(){
char num[100]={0}; int i,j,k,m,t;
 gets(num); t=strlen(num);
 for(i=0;i<t;i++)
{ while(num[i]!=num[0]&&num[i]!='\0')
{     k=i;
    for(j=k;j>=0;j--)
   if(num[j]==num[0])
     break;
printf("%d %d\n",j,k);
num[j]='\0'; num[k]='\0';
           } 
               }
return 0;



}
int i=0,j=0;
int a[200];
char d;
int solve()
{
 char c;
 scanf("%c",&c);
 if(c==d) {
            a[i]=j;
            j++;
            i++;
            solve();
            }
   if(c!=d){
            printf("%d %d\n",a[i-1],j);
            i--;
            j++;
            if(i==0) return 0;
            solve();
            }
}
int main()
{ 
char c;  
scanf("%c",&c);
  d=c;
  a[i]=j;
  j++;
  i++;
  solve();
 
}
char a[100000000];
int n;
char e,f;
int lala(){
	int i,j;
	if(a[0]=='0')return 0;
	for(i=0;i<n;i++){
		if(a[i]==e){
			for(j=1;j<n-i;j++){
				if(a[i+j]=='0')continue;
				else if(a[i+j]==f){
					a[i]='0';a[i+j]='0';
					cout<<i<<' '<<i+j<<endl;
					return lala();
				}
				else if(a[i+j]==e)break;
			}
		}
	}return 0;
}
int main(){
	cin>>a;
	n=strlen(a);
	for(int i=1;i<n;i++)
		if(a[i]!=a[0]){
			f=a[i];
		}
	e=a[0];
	lala();
	return 0;
}
int main()
{
	char x[110]={'\0'};
	int i=0,j=1,count=0;
	char a=0,b=0,c=getchar();
	while(c!='\n')
	{
		x[i++]=c;
		c=getchar();
	}
	count=i+1;
	a=x[0];
	for(i=0;i<count;i++)
	{
		if(x[i]!=a)
		{
			b=x[i];
			break;
		}
	}
	int boy=0;
	while(x[0]!='\0')
	{
		for(i=0;i<count;i++)
		{
			if(x[i]==a)
			{
				boy=i;
				continue;
			}
			else if(x[i] == '\0')
				continue;
			else
			{
				cout<<boy<<" "<<i<<endl;
				x[boy] = '\0';
				x[i] = '\0';
				break;
			}
			/*for(j=i+1;j<count;j++)
			{
			if(x[j]==a)
			break;
			else if(x[j]=='\0')
			continue;
			else if(x[j]==b)
			{
			cout<<boy<<' '<<j<<'\n';
			x[i]='\0';
			x[j]='\0';
			break;
			}
			}*/
		}
	}
		return 0;
}
int main()
{
	int i,j,count=0;
    char line[200],tmp;
	scanf("%s",line);
	tmp=line[0];
	for(i=0;line[i];i++) count++;
	for(i=0;line[i];i++)
	{
		if(line[i]==tmp)     //???
		{
			for(j=i+1;line[j];j++)
			{
				if(line[j]==tmp) break;
				else if(line[j]!=tmp&&line[j]!='0')    //???
				{
					printf("%d %d\n",i,j);
					line[i]=line[j]='0';
					i=0;
				    break;
				}
			}
		}
	}
	printf("0 %d\n",count-1);
	return 0;
}
/**
* @file homework.cpp
* @author ???
* @date 2011-11-16
* @description
* ??????: ????
*/


int main()
{
	int i, j, k;
	char a[1000];
	cin.getline(a, 1000);
	for (i=1;a[i]!='\0';i++) // ???1????2
	{
		if (a[i]==a[0]) a[i]=1;
		else a[i]=2;
	}
	a[0]=1;
	do
	{
		for (j=0;j<i;j++)
		{
			if (a[j]==2)
			{
				for(k=j-1;k>=0;k--)
				{
									if (a[k]==1)
					{
						cout<<k<<" "<<j<<endl;
						a[k]=0;
						a[j]=0;
						break;
					}
				}
		
			}
		}
	} while (a[0]!=0);
	return 0;
}
//????  ???
int l,js = 0;
char a,b;

void search(char c[])
{
	int i,j;
	for (i = 0; i <= l - 1; i++)
		if (c[i] == b) break;                  //???????????
	for (j = i - 1; j >= 0; j--)
		if (c[j] == a)                         //?????????
		{
			c[i] = 'Z'; c[j] = 'Z';                 //???????????????
			cout << j << ' ' << i << endl;        //????
			js += 2;
			if (js == l)                            //?????????
				return;
			else
				search (c);                         //????
		}
}

	
int main()
{
	int i;
	char s[201];
	cin >> s;          //?????
	l = strlen (s);	     //????
	a = s[0];              //a?????????b????????
	for (i = 1; i <= l - 1; i++)
		if (s[i] != a)
		{
			b = s[i];
			break;
		}
	search (s);         //??????????
	return 0;
	
}
int main(int argc, char* argv[])
{
	char s[100],c;
	int i,k=0,j,len,p,q,temp0,temp1,w;
	int a[50],b[50];
	gets(s);
	c=s[0];
	len=strlen(s);
	for(p=0;p<len/2;p++)            //?????????? ???????? ??len/2?
	{
		for(i=0;i<len-1;i++)
		{            
			if(s[i]==' ')           //??????????
			{
				continue;
			}
			else
			{
				for(j=i+1;j<len-1;j++)       //?????i??????????
				{
					if(s[j]!=' ')
						break;
				}
				if(s[i]==c&&s[j]!=c)         //???i????????????????
				{
					s[i]=' ';s[j]=' ';       //???????? ???????? ?a?b
					a[k]=i;b[k]=j;
					k++;
				}
			}
		}	
	}
    for(p=0;p<k-1;p++)                      //??????????
	{
		for(q=0;q<k-p-1;q++)
		{
			if(b[q]>b[q+1])
			{
				temp0=b[q];
				b[q]=b[q+1];
				b[q+1]=temp0;
                temp1=a[q];
				a[q]=a[q+1];
				a[q+1]=temp1;
			}
		}
	}
	for(w=0;w<k;w++)
	{
        printf("%d %d\n",a[w],b[w]);
	}
	return 0;
}
struct ch
{
	int k;
	char a;
	struct ch *next;
};
void main()
{
	int i,j,t=0,n=0,N,z[50][2],temp;
	char boy,girl;
	struct ch *p1,*p2,*p3,*head;
	p1=p2=(struct ch *)malloc(LEN);
	boy=p1->a=getchar();
	p1->k=0;
	head=NULL;
	for (i=0;;i++)
	{
		n=n+1;
		if (n==1)
			head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct ch *)malloc(LEN);
		p1->a=getchar();
		p1->k=n;
		if (p1->a!='\n' && p1->a!=boy)
			girl=p1->a;
		if (p1->a=='\n')
		{
			N=n=n-1;
			break;
		}
	}
	p2->next=NULL;
	while (n>1)
	{
		p1=p2=head,p3=p2->next;
		while (p3!=NULL)
		{
			if (p2->a==boy && p3->a==girl)
			{
				if (p2==head)
				{
					z[t][0]=p2->k,z[t][1]=p3->k,t=t+1;
					if (p3->next!=NULL)
						head=(head->next)->next,p1=p2=head,p3=p2->next;
					else
						head=NULL;
					n=n-2;
				}
				else
				{
					z[t][0]=p2->k,z[t][1]=p3->k,t=t+1;
					if (p3->next!=NULL)
						p1->next=p3->next,p2=p3->next,p3=p2->next;
					else
						p1->next=NULL;
					n=n-2;
				}
			}
			else
				p1=p2,p2=p2->next,p3=p2->next;
		}
	}
	for (j=0;j<t;j++)
	{
		for (i=0;i<t-j-1;i++)
		{
			if (z[i][1]>z[i+1][1])
			{
				temp=z[i][0],z[i][0]=z[i+1][0],z[i+1][0]=temp;
				temp=z[i][1],z[i][1]=z[i+1][1],z[i+1][1]=temp;
			}
		}
	}
	for (i=0;i<t;i++)
		printf ("%d %d\n",z[i][0],z[i][1]);
	printf ("0 %d\n",N);
}
//???????????????
int main()
{
	char kid[300];
	cin>>kid;//??
	int line=strlen(kid);
	int i,j;
	char boy=kid[0];
	char girl=kid[line-1];
	for(i=0;i<line;i++)
	{
		if(kid[i]==boy)continue;//??????????
		else if(kid[i]==girl)
		{
			for(j=i-1;j>=0;j--)
			{
				if(kid[j]==boy)
				{
					cout<<j<<' '<<i<<endl;
					kid[i]=' ';
					kid[j]=' ';
					break;
				}
			}
		}//?????????????????????????????????
	}
	return 0;
}
int main()
{
    int i=0,j=0,b[100];
    char a[100];
    gets(a);
    b[0]=0;
    for(i=1;i<strlen(a);i++)
    {
        if(a[i]==a[0])
            b[++j]=i;
        else
            cout<<b[j--]<<" "<<i<<endl;
    }   

    return 0;
}
int stack[100];
int top=-1;


int pop(){
	top--;
	return stack[top+1];
}
void push(int e){
	top++;
	stack[top]=e;
}


int main(){
	char s[100];
	int i;
	char nan;
	scanf("%s",s);
	nan=s[0];
	push(0);
	for(i=1;s[i];i++){
		if(s[i]==nan) push(i);
		else{
			printf("%d %d\n",pop(),i);
		}
	}

	return 0;
}
char a[1000];
int n;

int xx (int k)
{
     int x,y;
     x=k;
     y=k+1;
     while (a[y]==a[x])
     y=xx(y);
     cout <<x<<" "<<y<<endl;
     return y+1;
}
     
int main ()
{
    cin.getline(a,999,'\n');
    n=strlen(a);
    int p=0;
    while (1)
    {
          p=xx(p);
          if (p==n)
          break;
    }
    return 0;
}
int k,p,t=0,n,a[500],b[500],temp;

char str[1000],c1,c2;

void f(int j){
     int i;
     for(i=0;i<n-1;i++){
        if((str[i]==c1)&&(str[i+j]==c2)){
            a[t]=i;
            b[t]=i+j;
            //printf("%d %d\n",i,i+j);
            t++;
            str[i]=' ';
            str[i+j]=' ';
        }
     }

}
int main(){
    scanf("%s",str);
    n=strlen(str);
    c1=str[0];
    c2=str[n-1];
    
    for(k=1;k<n;k++){
        f(k);
    }
    for(k=0;k<n/2;k++){
        for(p=n/2-1;p>k;p--){
            if(b[p-1]>b[p]){
                temp=b[p-1];
                b[p-1]=b[p];
                b[p]=temp;
                temp=a[p-1];
                a[p-1]=a[p];
                a[p]=temp;
            }
        }
    }
    for(k=0;k<n/2;k++){
        printf("%d %d\n",a[k],b[k]);
    }
    
scanf("%d",&k);
return 0;
}
int main()
{
	char line[101], b;
	int len, count = 0;
	int i, j;
	int intline[101];
	cin.getline(line, 101);
	b = line[0];
	len = strlen(line);
	for (i = 0; i < len; i++)
	{
		if (line[i] == b)
			intline[i] = 1;				//1??boy
		else
			intline[i] = 2;				//2??girl, 3?????????????
	}
	while (count < len / 2)
	{
		for (i = 0; i < len; i++)		//????????????
		{
			if (intline[i] == 2)
				break;
		}
		for (j = i; j >= 0; j--)		//????????????????
		{
			if (intline[j] == 1)
				break;
		}
		intline[i] = 3;					//???????????
		intline[j] = 3;
		cout << j << " " << i << endl;
		count++;
	}
	return 0;
}
void main()
{
	char pupils[100],g;
	int i=0,j,k;
	gets(pupils);
	k=strlen(pupils);
	g=pupils[k-1];
	while (i<k)
	{
		if (pupils[i]==g)
		{
			j=1;
			while (pupils[i-j]==0) j++;
			pupils[i]=0;
			pupils[i-j]=0;
			printf("%d %d\n",i-j,i);
		}
		i++;
	}
}
void main()
{
	char s[100],boy;
	int num[100],i,*p,*q,N;
	
	scanf("%c",&s[0]);
	boy=s[0];
	num[0]=0;
	for(i=1;i<=100;i++)
	{
		scanf("%c",&s[i]);
		if(s[i]=='\n')
		{
			N=i-1;break;//
		}
		if(s[i]!=boy)
		{
			num[i]=-1*i;
		}
		if(s[i]==boy)
		{num[i]=i;}
		N=i;
	}

	for(p=num+1;p<num+N;p++)
	{
		if(*p<0)
		{
			q=p;
			while(*(q-1)==0)q--;
			printf("%d %d\n",*(q-1),-1*(*p));
			*p=0;*(q-1)=0;
		}
	}
	printf("0 %d",N);
}
int main()
{
	int i, j, l;
	char a[101];
	cin >> a;
	l = strlen(a);
	for (i = 0; i < l; i++)
	{
		if (a[i] == a[l - 1])
		{
			for (j = i - 1; j >= 0; j--)
			{
				if (a[j] == a[0])
				{
					cout << j << " " << i << endl;
					a[j] = a[l - 1];
					break;
				}
			}
		}
	}

return 0;
}
void leave(char a[], char b)
{
    int i,temp;
    if (a[0] == b)
    {
        for (i = 0; a[i] != '\0'; )
        {
            if (a[i] == b )
            {
                temp = i;
                i++;
                while (a[i] == 0)
                {
                    i++;
                }
                if (a[i] != b && a[i] != 0 )
                {
                    a[i] = 0;
                    a[temp] = 0;
                    cout << temp << " " << i << endl;
                }
            }
        }
        leave(a,b);
    }
}

int main()
{
    char a[100];
    char b;
    cin.getline(a, 100);
    b = a[0];
    leave(a,b);
    return 0;
}
void bubble(int array[],int n);
void main()
{
	struct answer
	{
		int girl;
		int boy;
	};
	char test[MAXSIZE]={'\0'},boy,girl;
	int len,i,j,p;
	struct answer ans[MAXSIZE]={0,0},temp;
	
	scanf("%s",test);
	len=strlen(test);
	boy=test[0];
	girl=test[len-1];
	
	p=0;
	for(i=0;i<len;i++)
	{
		if(test[i]==girl)
		{
			for(j=i-1;j>=0;j--)
			{
				if(test[j]==boy)
				{
					ans[p].boy=j;
					ans[p].girl=i;
					test[i]=girl+boy;
					test[j]=girl+boy;
					p++;
					break;
				}
			}
		}
	}
	
	for(j=1;j<=p;j++)
	{
		for(i=0;i<p-j;i++)
		{
			if(ans[i].girl>ans[i+1].girl)
			{
				temp=ans[i];
				ans[i]=ans[i+1];
				ans[i+1]=temp;
			}
		}
	}

	for(i=0;i<p;i++)
	{
		printf("%d %d\n",ans[i].boy,ans[i].girl);
	}
}
int main() 
{
	int a[111],i, n = 0;;
	char s[111];
	cin >> s;
	char boy=s[0];
	for (i = 0; s[i]; ++i)
		if (s[i] == boy) a[++n] = i;
		else cout << a[n--] << " " << i << endl;
	return 0;
}
char set[100];
void getBoy(int i,char b,char g){
	if(set[i]=='\0')return;
	while(set[i]!='\0' && set[i]!=g)++i;
	int j=i-1;
	while(j>=0 && set[j]!=b)--j;
	cout<<j<<" "<<i<<endl;
	set[i]=0;set[j]=0;
	getBoy(i+1,b,g);
}
int main(){
	cin>>set;
	char b,g;
	b = set[0];
	g = set[strlen(set)-1];
	getBoy(0,b,g);
	return 0;
}