import java.util.Hashtable;

public class sim
{
    public static void main(String args[]) {
        int stuff[];
        stuff = new int[15];
 /*       for (int lcv=0;lcv<15;lcv++) stuff[lcv] = 0;
        stuff[1] = 1;
        stuff[2] = 2;
        stuff[4] = 1;
        stuff[5] = 2;
        stuff[6] = 1;
        stuff[9] = 2;
        stuff[10] = 2;
        SimGrid foo = new SimGrid(stuff);
        System.out.println(foo);
        foo.simplify();
        System.out.println(foo);
 */      
        
        for (int lcv=0;lcv<15;lcv++) stuff[lcv] = 0;
        
        sim.placeMoves(0,stuff,0);
        stuff[0] = 2;
        for (int moves=1;moves<16;moves++) {
            sim.placeMoves(1,stuff,moves);
        }
    }
    
    public static void placeMoves(int move,int[] stuff,int maxmoves) {
        if (move < maxmoves) {
            int val = 2 - move % 2;
            int max = 14;
            while ((max >= 0) && (stuff[max] != val)) max--;
            for (int lcv = max+1;lcv<15;lcv++) if (stuff[lcv] == 0) {
                stuff[lcv] = val;
                placeMoves(move+1,stuff,maxmoves);
                stuff[lcv] = 0;
            }
        } else {
            SimGrid foo = new SimGrid(stuff);
            sim.checkFoo(foo,move);
            foo = null;
        }
    }
    
    private static Hashtable stuff = new Hashtable(300);
    private static final String yes = "Yes!";
    
    public static void checkFoo(SimGrid foo, int size) {
        foo.simplify();
        if (!stuff.containsKey(foo)) {
            stuff.put(foo,sim.yes);
            int propLoser = size % 2 + 1;
            if (size < 5)
                System.out.println(foo.toString() + " " + foo.triangleCount());
            else if (foo.triangleCount() == 0)
                System.out.println(foo.toString() + " " + foo.triangleCount());
            else if ((foo.triangleCount() == 1) && (foo.getLoser() == propLoser))
                System.out.println(foo.toString() + " " + foo.triangleCount() + " " + foo.getLoser());
        } else {
//            System.out.print(".");
//            System.out.flush();
        }
    }
    
    public static void increment(int[] stuff) {
        int lcv = 14;
        while (stuff[lcv] == 2) lcv--;
        stuff[lcv]++;
        lcv++;
        while (lcv < 15) {
            stuff[lcv] = 0;
            lcv++;
        }
    }
}