//	This source and similar text sequences 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.

//  Similar Text Sequences 
//	written by Dzinleski Jasenko  August 2016

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

FILE		*f1,*f2;

char		infn[256]="out_s2_s16.txt";
char		cns[256]="1111111111111111";
char		cks[256]="1111111111111111";

char		cv[256];int cvi=0;

int			cic[32][2];
int			ckc[32];
int			cna[32][3];

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

int	a,b;
int	i,j,k,l,m,n;
int	fb;
int	nc=1;
int	v;
int c[32];

	if(argc<3){return(0);}
	if(strlen(argv[1])==0){return(0);}
	if(strlen(argv[2])==0){return(0);}
	if(strlen(argv[3])==0){return(0);}
	strcpy(infn,argv[1]);
	strcpy(cns,argv[2]);
	strcpy(cks,argv[3]);
	if(strlen(cns)!=32){return(0);}
	if(strlen(cks)!=32){return(0);}
	
	for(i=0;i<strlen(cns);++i){if(cns[i]=='1'){cna[i][0]=1;}else{cna[i][0]=0;}}
	for(i=0;i<strlen(cks);++i){if(cks[i]=='1'){cna[i][1]=1;}else{cna[i][1]=0;}}

	f1=fopen(infn,"rb");
	fb=getc(f1);
	while(!feof(f1))
	{
		cvi=0;while((fb!=10)&&(fb!=13)){cv[cvi]=fb;++cvi;fb=getc(f1);}
		while((fb==10)||(fb==13)){fb=getc(f1);}

		for(i=0;i<cvi&&i<64;++i){if(cv[i]>='0'&&cv[i]<='9'){}else{break;}}
		if(i!=64){continue;}++nc;
		//printf("%s\n",cv);

		i=0;
		v=10*(-48+(int)cv[0] )+(-48+(int)cv[1] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[2] )+(-48+(int)cv[3] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[4] )+(-48+(int)cv[5] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[6] )+(-48+(int)cv[7] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[8] )+(-48+(int)cv[9] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[10])+(-48+(int)cv[11]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[12])+(-48+(int)cv[13]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[14])+(-48+(int)cv[15]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[16])+(-48+(int)cv[17]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[18])+(-48+(int)cv[19]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[20])+(-48+(int)cv[21]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[22])+(-48+(int)cv[23]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[24])+(-48+(int)cv[25]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[26])+(-48+(int)cv[27]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[28])+(-48+(int)cv[29]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[30])+(-48+(int)cv[31]);cna[i][2]=v;++i;

		v=10*(-48+(int)cv[32] )+(-48+(int)cv[33] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[34] )+(-48+(int)cv[35] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[36] )+(-48+(int)cv[37] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[38] )+(-48+(int)cv[39] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[40] )+(-48+(int)cv[41] );cna[i][2]=v;++i;
		v=10*(-48+(int)cv[42])+(-48+(int)cv[43]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[44])+(-48+(int)cv[45]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[46])+(-48+(int)cv[47]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[48])+(-48+(int)cv[49]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[50])+(-48+(int)cv[51]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[52])+(-48+(int)cv[53]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[54])+(-48+(int)cv[55]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[56])+(-48+(int)cv[57]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[58])+(-48+(int)cv[59]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[60])+(-48+(int)cv[61]);cna[i][2]=v;++i;
		v=10*(-48+(int)cv[62])+(-48+(int)cv[63]);cna[i][2]=v;++i;
		
		for(i=0;i<32;++i){c[i]=0;}
		for(i=0;i<32;++i){if(cna[i][0]){if(cna[i][2]){++c[i];}}else{if(!cna[i][2]){++c[i];}}}
		for(i=0;i<32;++i){if(!cna[i][1]){}else{if(c[i]){}else{break;}}}
		if(i==32){for(j=0;j<cvi;++j){printf("%c",cv[j]);}printf("\n");}

	}
	return(0);

}