//	This source and text sequencing method apply to GNU General Public License. 
//			Copyright (C) 2003  Jasenko Dzinleski 

//	This source applies to the GNU General Public License as
//	published by the Free Software Foundation 
//	and can not be used, copied, sold, redistributed or 
//	used in any other way but only by written permission by Jasenko Dzinleski . 
//	Copyright (C) from 2003 - 2014 and later by Jasenko Dzinleski 

//	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 longest reocuring string
//		written by Dzinleski Jasenko  2003 - 02 , December , 2014
//


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

FILE		*f1,*f2,*f3;

char		infn[256]="fasta__.txt";
//char		infn[256]="War_and_Peace_NT.txt";
char		outfn[256]="v_.txt";
char		outfn_[256]="out.txt";

int 		ba2b[256][256][256][2];	int ba2bi=0;
int 		bab[256][2][50000];	int babi=0;
int 		bab_[256][50000];	int babi_=0;

char		ca[8*1024];		int cai=0;
char		fs[8*1024];		int fsi=0;

//

char		csv[256];		int csvi=0;

char		cv[256];int cvi=0;
char		nl[256];int nli=0;

//
char		sv1_[256];
char		sv2_[256];
char		sv3_[256];
char		sv4_[256];
char		sv5_[256];
char		sv6_[256];
char		sv7_[256];
char		sv8_[256];

int		c1,c2,c3,c4,c5,c6,c7,c8,c9;
int		c1_,c2_,c3_,c4_,c5_,c6_,c7_,c8_,c9_;
//


int p_1(char sv1[256],char sv2[256],char sv3[256],char sv4[256],char sv5[256],char sv6[256],char sv7[256],char sv8[256])
{

int sv1i=strlen(sv1);
int sv2i=strlen(sv2);
int sv3i=strlen(sv3);
int sv4i=strlen(sv4);
int sv5i=strlen(sv5);
int sv6i=strlen(sv6);
int sv7i=strlen(sv7);
int sv8i=strlen(sv8);

int	a,b,d,e;
int	i,j,k,l,m,n;
int	fb;
int	nc=1;

	c1_=0;c2_=0;c3_=0;c4_=0;c5_=0;c6_=0;c7_=0;c8_=0;c9_=0;
	f3=fopen(infn,"rb");
	fb=getc(f3);
	while(!feof(f3))
	{
		cvi=0;while((fb!=10)&&(fb!=13)){cv[cvi]=fb;++cvi;fb=getc(f3);}
		if(nli==0){while((fb==10)||(fb==13)){nl[nli]=fb;++nli;fb=getc(f3);}}else{
			j=0;while((fb==10)||(fb==13)){if(nl[j]==fb){++j;if(j==nli){j=0;++nc;}}fb=getc(f3);}
		}

		//printf("%s\n",cv);

		c1=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv1);++j){if(sv1[j]!='_'){if(sv1[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv1)){++c1;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c2=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv2);++j){if(sv2[j]!='_'){if(sv2[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv2)){++c2;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c3=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv3);++j){if(sv3[j]!='_'){if(sv3[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv3)){++c3;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c4=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv4);++j){if(sv4[j]!='_'){if(sv4[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv4)){++c4;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c5=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv5);++j){if(sv5[j]!='_'){if(sv5[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv5)){++c5;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c6=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv6);++j){if(sv6[j]!='_'){if(sv6[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv6)){++c6;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c7=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv7);++j){if(sv7[j]!='_'){if(sv7[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv7)){++c7;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		c8=0;for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		for(k=0;k<cvi;++k)
		{
			m=0;for(j=0;j<strlen(sv8);++j){if(sv8[j]!='_'){if(sv8[j]!=cv[j+k]){break;}else{++m;csv[csvi]=cv[j+k];++csvi;}}else{++m;csv[csvi]=cv[j+k];++csvi;}}
			if(strlen(csv)==strlen(sv8)){++c8;/*break;*/}
			for(i=0;i<256;++i){csv[i]='\0';}csvi=0;
		}

		if(c1>=1||c2>=1||c3>=1||c4>=1||c5>=1||c6>=1||c7>=1||c8>=1)
		{
			c1_+=c1;c2_+=c2;c3_+=c3;c4_+=c4;c5_+=c5;c6_+=c6;c7_+=c7;c8_+=c8;if(c1>=1&&c2>=1&&c3>=1&&c4>=1&&c5>=1&&c6>=1&&c7>=1&&c8>=1){++c9_;}
			/*
			printf("%02d%02d%02d%02d%02d%02d%02d%02d\t",c1,c2,c3,c4,c5,c6,c7,c8);
			for(j=0;j<cvi;++j){printf("%c",cv[j]);}
			printf("\t%s\t%s",csv,sv1);printf("\t%d\n",nc);
			*/
		}
	}
	fclose(f3);
	return(0);

}

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

int	a,b,c,d,e,lc;
int	i,j,k,l,m,n;
int	b1_,b2_,b3_,b4_,b5_;
int	b1,b2,b3,b4;

	for(i=0;i<256;++i){
	for(j=0;j<256;++j){
	for(k=0;k<256;++k){
		ba2b[i][j][k][0]=-1;
	}}}ba2bi=0;

	for(i=0;i<256;++i){
	for(j=0;j<50000;++j){
		bab[i][0][j]=-1;
		bab[i][1][j]=0;
	}}babi=0;

	for(i=0;i<256;++i){
	for(j=0;j<50000;++j){
		bab_[i][j]=0;
	}}babi_=0;

	f1=fopen(infn,"rb");

	b1_=getc(f1);
	b2_=getc(f1);
	b3_=getc(f1);
	b4_=getc(f1);
	b5_=getc(f1);

	while(!feof(f1))
	{

	if(
	ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]==-1
	)
	{
	ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]=ba2bi;	
	if(bab[(b4_&0xff)][0][ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]]==-1)
	{
	bab[(b4_&0xff)][0][ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]]=babi;
	++bab_[(b5_&0xff)][babi];
	++babi;
	++bab[(b4_&0xff)][1][ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]];
	}else{++bab[(b4_&0xff)][1][ba2b[(b1_&0xff)][(b2_&0xff)][(b3_&0xff)][0]];++bab_[(b5_