//	This source and number (rhymes) permutation method apply to GNU General Public License. 
//		Copyright (C) 2011 and later by Jasenko Dzinleski 

//		This program is free software; you can redistribute it
//	and/or modify it under the terms of the GNU General Public License as
//	published by the Free Software Foundation; either version 2 of the
//	License, or (at your option) any later version. 

//	This program is distributed in the hope that it will be useful, but
//	WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//	General Public License for more details. 

//	You should have received a copy of the GNU General Public License along
//	with this program; if not, write to the Free Software Foundation, Inc.,
//	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

//
//			Text Rhymes VRM 1.0.5 
//			written by Dzinleski Jasenko December , 11 , 2011
//			

#include <stdio.h>
#include <string.h>
#include <math.h>


char	in_fn[256];
char	outfn[256]="out.txt";

FILE	*f1,*f2;

char	ip[256]="1234567890";
char	ia[256];
char	ib[256]="6050506050";

char	iv[256];int	ivi=0;

char	arga[256];
char	s_a[256];int	sai=0;
char	s_b[256];int	sbi=0;


char	rp_f[256];
char	rp_f_[256];
int	da[3];

int	ba9[9][9][9][2];	int	ba9i=0;
int	ba16[16][16][16][16][2];int	ba16i=0;

int 	sa[0xffff];
int 	so[30];int	soi=0;

double p_val(char arr0[256])
{
	int	sig=0;
	int	j=0,k=0,l;

	long		fr;
	int		rvi;
	__int64		rvl;
	__int64	rvd;
	double		rvd_;

	char 		arr1[256];

	for(j=0;j<strlen(arr0);++j){if(arr0[j]=='-'){sig=1;break;}}

	for(j=0;j<256;++j){arr1[j]='\0';}
	l=0;for(j=0;j<strlen(arr0);++j){if((arr0[j]>='0'&&arr0[j]<='9')||(arr0[j]=='.'||arr0[j]==',')){arr1[l]=arr0[j];++l;}}

	for(j=0;j<256;++j){arr0[j]='\0';}l=0;for(j=0;j<strlen(arr1);++j){arr0[l]=arr1[j];++l;}

	for(j=0;j<strlen(arr0);++j){if(arr0[j]=='.'){break;}}

	if(j==strlen(arr0))
	{
		rvl=0;l=-1;
		for(j=-1+strlen(arr0);j>=0;--j)
		{
			++l;rvl+=(__int64)(-48+arr0[j])*pow(10,l);
		}
		rvi=(int)rvl;
		rvd_=(double)rvl;

	}else{

			fr=0;l=-1;
			for(k=-1+strlen(arr0);k>j;--k)
			{
				++l;fr+=(long)(-48+arr0[k])*pow(10,l);
			}

			rvd=0;l=-1;
			for(k=j-1;k>=0;--k)
			{
				++l;rvd+=(__int64)(-48+arr0[k])*pow(10,l);

			}rvd*=(__int64)pow(10,strlen(arr0)-j-1);

			rvd_=(double)(rvd+(__int64)fr)/(__int64)pow(10,strlen(arr0)-j-1);
				
	}

	if(sig==0){return(rvd_);}else{return(-1.0*rvd_);}

}

double p_v(char pv_a1[256])
{

	bool	df=false;
	int	i,l;
	double	p_v;

	p_v=0;l=-1;
	for(i=-1+strlen(pv_a1);i>=0;--i)
	{
		++l;p_v+=(double)(-48+(int)pv_a1[i])*pow(10,l);
		if(df){printf("%d %e\n",-48+(int)pv_a1[i],pow(10,l));}
	}
	return(p_v);

}

int p_f_(double ar1)
{
	int	i,j,l,n;
	__int64	r,k,m,ti,tj;

	char ta[256];int	tai=-1+256;

	for(i=0;i<256;++i){ta[i]='\0';}

	r=0;ti=10;tj=(__int64)ar1;
	while(tj>0)
	{

		if((((__int64)(tj/ti))*ti)-(((double)(tj/ti))*ti)==(double)0.00)
		{r=tj-((__int64)(tj/ti))*ti;}else{r=tj-((__int64)(tj/ti))*ti;--r;}

		tj-=r;
		//printf("!%c!",(48+(int)(r/(ti/10))));
		ta[tai]=(48+(int)(r/(ti/(__int64)10)));--tai;
				
		ti*=(__int64)10;

	}
	for(j=0;j<256;++j){rp_f[j]='\0';}
	j=0;l=0;for(i=0;i<256;++i){if(j==0){if(ta[i]!='\0'){j=1;rp_f[l]=ta[i];++l;/*printf("%c",ta[i]);*/}}else{rp_f[l]=ta[i];++l;/*printf("%c",ta[i]);*/}}/*printf("\n");*/

	return(0);
}

int p_f(double pf_r1)
{

	bool	df=false;
	int	i,j;
	int	l,l_,q;
	double pf_r1_;

	pf_r1_=pf_r1;
	for(i=0;i<256;++i){rp_f[i]='\0';}i=0;
	if(pf_r1==0){rp_f[i]='0';return(0);}

	l=0;while((pf_r1-pow(10,l))/(1000*pow(10,l))>10*(0.001)){++l;}l_=l;q=l;

	if(df){printf("%d %d\n",(int)(pf_r1/pow(10,l)),l );}
	if((int)(pf_r1/pow(10,l))<10)
	{
		rp_f[i]=48+(int)(pf_r1/pow(10,l));++i;
		if(df){printf("0.%d ",(int)(pf_r1/pow(10,l)));}
	}else{
		rp_f[i]=48+(int)(pf_r1/pow(10,l))/10;++i;
		if(df){printf("1.%d ",(int)(pf_r1/pow(10,l))/10);}
		rp_f[i]=48+pf_r1/pow(10,l)-10*(int)((pf_r1/pow(10,l))/10);++i;
		if(df){printf("2.%d ",(int)(pf_r1/pow(10,l))-10*(int)(pf_r1/pow(10,l))/10);}
	}
	if(df){printf("?%s?\n",rp_f);}

	pf_r1=pf_r1-pow(10,l)*(int)(pf_r1/pow(10,l));

	while(l>0)
	{
		l=0;while((pf_r1-pow(10,l))/(1000*pow(10,l))>10*(0.001)){++l;}
		if(df){printf("%e\n",(pf_r1-pow(10,l)*(int)(pf_r1/pow(10,l))));}
		j=l;while(j+1<l_){rp_f[i]='0';++i;++j;}l_=l;
		if((int)(pf_r1/pow(10,l))<10)
		{
			rp_f[i]=48+(int)(pf_r1/pow(10,l));++i;
			if(df){printf("0.%d ",(int)(pf_r1/pow(10,l)));}
		}else{
			rp_f[i]=48+(int)(pf_r1/pow(10,l))/10;++i;
			if(df){printf("1.%d ",(int)(pf_r1/pow(10,l))/10);}
			rp_f[i]=48+pf_r1/pow(10,l)-10*(int)((pf_r1/pow(10,l))/10);++i;
			if(df){printf("2.%d ",(int)(pf_r1/pow(10,l))-10*(int)(pf_r1/pow(10,l))/10);}
		}
		
		if(df){printf("?%s?\n",rp_f);}
		pf_r1=pf_r1-pow(10,l)*(int)(pf_r1/pow(10,l));
	}
	if(df){printf("?%s?\n",rp_f);}
	if(pf_r1_-p_v(rp_f)==-900){rp_f[-1+strlen(rp_f)]='\0';}
	//printf("%e\n",pf_r1_-p_v(rp_f));
	return(0);

}

int p_format(double ar1,char fm[256],char ar2[256])
{

	int		i,j,k,l,m,n;
	int		sig=0;
	int		ar2i=-1+256;

	char		lfm[256]="0000000000";
	bool		li=true;
	
	//0.00
	//#.00
	//#.##
	//000000
	//######
	//#,###,##0.00
	//
	
	if(ar1<0){ar1*=(double)-1;sig=1;}
	for(j=0;j<256;++j){ar2[j]='\0';}

	if(ar1==0){i=0;for(j=0;j<strlen(fm);++j){ar2[i]=fm[j];++i;}

		for(i=0;i<strlen(ar2);++i){if(ar2[i]=='#'){ar2[i]=' ';}}
		for(i=0;i<strlen(ar2);++i){if(ar2[i]==' '&&ar2[i+1]==','){ar2[i+1]=' ';}}
		return(0);
	}

	if(strlen(fm)!=0)
	{
		m=-1+strlen(fm);
		n=256-strlen(fm);

		for(i=-1+strlen(fm);i>=0;--i){if(fm[i]=='.'){break;}}//decimal point point
		if(i==-1)
		{

			p_f_(ar1);
			l=-1+strlen(rp_f);
			if(strlen(rp_f)==0){while(m>=0){ar2[ar2i]=fm[m];--ar2i;--m;}}else{
				while(l>=0){if(fm[m]==','){ar2[ar2i]=',';--ar2i;--m;}else{
					ar2[ar2i]=rp_f[l];--l;--ar2i;--m;}
				}
			}
			while(m>=0){ar2[ar2i]=fm[m];--ar2i;--m;}

		}else{

			p_f_(ar1);
			p_f_((ar1-p_v(rp_f))*pow(10,-1+strlen(fm)-i));
			k=-1+strlen(rp_f);
			l=(m-i)-strlen(rp_f);while(l>0){ar2[ar2i]='0';--l;--ar2i;}
			while(k>=0&&ar2i>=256-(m-i)){ar2[ar2i]=rp_f[k];--k;--ar2i;}
			ar2[ar2i]='.';--ar2i;m=-1+i;

			p_f_(ar1);
			l=-1+strlen(rp_f);
			while(l>=0){if(m>=0&&fm[m]==',')
			{ar2[ar2i]=fm[m];--ar2i;--m;}ar2[ar2i]=rp_f[l];--l;--ar2i;--m;}
			while(m>=0&&ar2i>=n){ar2[ar2i]=fm[m];--ar2i;--m;}

		}
	
	}else{

		p_f_(ar1);
		p_f_((ar1-p_v(rp_f))*pow(10,2));
		k=-1+strlen(rp_f);
		l=2;i=0;while(k>=0||l>i){if(k>=0){ar2[ar2i]=rp_f[k];--k;--ar2i;--l;}else{
			ar2[ar2i]='0';--ar2i;--l;}}ar2[ar2i]='.';--ar2i;m=1;

		p_f_(ar1);
		l=-1+strlen(rp_f);
		if(strlen(rp_f)==0){while(m>=0){ar2[ar2i]='0';--ar2i;--m;}}else{
			while(l>=0){ar2[ar2i]=rp_f[l];--l;--ar2i;}
		}

	}

	l=0;if(sig==1){ar2[l]='-';++l;for(i=1;i<256;++i){if(ar2[i]!='\0'){ar2[l]=ar2[i];++l;}}}else{
		for(i=0;i<256;++i){if(ar2[i]!='\0'){ar2[l]=ar2[i];++l;}}
	}
	for(i=l;i<256;++i){ar2[i]='\0';}

	for(i=0;i<strlen(ar2);++i){if(ar2[i]=='#'){ar2[i]=' ';}}
	for(i=0;i<strlen(ar2);++i){if(ar2[i]==' '&&ar2[i+1]==','){ar2[i+1]=' ';}}

	return(0);

}

int p_1()
{

	int		i,j,k,l,m,n,p,q,r;
	char		pa[256];
	double 		pad,argad;
	double 		r1,r2;

	int		fbyte;
	int		a,b,c,d,e;
	bool		df=false;
	

	for(i=0;i<256;++i){pa[i]='\0';}
	j=1;l=0;for(i=0;i<strlen(ip);++i){++j;pa[l]=ip[10-j];++l;pa[l]=ip[i];++l;}
	//printf("%s\n",ip);

	for(i=0;i<256;++i){ia[i]='\0';}
	j=0;for(i=0;i<strlen(pa);++i){ia[j]=pa[i];++j;}
	//printf("|ia|%s|\n",ia);
	//printf("|ib|%s|\n",ib);

	for(i=0;i<256;++i){iv[i]='\0';}ivi=0;
	a=10;
	while(a>3)
	{

		for(i=0;i<256;++i){pa[i]='\0';}
		j=0;l=0;for(i=0;i<a;++i)
		{
			pa[l]=ia[10-a];++l;
			if(l==strlen(ia)){break;}
			pa[l]=ia[i];++l;
			if(l==strlen(ia)){break;}
		}
		//printf("|pa|%d|%s\n",a,pa);

		for(i=0;i<256;++i){s_b[i]='\0';}
		j=0;for(i=0;i<5;++i){s_b[i]=pa[i];++j;}

		//printf("|ia|%d|%s\n",a,ia);

		pad=p_val(ib);
		argad=p_val(s_b);

		r1=pad/argad;
		//printf("%e\n",pad/argad);

		p_format(r1,"0",rp_f_);
		//printf("%s\n",rp_f_);


		iv[ivi]=rp_f_[0];++ivi;
		iv[ivi]=rp_f_[1];++ivi;
		iv[ivi]=rp_f_[2];++ivi;


		//iv[ivi]=rp_f_[3];++ivi;
		//iv[ivi]=rp_f_[4];++ivi;

		--a;

	}

	if(df){printf("|iv|%s\n",iv);}

	return(0);
	
}

int p_2()
{

	int		i,j,k,l;
	bool		df=false;
	char		c0[256];
	char		c1[256];
	char		c2[256];

	p_1();
	for(i=0;i<256;++i){c0[i]='\0';}
	j=0;for(i=0;i<strlen(iv);++i){c0[j]=iv[i];++j;}

	for(i=0;i<256;++i){ib[i]='\0';}
	j=0;for(i=0;i<1+10;++i){ib[j]=iv[i];++j;}

	p_1();
	for(i=0;i<256;++i){c1[i]='\0';}
	j=0;for(i=0;i<strlen(iv);++i){c1[j]=iv[i];++j;}

	if(df)
	{
		for(i=0;i<strlen(c0);)
		{
			printf("%c",c0[i]);++i;
			printf("%c",c0[i]);++i;
			printf("%c",c0[i]);++i;
			printf(" ");
		}printf("\n");
	}
	j=0;
	for(i=0;i<strlen(c0);)
	{
		if(c0[i]!=c1[i]){if(df){printf("|");}++j;}else{if(df){printf(" ");}}++i;
		if(c0[i]!=c1[i]){if(df){printf("|");}++j;}else{if(df){printf(" ");}}++i;
		if(c0[i]!=c1[i]){if(df){printf("|");}++j;}else{if(df){printf(" ");}}++i;
		if(df){printf(" ");}
	}if(df){printf("\n");}
	da[0]=0;da[1]=0;da[2]=0;
	if(c0[1]==c1[1]&&c0[4]==c1[4]&&c0[7]==c1[7])
	{
		//0123 123 123
		da[0]=(10*(-48+c0[2])+(-48+c0[3]))-(10*(-48+c1[2])+(-48+c1[3]));
		da[1]=(10*(-48+c0[5])+(-48+c0[6]))-(10*(-48+c1[5])+(-48+c1[6]));
		da[2]=(10*(-48+c0[8])+(-48+c0[9]))-(10*(-48+c1[8])+(-48+c1[9]));	
	}
	if(df)
	{
		for(i=0;i<strlen(c1);)
		{
			printf("%c",c1[i]);++i;
			printf("%c",c1[i]);++i;
			printf("%c",c1[i]);++i;
			printf(" ");
		}printf("\n");
	}
	return(j);


}

int main(int argc,char *argv[])
{

	int		i,j,k,l;
	int		a,b,c,d,e,cc;
	long 		pos,ppos;
	long 		fbyte3;
	int		fbyte,fbyteA[4];int	fbyteA_i=0;
	char		s_a[256];int	sai=0;
	int		ba[3];
	int		ba_[4];int	ba_i=0;

	bool		de=false;
	bool		df=false;
	bool		df1=false;
	bool		df2=false;


	printf("\n\n");
	printf("\nText Rhymes by Dzinleski Jasenko 2011 , December , 11 , 2011\n");
	printf("\n");
	printf("\nOS Win32 VRM 1.0.5\n\n");
	printf("\n");


	for(i=0;i<9;++i){for(j=0;j<9;++j){for(k=0;k<9;++k){ba9[i][j][k][0]=-1;}}}ba9i=0;
	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l){
		ba16[i][j][k][l][0]=-1;}}}}ba16i=0;

	if(argv[1]!=NULL){
		if(argv[2]!=NULL){
			if(argv[2][0]=='c'){d=1;}else{d=0;}
			strcpy(in_fn,argv[1]);
		}else{
			return(0);
		}
	}else{
		printf("Enter: <FASTA file name .txt> <c>\n");return(0);
	}
	f1=fopen(in_fn,"rb");
	if(f1==NULL){printf("Nothing to do!\n");printf("Enter: <ASCII book name .txt> <c>\n");return(0);}else{fclose(f1);}
	
	f1=fopen(in_fn,"rb");
	ppos=-1;cc=0;
	fbyte=getc(f1);fbyteA[fbyteA_i]=fbyte;++fbyteA_i;
	while(!feof(f1))
	{
		fbyte=getc(f1);fbyteA[fbyteA_i]=fbyte;++fbyteA_i;
		if(fbyteA_i==3)
		{

			pos=ftell(f1);
			p_format(fbyteA[0],"000",s_a);
			for(i=0;i<256;++i){ib[i]='\0';}
			j=0;ib[j]='0';++j;
			for(i=0;i<3;++i){ib[j]=s_a[i];++j;}
			p_format(fbyteA[1],"000",s_a);
			for(i=0;i<3;++i){ib[j]=s_a[i];++j;}
			p_format(fbyteA[2],"000",s_a);
			for(i=0;i<3;++i){ib[j]=s_a[i];++j;}

			ba[0]=-1;ba[1]=-1;ba[2]=-1;
			p_2();
			//printf("|%d|%d|%d|\n",da[0],da[1],da[2]);			
			if((da[0]>=-30&&da[0]<=30)&&(da[1]>=-30&&da[1]<=30)&&(da[2]>=-30&&da[2]<=30))
			{
				//printf("|%d|%d|%d| ",da[0],da[1],da[2]);
				if(da[0]==0  ){/*printf("_");*/ba[0]=0;}				
				if(da[0]==-10){/*printf("a");*/ba[0]=1;}
				if(da[0]==10 ){/*printf("A");*/ba[0]=2;}
				if(da[0]==-11){/*printf("b");*/ba[0]=3;}
				if(da[0]==11 ){/*printf("B");*/ba[0]=4;}
				if(da[0]==-20){/*printf("c");*/ba[0]=5;}
				if(da[0]==20 ){/*printf("C");*/ba[0]=6;}
				if(da[0]==-30){/*printf("d");*/ba[0]=7;}
				if(da[0]==30 ){/*printf("D");*/ba[0]=8;}

				if(da[1]==0  ){/*printf("_");*/ba[1]=0;}
				if(da[1]==-10){/*printf("e");*/ba[1]=1;}
				if(da[1]==10 ){/*printf("E");*/ba[1]=2;}
				if(da[1]==-11){/*printf("f");*/ba[1]=3;}
				if(da[1]==11 ){/*printf("F");*/ba[1]=4;}
				if(da[1]==-20){/*printf("g");*/ba[1]=5;}
				if(da[1]==20 ){/*printf("G");*/ba[1]=6;}
				if(da[1]==-30){/*printf("h");*/ba[1]=7;}
				if(da[1]==30 ){/*printf("H");*/ba[1]=8;}

				if(da[2]==0  ){/*printf("_");*/ba[2]=0;}
				if(da[2]==-10){/*printf("i");*/ba[2]=1;}
				if(da[2]==10 ){/*printf("I");*/ba[2]=2;}
				if(da[2]==-11){/*printf("j");*/ba[2]=3;}
				if(da[2]==11 ){/*printf("J");*/ba[2]=4;}
				if(da[2]==-20){/*printf("k");*/ba[2]=5;}
				if(da[2]==20 ){/*printf("K");*/ba[2]=6;}
				if(da[2]==-30){/*printf("l");*/ba[2]=7;}
				if(da[2]==30 ){/*printf("L");*/ba[2]=8;}

				if(ba[0]==-1){printf("0. Error...%d %d\n",ba[0],da[0]);}
				if(ba[1]==-1){printf("1. Error...%d %d\n",ba[1],da[1]);}
				if(ba[2]==-1){printf("2. Error...%d %d\n",ba[2],da[2]);}

				if(ba[0]!=-1&&ba[1]!=-1&&ba[2]!=-1)
				{
					if(ba9[ba[0]][ba[1]][ba[2]][0]==-1)
					{
						ba9[ba[0]][ba[1]][ba[2]][0]=ba9i;
						//printf("|%d|",ba9i);ba_[ba_i]=ba9i;++ba_i;
						ba_[ba_i]=ba9i;++ba_i;
						++ba9i;
						ba9[ba[0]][ba[1]][ba[2]][1]=1;
					}else{
						++ba9[ba[0]][ba[1]][ba[2]][1];
						ba_[ba_i]=ba9[ba[0]][ba[1]][ba[2]][0];++ba_i;
						//printf("|%d|",ba9[ba[0]][ba[1]][ba[2]][0]);
					}
				}

				if(d==1)
				{
					if(fbyteA[0]!=10&&fbyteA[0]!=13){printf("%c",fbyteA[0]);}
					if(fbyteA[1]!=10&&fbyteA[1]!=13){printf("%c",fbyteA[1]);}
					if(fbyteA[2]!=10&&fbyteA[2]!=13){printf("%c",fbyteA[2]);}
				}else{
					printf("%d",1+ba[0]);printf("%d",1+ba[1]);printf("%d\t",1+ba[2]);
				}

				if(ba_i==4)
				{

					printf("\t%d",cc);++cc;
					printf("\n");

					if(!(ba_[0]>=0&&ba_[0]<=15))
					{if(de){printf("_0. Error...%d\n",ba_[0]);}}
					if(!(ba_[1]>=0&&ba_[1]<=15))
					{if(de){printf("_1. Error...%d\n",ba_[1]);}}
					if(!(ba_[2]>=0&&ba_[2]<=15))
					{if(de){printf("_2. Error...%d\n",ba_[2]);}}
					if(!(ba_[3]>=0&&ba_[3]<=15))
					{if(de){printf("_3. Error...%d\n",ba_[3]);}}

					if
					(
						(ba_[0]>=0&&ba_[0]<=15)&&
						(ba_[1]>=0&&ba_[1]<=15)&&
						(ba_[2]>=0&&ba_[2]<=15)&&
						(ba_[3]>=0&&ba_[3]<=15)
					)
					{

						if(ba16[ba_[0]][ba_[1]][ba_[2]][ba_[3]][0]==-1)
						{
							ba16[ba_[0]][ba_[1]][ba_[2]][ba_[3]][0]=ba16i;
							//printf("%d ",ba16i);
							++ba16i;
							ba16[ba_[0]][ba_[1]][ba_[2]][ba_[3]][1]=1;
						}else{
							++ba16[ba_[0]][ba_[1]][ba_[2]][ba_[3]][1];
							//printf("%d ",ba16[ba_[0]][ba_[1]][ba_[2]][ba_[3]][0]);
						}


					}
					
					ba_i=0;
				}

				if(d==1)
				{
					if(df)
					{
					printf("%c",fbyteA[0]);
					printf("%c",fbyteA[1]);
					printf("%c",fbyteA[2]);
					}
				}else{
					if(df)
					{
					printf("%03d",fbyteA[0]);
					printf("%03d",fbyteA[1]);
					printf("%03d",fbyteA[2]);
					}
				}
				if(ppos!=-1&&ppos+3==pos){}else{if(df){printf("\n");}}
				ppos=pos;

			}else{ppos=-1;}
			fbyteA_i=0;
		}
	}
	fclose(f1);

	if(df2)
	{
	for(i=0;i<9;++i){for(j=0;j<9;++j){for(k=0;k<9;++k)
	{
		if(ba9[i][j][k][0]!=-1){printf("%d %d %d - %d\n",i,j,k,ba9[i][j][k][1]);}
	}}}
	}

	if(df1)
	{
	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l)
	{
		if(ba16[i][j][k][l][0]!=-1){printf("%d %d %d %d - %d\n",i,j,k,l,ba16[i][j][k][l][1]);}
	}}}}
	}

	for(i=0;i<0xffff;++i){sa[i]=-1;}
	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l)
	{
		if(ba16[i][j][k][l][0]!=-1)
		{
			sa[((i&0x0f)<<12)|((j&0x0f)<<8)|((k&0x0f)<<4)|((l&0x0f)<0)]=ba16[i][j][k][l][1];
		}
	}}}}

	e=-1;
	for(i=0;i<0xffff;++i)
	{
		if(sa[i]!=-1)
		{
			if(e==-1)
			{
				e=sa[i];
				for(j=0;j<0xffff;++j)
				{
					if(e<sa[j]){e=sa[j];}	
				}
				//printf("%d\n",e);
				so[soi]=e;++soi;if(soi==10){break;}
			}else{
				if(e>sa[i]){a=sa[i];}
				for(j=0;j<0xffff;++j)
				{
					if(sa[j]<e&&a<sa[j]){a=sa[j];}	
				}
				e=a;
				//printf("%d\n",e);
				so[soi]=e;++soi;if(soi==10){break;}
			}
		}
	}

	printf("\n");

	for(e=0;e<soi;++e)
	{
	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l)
	{
		if(ba16[i][j][k][l][0]!=-1&&ba16[i][j][k][l][1]==so[e])
		{
			//printf("%d %d %d %d - %d\n",i,j,k,l,ba16[i][j][k][l][1]);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==i){break;}
			}if(c!=9){break;}}if(b!=9){break;}}


			if(a==0){printf("_");}

			if(a==1){printf("a");}

			if(a==2){printf("A");}

			if(a==3){printf("b");}

			if(a==4){printf("B");}

			if(a==5){printf("c");}

			if(a==6){printf("C");}

			if(a==7){printf("d");}

			if(a==8){printf("D");}


			if(b==0){printf("_");}

			if(b==1){printf("e");}

			if(b==2){printf("E");}

			if(b==3){printf("f");}

			if(b==4){printf("F");}

			if(b==5){printf("g");}

			if(b==6){printf("G");}

			if(b==7){printf("h");}

			if(b==8){printf("H");}


			if(c==0){printf("_");}

			if(c==1){printf("i");}

			if(c==2){printf("I");}

			if(c==3){printf("j");}

			if(c==4){printf("J");}

			if(c==5){printf("k");}

			if(c==6){printf("K");}

			if(c==7){printf("l");}

			if(c==8){printf("L");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==j){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("_");}

			if(a==1){printf("a");}

			if(a==2){printf("A");}

			if(a==3){printf("b");}

			if(a==4){printf("B");}

			if(a==5){printf("c");}

			if(a==6){printf("C");}

			if(a==7){printf("d");}

			if(a==8){printf("D");}


			if(b==0){printf("_");}

			if(b==1){printf("e");}

			if(b==2){printf("E");}

			if(b==3){printf("f");}

			if(b==4){printf("F");}

			if(b==5){printf("g");}

			if(b==6){printf("G");}

			if(b==7){printf("h");}

			if(b==8){printf("H");}


			if(c==0){printf("_");}

			if(c==1){printf("i");}

			if(c==2){printf("I");}

			if(c==3){printf("j");}

			if(c==4){printf("J");}

			if(c==5){printf("k");}

			if(c==6){printf("K");}

			if(c==7){printf("l");}

			if(c==8){printf("L");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==k){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("_");}

			if(a==1){printf("a");}

			if(a==2){printf("A");}

			if(a==3){printf("b");}

			if(a==4){printf("B");}

			if(a==5){printf("c");}

			if(a==6){printf("C");}

			if(a==7){printf("d");}

			if(a==8){printf("D");}


			if(b==0){printf("_");}

			if(b==1){printf("e");}

			if(b==2){printf("E");}

			if(b==3){printf("f");}

			if(b==4){printf("F");}

			if(b==5){printf("g");}

			if(b==6){printf("G");}

			if(b==7){printf("h");}

			if(b==8){printf("H");}


			if(c==0){printf("_");}

			if(c==1){printf("i");}

			if(c==2){printf("I");}

			if(c==3){printf("j");}

			if(c==4){printf("J");}

			if(c==5){printf("k");}

			if(c==6){printf("K");}

			if(c==7){printf("l");}

			if(c==8){printf("L");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==l){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("_");}

			if(a==1){printf("a");}

			if(a==2){printf("A");}

			if(a==3){printf("b");}

			if(a==4){printf("B");}

			if(a==5){printf("c");}

			if(a==6){printf("C");}

			if(a==7){printf("d");}

			if(a==8){printf("D");}


			if(b==0){printf("_");}

			if(b==1){printf("e");}

			if(b==2){printf("E");}

			if(b==3){printf("f");}

			if(b==4){printf("F");}

			if(b==5){printf("g");}

			if(b==6){printf("G");}

			if(b==7){printf("h");}

			if(b==8){printf("H");}


			if(c==0){printf("_");}

			if(c==1){printf("i");}

			if(c==2){printf("I");}

			if(c==3){printf("j");}

			if(c==4){printf("J");}

			if(c==5){printf("k");}

			if(c==6){printf("K");}

			if(c==7){printf("l");}

			if(c==8){printf("L");}


			printf("%c%06d\n",(char)9,ba16[i][j][k][l][1]);
			//printf("\n");

		}

	}}}}

	}

	printf("\n");

	for(e=0;e<soi;++e)
	{
	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l)
	{
		if(ba16[i][j][k][l][0]!=-1&&ba16[i][j][k][l][1]==so[e])
		{
			//printf("%d %d %d %d - %d\n",i,j,k,l,ba16[i][j][k][l][1]);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==i){break;}
			}if(c!=9){break;}}if(b!=9){break;}}


			if(a==0){printf("1");}

			if(a==1){printf("2");}

			if(a==2){printf("3");}

			if(a==3){printf("4");}

			if(a==4){printf("5");}

			if(a==5){printf("6");}

			if(a==6){printf("7");}

			if(a==7){printf("8");}

			if(a==8){printf("9");}


			if(b==0){printf("1");}

			if(b==1){printf("2");}

			if(b==2){printf("3");}

			if(b==3){printf("4");}

			if(b==4){printf("5");}

			if(b==5){printf("6");}

			if(b==6){printf("7");}

			if(b==7){printf("8");}

			if(b==8){printf("9");}


			if(c==0){printf("1");}

			if(c==1){printf("2");}

			if(c==2){printf("3");}

			if(c==3){printf("4");}

			if(c==4){printf("5");}

			if(c==5){printf("6");}

			if(c==6){printf("7");}

			if(c==7){printf("8");}

			if(c==8){printf("9");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==j){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("1");}

			if(a==1){printf("2");}

			if(a==2){printf("3");}

			if(a==3){printf("4");}

			if(a==4){printf("5");}

			if(a==5){printf("6");}

			if(a==6){printf("7");}

			if(a==7){printf("8");}

			if(a==8){printf("9");}


			if(b==0){printf("1");}

			if(b==1){printf("2");}

			if(b==2){printf("3");}

			if(b==3){printf("4");}

			if(b==4){printf("5");}

			if(b==5){printf("6");}

			if(b==6){printf("7");}

			if(b==7){printf("8");}

			if(b==8){printf("9");}


			if(c==0){printf("1");}

			if(c==1){printf("2");}

			if(c==2){printf("3");}

			if(c==3){printf("4");}

			if(c==4){printf("5");}

			if(c==5){printf("6");}

			if(c==6){printf("7");}

			if(c==7){printf("8");}

			if(c==8){printf("9");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==k){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("1");}

			if(a==1){printf("2");}

			if(a==2){printf("3");}

			if(a==3){printf("4");}

			if(a==4){printf("5");}

			if(a==5){printf("6");}

			if(a==6){printf("7");}

			if(a==7){printf("8");}

			if(a==8){printf("9");}


			if(b==0){printf("1");}

			if(b==1){printf("2");}

			if(b==2){printf("3");}

			if(b==3){printf("4");}

			if(b==4){printf("5");}

			if(b==5){printf("6");}

			if(b==6){printf("7");}

			if(b==7){printf("8");}

			if(b==8){printf("9");}


			if(c==0){printf("1");}

			if(c==1){printf("2");}

			if(c==2){printf("3");}

			if(c==3){printf("4");}

			if(c==4){printf("5");}

			if(c==5){printf("6");}

			if(c==6){printf("7");}

			if(c==7){printf("8");}

			if(c==8){printf("9");}


			printf("%c",(char)9);

			for(a=0;a<9;++a){for(b=0;b<9;++b){for(c=0;c<9;++c){
				if(ba9[a][b][c][0]==l){break;}
			}if(c!=9){break;}}if(b!=9){break;}}

			if(a==0){printf("1");}

			if(a==1){printf("2");}

			if(a==2){printf("3");}

			if(a==3){printf("4");}

			if(a==4){printf("5");}

			if(a==5){printf("6");}

			if(a==6){printf("7");}

			if(a==7){printf("8");}

			if(a==8){printf("9");}


			if(b==0){printf("1");}

			if(b==1){printf("2");}

			if(b==2){printf("3");}

			if(b==3){printf("4");}

			if(b==4){printf("5");}

			if(b==5){printf("6");}

			if(b==6){printf("7");}

			if(b==7){printf("8");}

			if(b==8){printf("9");}


			if(c==0){printf("1");}

			if(c==1){printf("2");}

			if(c==2){printf("3");}

			if(c==3){printf("4");}

			if(c==4){printf("5");}

			if(c==5){printf("6");}

			if(c==6){printf("7");}

			if(c==7){printf("8");}

			if(c==8){printf("9");}


			printf("%c%06d\n",(char)9,ba16[i][j][k][l][1]);
			//printf("\n");

		}

	}}}}

	}

	return(0);

}