import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.lang.String;
public class tilegen2 {
	
	int array[][] = new int[1000][4];
	int num_compu_rows;
	static Formatter output;
	
	int glue_table[][] = new int[3000][100];
	int index;int numglu;
	int array1[] = new int[100];
	public int compuRows()
	{
		return num_compu_rows;
	}
	public int[] getIndex()
	{
		return array1;
	}
	public int glunum()
	{
		return numglu;
	}
	public int[][] compuglues()
	{
		return array;
	}
	public int[][] getGlue_table()
	{
	
		return glue_table;
	}
	
	public int getMaxGlue()
	{
		return index;
	}
	
	static int tobin(int x1,int x2)
	{
		
		//System.out.printf("\nx1=%d,x2=%d",x1,x2);
		int x3,x4;
		x3=0;
		x4=0;
		
		int n=0;
		do{
			int pw=1;
			for(int t=0;t<n;t++)
			{
				pw=pw*10;
			}
			x3=x1%2;
			x1=x1/2;
			x4=x4+(x3+4)*pw;
			n++;
			x2--;
			if(x2==0) break;
		}while(x1>0);
		
		if(x2>0)
		{
			do
			{
				int pw=1;
				for(int t=0;t<n;t++)
				{
					pw=pw*10;
				}
				x4=x4+(4)*pw;
				n++;
				x2--;
			}while(x2>0);	
		}
		
		return x4;
		
		
	}
        
    public void computation(int size_north,int size_east,int size_south,int size_west,String north_ip[],String east_ip[],String south_ip[],String west_ip[])
    {
            Scanner input = new Scanner(System.in);
            
            String[] iptable = new String[1000];
            String[] uiptable = new String[1000];
            int[] lctable = new int [1000];
            int x=0;
  			int nx=0;
            //int size_north,size_south,size_east,size_west;
			int n,flag;
			flag=0;n=0;            
            //System.out.printf("welcome to tilegen !!\n");
            //System.out.printf("How many inputs for side NORTH ? please enter them too");
            //size_north = input.nextInt();
            String[] a1 =new String[size_north];
            for(int i=0;i<size_north;i++)
            {
              a1[i] = north_ip[i];
            System.out.printf("\n");
            flag=0;
            char[] a11 = a1[i].toCharArray();
            for(int j=0; j<a1[i].length();j++)
            {
            	if(a11[j]=='+' || a11[j]=='.' || a11[j]=='^' || a11[j]=='~') flag=1;
            }
            iptable[x]= a1[i];
            x++;
            if(flag==0)
            {
            	 lctable[n]= i;
            	 n++;
            }	
            
 			}
 			
 			
            //System.out.printf("How many inputs for side EAST ? please enter them too");
            //size_east = input2.nextInt();
            String[] a2 =new String[size_east];
            for(int i=0;i<size_east;i++)
            {
              a2[i] = east_ip[i];
            System.out.printf("\n");
            flag=0;
            char[] a12 = a2[i].toCharArray();
            for(int j=0; j<a2[i].length();j++)
            {
            	if(a12[j]=='+' || a12[j]=='.' || a12[j]=='^' || a12[j]=='~') flag=1;
            }
            iptable[x]= a2[i];
            x++;
            if(flag==0)
            {
            	 lctable[n]= i;
            	 n++;
            }	
            
 			}
 			
 		
            //System.out.printf("How many inputs for side SOUTH ? please enter them too");
            //size_south = input4.nextInt();
            String[] a3 =new String[size_south];
            for(int i=0;i<size_south;i++)
            {
              a3[i] = south_ip[i];
            System.out.printf("\n");
            flag=0;
            char[] a13 = a3[i].toCharArray();
            for(int j=0; j<a3[i].length();j++)
            {
            	if(a13[j]=='+' || a13[j]=='.' || a13[j]=='^' || a13[j]=='~') flag=1;
            }
            iptable[x]= a3[i];
           	x++;
            if(flag==0)
            {
            	 lctable[n]= i;
            	 n++;
            }	
            
 			}
 			
 			
            //System.out.printf("How many inputs for side WEST ? please enter them too");
            //size_west = input6.nextInt();
            String[] a4 =new String[size_west];
            for(int i=0;i<size_west;i++)
            {
              a4[i] = west_ip[i];
            System.out.printf("\n");
            flag=0;
            char[] a14 = a4[i].toCharArray();
            for(int j=0; j<a4[i].length();j++)
            {
            	if(a14[j]=='+' || a14[j]=='.' || a14[j]=='^' || a14[j]=='~') flag=1;
            }
            iptable[x]= a4[i];
            x++;
            if(flag==0)
            {
            	 lctable[n]= i;
            	 n++;
            }	
            
 			}
 			
 			
 			for(int b=0;b<x;b++)
 			{
 				uiptable[b]=iptable[b];
 			}
 			
 			nx=x;
 			for(int q=0;q<x;q++)
 			{
 				for(int w=0;w<x;w++)
 				{
 					 int chkflag=0;
           			 char[] chkk = iptable[w].toCharArray();
            		for(int j=0; j<iptable[w].length();j++)
            		{
            			if(chkk[j]=='+' || chkk[j]=='.' || chkk[j]=='^' || chkk[j]=='~') chkflag=1;
           			 }
 					if(iptable[q].compareTo(iptable[w]) == 0 && w!=q && chkflag==0)
 					{	int e;
 						for(e=w;e<x-1;e++)
 						{
 							iptable[e]=iptable[e+1];
 							
 						}
 						iptable[e]="\0";
 						x--;
 					}
 				}
 			}
 			
 		/*	 			
 			System.out.printf("the iptable is\n");
 			for(int y1=0;y1<x;y1++)
 			{
 				System.out.printf("%s\t", iptable[y1]);
 			}
 			System.out.printf("\nthe uiptable is\n");
 			for(int y2=0;y2<nx;y2++)
 			{
 				System.out.printf("%s\t", uiptable[y2]);
 			}
 			
 			*/
 			n=n-(nx-x);
 			
 			
 			 
 		//	System.out.printf("\n no. of independent inputs is %d\n",n);
 			int c=nx;
 			int r=2;
 			for(int y=1;y<n;y++)
 			{
 				r=r*2;
 			}
 			//System.out.printf("r==%d, c==%d\n",r,c);
 			
 			int[][] arr = new int[r][c];
 			for(int a=0;a<r;a++)
 			{	
 				for(int b=0;b<c;b++)
 				{
 					arr[a][b]=0;
 				}
 				
 			}
 			
 			int c2=x;
 			int r2=2;
 			for(int y=1;y<n;y++)
 			{
 				r2=r2*2;
 			}
 			//System.out.printf("r==%d, c==%d\n",r,c);
 			
 			int[][] arr2 = new int[r2][c2];
 			for(int a=0;a<r2;a++)
 			{	
 				for(int b=0;b<c2;b++)
 				{
 					arr2[a][b]=0;
 				}
 				
 			}
 			
 		/*	for(int y=0;y<nx;y++)
 			{
 				System.out.printf("%s\t", uiptable[y]);
 			}
 			System.out.printf("\n");
 			for(int a=0;a<r;a++)
 			{	
 				for(int b=0;b<c;b++)
 				{
 					System.out.printf("%d\t",arr[a][b]);
 					System.out.printf("");
 				}
 				System.out.printf("\n");
 			}*/
 			n++;
 			for(int gg=0;gg<x;gg++)
 			{
 				flag=0;
 				
            	char[] ch = iptable[gg].toCharArray();
            	for(int j=0; j<iptable[gg].length();j++)
            	{
            		if(ch[j]=='+' || ch[j]=='.' || ch[j]=='^' || ch[j]=='~') flag=1;
            	}
            	if(flag==0)
            	{	
            		n=n-1;
            		//System.out.printf("\nn=%d\n",n);
            		int r1=1;
 					for(int y=1;y<n;y++)
 					{
 						r1=r1*2;
 					}
 					int start=0;
 					int end=r1;
 					int val=0;
 					//System.out.printf("\n gg=%d r1=%d \n",gg,r1);
 					do
 					{	//System.out.printf("\n gg=%d start=%d end=%d val=%d\n",gg,start,end,val);
 						for(int xs=start;xs<end;xs++)
 						{
 							arr2[xs][gg]=val;//System.out.printf("\nhere %d\n",val);
 						}
 						val=1-val;
 						start=end;
 						end=end+r1;
 						
 					}while((r+1)>end);
 					
 				}
 			}
 			
 		/*	System.out.printf("\nthe changed iptable is\n");
 			for(int y1=0;y1<x;y1++)
 			{
 				System.out.printf("%s\t", iptable[y1]);
 			}
 			System.out.printf("\n");
 			for(int a=0;a<r2;a++)
 			{	
 				for(int b=0;b<c2;b++)
 				{
 					System.out.printf("%d\t",arr2[a][b]);
 					System.out.printf("");
 				}
 				System.out.printf("\n");
 			}		
    */
    //infix to postfix
    String[] piptable = new String[1000];
    for(int g=0;g<nx;g++)
    {
    	char[] inf = uiptable[g].toCharArray();
    	
    	char[] stk = new char[uiptable[g].length()];
    	char[] pof = new char[uiptable[g].length()];
    	int op=0;
    	int pp=0;
    	for(int g1=0;g1<uiptable[g].length();g1++)
    	{
    		if(inf[g1]=='+' || inf[g1]=='.' || inf[g1]=='^' || inf[g1]=='~')
    		{
    			
    			stk[op] = inf[g1];//System.out.printf("\nstk=%c\n",stk[op]);
    			op++;
    		}	
    		
    		else if(inf[g1]=='(')
    		{
    			
    			stk[op] = inf[g1];//System.out.printf("\nstk=%c\n",stk[op]);
    			op++;
    		}
    		else if(inf[g1]==')')
    		{
    			op--;
    			do
    			{	
    				pof[pp]=stk[op];//System.out.printf("\npof=%c\n",pof[pp]);
    				op--;
    				pp++;
    			}while(stk[op]!='(');
    			
    		}
    		else
    		{
    			pof[pp]=inf[g1];//System.out.printf("\npof=%c\n",pof[pp]);
    			pp++;
    		}
    		
    	}
    	//System.out.printf("\n pp=%d op=%d\n",pp,op);
    	if(pp!=uiptable[g].length())
    		{//System.out.printf("\nhello  pof=%c pp=%d op=%d\n",pof[pp],pp,op);
    			do{
    				
    				op--;
    				pof[pp]=stk[op];//System.out.printf("\npof=%c stk=%c\n",pof[pp],stk[op]);
    				
    				pp++;
    				
    			  }while(op>0);
    		}
    	piptable[g]="";
    	for(int g2=0;g2<pp;g2++)
    	{
    		piptable[g]=String.valueOf(pof[g2]) + piptable[g];
    	}	
    	
    	String reversed = "";
            for (int i=0; i<pp; i++) {
                reversed = piptable[g].substring(i, i+1) + reversed;
            }
		piptable[g] = reversed;
    	
    	
    	
    	
    }
  /*  System.out.printf("\nthe piptable is\n");
 	for(int yn=0;yn<nx;yn++)
 	{
 		System.out.printf("%s\t", piptable[yn]);
 	}
 	*/
 
 	System.out.printf("\n");
 	
 	//evaluating postfix
 	
 	
    for(int gx=0;gx<nx;gx++)
    {
    char[] chal = piptable[gx].toCharArray();
    int[] stk = new int[piptable[gx].length()];
    
    for(int gy=0;gy<r;gy++)
    {
    	
    	int gs=0;
    	int go=0; 
    	for(int gt=0;gt<piptable[gx].length();gt++)
    	{	
    		//System.out.printf("\nA:chal==%c\n",chal[gt]);
    		if(chal[gt]=='+' || chal[gt]=='.' || chal[gt]=='^' || chal[gt]=='~')
    		{
    			
    			if(chal[gt]=='+')
    			{	//System.out.printf("\n or gate \n");
    				gs--;int t2 = stk[gs];//System.out.printf("\n1+gs=%d",gs);
    				gs--;int t1 = stk[gs];//System.out.printf("\n2+gs=%d",gs);
    				//System.out.printf("\nt1=%d t2=%d",t1,t2);
    				if(t1==0 && t2==0)stk[gs]=0;
    				else stk[gs]=1;
    				gs++;
    			}
    			else if(chal[gt]=='.')
    			{	//System.out.printf("\n and gate \n");
    				gs--;int t2 = stk[gs];//System.out.printf("\n1.gs=%d",gs);
    				gs--;int t1 = stk[gs];//System.out.printf("\n2.gs=%d",gs);
    				//System.out.printf("\nt1=%d t2=%d",t1,t2);
    				if(t1==1 && t2==1)stk[gs]=1;
    				else stk[gs]=0;
    				gs++;
    			}
    			else if(chal[gt]=='^')
    			{	//System.out.printf("\n xor gate \n");
    				gs--;int t2 = stk[gs];//System.out.printf("\n1^gs=%d",gs);
    				gs--;int t1 = stk[gs];//System.out.printf("\n2^gs=%d",gs);
    				//System.out.printf("\nt1=%d t2=%d",t1,t2);
    				if(t1==1 && t2==0)stk[gs]=1;
    				else if(t1==0 && t2==1)stk[gs]=1;
    				else stk[gs]=0;
    				gs++;
    			}
    			else if(chal[gt]=='~')
    			{	//System.out.printf("\n not gate \n");
    				gs--;
    				int t1=1-stk[gs];
    				//System.out.printf("\nt1=%d\n",t1);
    				stk[gs]=t1;
    				gs++;
    			}
    			//System.out.printf("\nB:stk==%d gs==%d\n",stk[gs],gs);
    		}
    		
    		else
    		{   //System.out.printf("\nB:chal==%c\n",chal[gt]);
    			
    			
    			int mark=0;
    			String ttg = String.valueOf(chal[gt]);
    			//System.out.printf("\nttg=%s\n",ttg);
    			for(int s=0;s<x;s++)
    			{
    				
    				if(ttg.compareTo(iptable[s])==0) mark=s;
    			}
    			//System.out.printf("\ngs=%d gy=%d mark=%d\n",gs,gy,mark);
    			stk[gs]=arr2[gy][mark];//System.out.printf("stk[gs]=%d\t",stk[gs]);
    			gs++;
    		}
    	
    	}
    	//System.out.printf("\ngy=%d gx=%d gs=%d\n",gy,gx,gs);
    	if(gs>0)gs--;
    	arr[gy][gx]=stk[gs];
    	//System.out.printf("\n___________________%d\n",arr[gy][gx]);
    	
    	
    	}
    }
/*    System.out.printf("\nthe uiptable is\n");
 	for(int y2=0;y2<nx;y2++)
 	{
 		System.out.printf("%s\t", uiptable[y2]);
 	}
 	System.out.printf("\n");
    for(int a=0;a<r;a++)
 	{	
 		for(int b=0;b<c;b++)
 		{
 			System.out.printf("%d\t",arr[a][b]);
 			System.out.printf("");
 		}
 		System.out.printf("\n");
 	}*/
    for(int a=0;a<r;a++)
 	{	
 		for(int b=0;b<c;b++)
 		{
 			if(arr[a][b]==0) arr[a][b]=4;
 			else arr[a][b]=5;
 		}
 		
 	}
 /*	System.out.printf("\n for ur info\n");
 	for(int a=0;a<r;a++)
 	{	
 		for(int b=0;b<c;b++)
 		{
 			System.out.printf("%d\t",arr[a][b]);
 			System.out.printf("");
 		}
 		System.out.printf("\n");
 	}*/
    int[] gv = new int[4]; 
    gv[0]=size_north;
    gv[1]=size_east;
    gv[2]=size_south;
    gv[3]=size_west;
    int lgv=4;
  /*  System.out.printf("\nA: the lgv is \n");
    for(int w4=0;w4<lgv;w4++)
    {
    	System.out.printf("%d\t",gv[w4]);
    }*/
    for(int w1=0;w1<lgv;w1++)
    {
    	for(int w2=0;w2<lgv;w2++)
    	if(gv[w1]==gv[w2] && w1!=w2)
    	{
    		int w3;
    		//System.out.printf("\n%d==%d",w1,w2);
    	   	for(w3=w2;w3<lgv-1;w3++)
    		{
    			gv[w3]=gv[w3+1];
    		}
    		gv[w3]=0;
    		lgv--;
    	}	
    }
    
   /* System.out.printf("\nB: the lgv is \n");
    for(int w4=0;w4<lgv;w4++)
    {
    	System.out.printf("%d\t",gv[w4]);
    }*/
    
    for(int v1=0;v1<lgv;v1++)
    {
    	for(int v2=0;v2<(lgv-1);v2++)
    	{
    		if(gv[v2]>gv[v2+1])
    		{
    			int temp=gv[v2];
    			gv[v2]=gv[v2+1];
    			gv[v2+1]=temp;
    		}
    	}
    }
    System.out.printf("\nr=%d",r);
  /*  System.out.printf("\nC: the lgv is \n");
    for(int w4=0;w4<lgv;w4++)
    {
    	System.out.printf("%d\t",gv[w4]);
    }
    */
    
    int nullflag=0;
    int[][] gc = new int[5000][3];
    int lgc=0;
    //int pri=0;
    int w1=0;
    int w4=0;
    
    for(int q1=0;q1<lgv;q1++)
    {
    	int w2=gv[q1];
    	if(w1<w2) w1=w1+w2;
    	int esl = 2;
    	for(int es=1;es<gv[q1];es++)
    	{
    		esl = esl*2;
    	}
    	//pri=pri+esl;
    	if(gv[q1]==0) esl=0;
    	//System.out.printf("\nesl=%d",esl);
    	if(esl==0)
    	{
    		gc[lgc][0] = 0;
    		gc[lgc][1] = 0;
    		gc[lgc][2] = 3;
    		lgc++;nullflag=1;
    	}
    	
    	
    	
    	for(int q2=0;q2<esl;q2++)
    	{
    		
    		
    		
    		gc[lgc][0] = w4;
    		
    		gc[lgc][1] = w2;
    		gc[lgc][2] = tobin(w1,w2);//System.out.printf("\nw1=%d, w2=%d, w4=%d\n",w1,w2,w4);
    		gc[lgc][0]++;
    		lgc++;w1++;w4++;
    	}
    	
    	  	
    }
    
 /*   
    System.out.printf("\n the glues array\n");
    for(int vb=0;vb<lgc;vb++)
    {
    	System.out.printf("\nhere !! %d\t%d\t%d",gc[vb][0],gc[vb][1],gc[vb][2]);
    }
    System.out.printf("\n");
   */ 
   
   
   index = 0;
   int index2;
   glue_table[0][0]=0;
   int ptr = 0;
   array1[0] = 0;
    System.out.printf("\n in binary format..the glues we have used are\n");
    System.out.printf("\nGlue no \tno. of bits\tbinary code");
    for(int vb=0;vb<lgc;vb++)
    {	
    	System.out.printf("\n%d\t\t%d\t\t",gc[vb][0],gc[vb][1]);
    	
    	
    	int tv = gc[vb][2];
    	//System.out.printf("\ngg %d=",tv);
    	
    		int temp=tv;
    		int pww=1;
    		int pkr=0;
    		do
    		{	
    			temp=temp/10;
    			pkr++;
    		}while(temp>0);
    		
    		for(int nc=1;nc<pkr;nc++)
    		{
    			pww=pww*10;
    		}
    		
    		int temp1=0;
    		
    		do
    		{
    			int ug1 = tv%10;
    			temp1=temp1+pww*ug1;
    			tv=tv/10;pww=pww/10;
    		}while(tv>0);
    		
    		tv=temp1;
    		//System.out.printf("\nff %d=",tv);
    		
    		index2=0;
    		index++;
    		ptr++;
    		
    	do{
    		int tp = tv%10;
    		if(tp==4)
    		{
    			 System.out.printf("0");
    			 glue_table[index][index2]=0;
    			 index2++;
    			 array1[ptr] = index2;
    		}
    		
    		else 
    		if(tp==5) 
    		{
    			System.out.printf("1");
    			glue_table[index][index2]=1;
    			index2++;
    			array1[ptr] = index2;
    		}
    		else if(tp==3) System.out.printf("null");
    		tv=tv/10;
    	}while(tv>0);
    }
    
    //north glues array
    int[][] nga = new int[r][2];
    if(size_north == 0)
    {
    	for(int zt=0;zt<r;zt++)
    	{
    	   	nga[zt][0]=3;
    		nga[zt][1]=0;
    	}
    }
    else
    {
    	int ft=1;
    	for(int tf=0;tf<size_north;tf++)
    	{
    		ft=ft*2;
    	}
    	for(int v=0;v<r;v++)
    	{
    		nga[v][0]=0;
    	}
    	for(int g1=0;g1<r;g1++)
    	{
    		int pwo=1;
    		for(int g2=0;g2<size_north;g2++)
    		{
    			nga[g1][0]=nga[g1][0]+arr[g1][g2]*pwo;
    			pwo=pwo*10;
    		
    		}
    		
    	
    		int temp=nga[g1][0];
    		int pww=1;
    		int pkr=0;
    		do
    		{	
    			temp=temp/10;
    			pkr++;
    		}while(temp>0);
    		
    		for(int nc=1;nc<pkr;nc++)
    		{
    			pww=pww*10;
    		}
    		
    		int temp1=0;
    		
    		do
    		{
    			int ug1 = nga[g1][0]%10;
    			temp1=temp1+pww*ug1;
    			nga[g1][0]=nga[g1][0]/10;pww=pww/10;
    		}while(nga[g1][0]>0);
    		
    		nga[g1][0]=temp1;
    		for(int g3=0;g3<lgc;g3++)
    		{
    			if(nga[g1][0]==gc[g3][2]){nga[g1][1]=gc[g3][0];break;}
    		}
    		
    		
    	}
    
	}
	
	
	//east glues array
    int[][] ega = new int[r][2];
    if(size_east == 0)
    {
    	for(int zt=0;zt<r;zt++)
    	{
    	   	ega[zt][0]=3;
    		ega[zt][1]=0;
    	}
    }
    else
    {
    	int ft=1;
    	for(int tf=0;tf<size_east;tf++)
    	{
    		ft=ft*2;
    	}
    	for(int v=0;v<r;v++)
    	{
    		ega[v][0]=0;
    	}
    	for(int g1=0;g1<r;g1++)
    	{
    		int pwo=1;
    		for(int g2=size_north;g2<size_east+size_north;g2++)
    		{
    			ega[g1][0]=ega[g1][0]+arr[g1][g2]*pwo;
    			pwo=pwo*10;
    		
    		}
    		
    	
    		int temp=ega[g1][0];
    		int pww=1;
    		int pkr=0;
    		do
    		{	
    			temp=temp/10;
    			pkr++;
    		}while(temp>0);
    		
    		for(int nc=1;nc<pkr;nc++)
    		{
    			pww=pww*10;
    		}
    		
    		int temp1=0;
    		
    		do
    		{
    			int ug1 = ega[g1][0]%10;
    			temp1=temp1+pww*ug1;
    			ega[g1][0]=ega[g1][0]/10;pww=pww/10;
    		}while(ega[g1][0]>0);
    		
    		ega[g1][0]=temp1;
    		for(int g3=0;g3<lgc;g3++)
    		{
    			if(ega[g1][0]==gc[g3][2]){ega[g1][1]=gc[g3][0];break;}
    		}
    		
    		
    	}
    
	}
	
	
	
	//south glues array
    int[][] sga = new int[r][2];
    if(size_south == 0)
    {
    	for(int zt=0;zt<r;zt++)
    	{
    	   	sga[zt][0]=3;
    		sga[zt][1]=0;
    	}
    }
    else
    {
    	int ft=1;
    	for(int tf=0;tf<size_south;tf++)
    	{
    		ft=ft*2;
    	}
    	for(int v=0;v<r;v++)
    	{
    		sga[v][0]=0;
    	}
    	for(int g1=0;g1<r;g1++)
    	{
    		int pwo=1;
    		for(int g2=size_north+size_east;g2<size_north+size_east+size_south;g2++)
    		{
    			sga[g1][0]=sga[g1][0]+arr[g1][g2]*pwo;
    			pwo=pwo*10;
    		
    		}
    		
    		
    		int temp=sga[g1][0];
    		int pww=1;
    		int pkr=0;
    		do
    		{	
    			temp=temp/10;
    			pkr++;
    		}while(temp>0);
    		
    		for(int nc=1;nc<pkr;nc++)
    		{
    			pww=pww*10;
    		}
    		
    		int temp1=0;
    		
    		do
    		{
    			int ug1 = sga[g1][0]%10;
    			temp1=temp1+pww*ug1;
    			sga[g1][0]=sga[g1][0]/10;pww=pww/10;
    		}while(sga[g1][0]>0);
    		
    		sga[g1][0]=temp1;
    		for(int g3=0;g3<lgc;g3++)
    		{
    			if(sga[g1][0]==gc[g3][2]){sga[g1][1]=gc[g3][0];break;}
    		}
    		
    		
    	}
    
	}
	
	//west glues array
    int[][] wga = new int[r][2];
    if(size_west == 0)
    {
    	for(int zt=0;zt<r;zt++)
    	{
    	   	wga[zt][0]=3;
    		wga[zt][1]=0;
    	}
    }
    else
    {
    	int ft=1;
    	for(int tf=0;tf<size_west;tf++)
    	{
    		ft=ft*2;
    	}
    	for(int v=0;v<r;v++)
    	{
    		wga[v][0]=0;
    	}
    	for(int g1=0;g1<r;g1++)
    	{
    		int pwo=1;
    		for(int g2=(size_south+size_east+size_north);g2<(size_south+size_east+size_north+size_west);g2++)
    		{
    			wga[g1][0]=wga[g1][0]+arr[g1][g2]*pwo;
    			pwo=pwo*10;
    		
    		}
    		
    		int temp=wga[g1][0];
    		int pww=1;
    		int pkr=0;
    		do
    		{	
    			temp=temp/10;
    			pkr++;
    		}while(temp>0);
    		
    		for(int nc=1;nc<pkr;nc++)
    		{
    			pww=pww*10;
    		}
    		
    		int temp1=0;
    		
    		do
    		{
    			int ug1 = wga[g1][0]%10;
    			temp1=temp1+pww*ug1;
    			wga[g1][0]=wga[g1][0]/10;pww=pww/10;
    		}while(wga[g1][0]>0);
    		
    		wga[g1][0]=temp1;
    		
    		
    		for(int g3=0;g3<lgc;g3++)
    		{
    			if(wga[g1][0]==gc[g3][2]){wga[g1][1]=gc[g3][0];break;}
    		}
    		
    		
    	}
    
	}
	
/*	System.out.printf("\nthe tiles glue array\n");
	for(int g4=0;g4<r;g4++)
	{
		System.out.printf("\n%d\t%d\t%d\t%d",nga[g4][1],ega[g4][1],sga[g4][1],wga[g4][1]);
	}
	System.out.printf("\n");
	
	System.out.printf("\nthe tiles glue array\n");
	for(int g4=0;g4<r;g4++)
	{
		System.out.printf("\n%d\t%d\t%d\t%d",nga[g4][0],ega[g4][0],sga[g4][0],wga[g4][0]);
	}*/
	System.out.printf("\n");
	if(nullflag==1) lgc--;
	int [][] glue_array = new int[r][4];
//	int sudh = input.nextInt();
	System.out.printf("no of glues used till now =%d\n",lgc);
	
	int g=0;
	for(int as=0;as<r;as++)
	{
		glue_array[as][0] = nga[g][1];
		glue_array[as][1] = ega[g][1];
		glue_array[as][2] = sga[g][1];
		glue_array[as][3] = wga[g][1];
		g++;
		
	}
	try
	{
	
	//	output = new Formatter("compu_glues.txt");
	
		
		System.out.printf("\n**************************************************");
		System.out.printf("\nThe final .tile file is");
		System.out.printf("\n**************************************************");
		System.out.printf("\ntile edges matches {{N E S W}*}");
		System.out.printf("\nnum tile types=%d",r);
		System.out.printf("\nnum binding types=%d",lgc);
		System.out.printf("\ntile edges={");
		
		numglu=r;
		for(int bh=0;bh<r;bh++)
		{
			array[bh][0] = glue_array[bh][0];
			array[bh][1] = glue_array[bh][1];
			array[bh][2] = glue_array[bh][2];
			array[bh][3] = glue_array[bh][3];
		}

		System.out.printf("\n}\nbinding strengths=\n{");
		
		
		num_compu_rows = r;
		for(int d1=0;d1<lgc;d1++)
		{
			System.out.printf("1\t");
			
		}
		
		System.out.printf("}\n");
		
	
		//output.close();
		
	}
	catch ( SecurityException securityException )
      	{
         System.err.println("You do not have write access to this file." );
         System.exit( 1 );
      	} // end catch
      /*	catch ( FileNotFoundException filesNotFoundException )
      	{
         System.err.println( "Error creating file." );
         System.exit( 1 );
      	} */// end catch
      	catch ( FormatterClosedException formatterClosedException )
        {
            System.err.println( "Error writing to file." );
            return;
        } // end catch
	
		
	}
}
     
           