import choco.Problem;
import choco.Constraint;
import choco.Solver;
import choco.Solution;
import choco.Problem;
import choco.Constraint;
import choco.Solver;
import choco.Solution;
import choco.ContradictionException;
import choco.integer.IntVar;
import choco.search.AssignVar;

import java.io.*;
import java.lang.*;
import java.util.*;

public class FBuild {	
   

    public static void main(String[] args) throws Exception,ContradictionException,FileNotFoundException,IOException {
	
	Dict d = new Dict();
	MyIo fin = new MyIo(args[0]);
	int n = fin.getNextInt();
	Tree t[] = new Tree[n];
	for (int i=0;i<n;i++) t[i] = new Tree(fin.getNextString(),d);
	
	fin.close();

	Problem pb = new Problem();
	int m = d.size();

	UMatrix um = new UMatrix(m,pb,d,false);	
	
	for (int i=0;i<n;i++) t[i].breakUp(um);

	pb.solve(false);

	Tree t3 = um.toTree();
	System.out.println(t3);	
	System.out.println(um);
	System.out.println(d);
	um.showTriples();

    }
}
