#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
	FILE *fp1,*fp2;
	int row1,column1,row2,column2;
	int *data1,*data2,*temp;
	int i,j;
	int di;
	
	if(argc!=3) {
		printf("Please input two files to compare\n");
		exit(1);
	}
	
	fp1 = fopen(argv[1],"r");
	fp2 = fopen(argv[2],"r");
	
	if(fp1==NULL || fp2 == NULL) {
		printf("Can't open file\n");
		exit(0);
	}
	
	fscanf(fp1,"%d%d",&row1,&column1);
	fscanf(fp2,"%d%d",&row2,&column2);
	
	data1 = new int[column1];
	data2 = new int[column1];
	temp = new int[2*column1];
	
	for(i=0;i<row1;i++) {
		for(j=0;j<column1;j++) {
			fscanf(fp1,"%d",&di);
			data1[j] = di;
		}
		
		for(j=0;j<2*column1;j++) {
			fscanf(fp2,"%d",&di);
			temp[j] = di;
		}
		
		for(j=0;j<column1;j++) {
			if(temp[j] == temp[j+column1])
				data2[j] = temp[j];
			else
				data2[j] = 2;
		}	
		
		//for(j=0;j<column1;j++) {
		//	printf("%d ",data2[j]);
		//}
		for(j=0;j<column1;j++) {
			if(data1[j] != data2[j]) {
				printf("Inconsistent in row %d and column %d.\n",i+1,j+1);
				return 0;
			}
		}
		//printf("\n");
	}
	
	printf("The output haplotypes have been verified: they do generate the input genotypes.\n");
	fclose(fp1);
	fclose(fp2);
	return 1;
}
