//	This source and Segregation of Text Sequences by their Complexity method apply to GNU General Public License. 
//			Copyright (C) 2001-2014 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.

//  	Segregation of Text Sequences by their Complexity  
//	written by Dzinleski Jasenko  December 2016 , May 2017


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

FILE		*f1,*f2;

char		infn[256];
char		outfn[256];
char		sv[256];
int		ca[100][100];
int		ba16[256][256][2];int ba16i;
int		df=0;

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

int	i,j,k,l,m,n;
int	a,b,c;
int	fb;

	//if(argc<2){return(0);}
	if(strlen(argv[1])==0){return(0);}
	//if(strlen(argv[2])==0){return(0);}

	strcpy(infn,argv[1]);
	//strcpy(outfn,argv[2]);

	f1=fopen(infn,"rb");
	//f2=fopen(outfn,"wb");
	fb=getc(f1);
	while(!feof(f1))
	{
		for(i=0;i<256;++i){sv[i]='\0';}i=0;
		while((fb!=10)&&(fb!=13)){sv[i]=fb;++i;fb=getc(f1);}
		while((fb==10)||(fb==13)){fb=getc(f1);}

		for(i=0;i<256;++i){for(j=0;j<256;++j){ba16[i][j][0]=-1;ba16[i][j][1]=0;}}ba16i=0;
		for(i=0;i<100;++i){for(j=0;j<100;++j){ca[i][j]=-1;}}
		a=0;for(i=0;i<strlen(sv)-1;++i)
		{
			if(sv[i]==sv[i+1])
			{
				c=i;a=1;b=1+i;
				while(sv[c]==sv[b]&&b<strlen(sv)){++a;++b;}i=b-1;
				if(ca[a][0]==-1){ca[a][0]=1;}else{++ca[a][0];}ca[a][ca[a][0]]=c;}
		}
		//
		for(i=0;i<100;++i)
		{
		if(ca[i][0]!=-1){for(j=1;j<=ca[i][0];++j){
			if(ba16[i][(int)sv[ca[i][j]]][0]==-1)
			{ba16[i][(int)sv[ca[i][j]]][0]=ba16i;++ba16i;++ba16[i][(int)sv[ca[i][j]]][1];}else{++ba16[i][(int)sv[ca[i][j]]][1];}
		}}
		}
		//
		if(df)
		{
		printf("%s\t",sv);
		for(i=0;i<100;++i)
		{
			if(ca[i][0]!=-1){for(j=1;j<=ca[i][0];++j){printf("!%d!%c",i,sv[ca[i][j]]);}}
		}
		printf("\n");
		}
		//
		//printf("%s\t",sv);
		//for(i=0;i<256;++i){for(j=0;j<256;++j){if(ba16[i][j][0]!=-1){printf("%d!%c!%d\t",i,j,ba16[i][j][1]);}}}
		//printf("\n");
		//
		b=0;for(i=0;i<256;++i){for(j=0;j<256;++j){if(ba16[i][j][0]!=-1){if(i>2){++b;}}}}
		if(!b){printf("%s\n",sv);}


	}
	fclose(f1);
	//fclose(f2);

	return(0);

}