Consider a directed graph with vertices and all the possible arcs, some of which are painted. How many Hamiltonian paths are in the graph starting at vertex 0, ending at vertex , and such that they do not traverse two consecutive painted arcs?
Input consists of several cases. Every case begins with , followed by an matrix, where the position has the color of the arc from vertex to vertex . A one indicates a painted arc, and a zero a non-painted arc. The diagonal (which is useless) only has zeroes. You can assume .
For every case, print the number of permutations of the vertices that start at 0, end at , and do not have three consecutive vertices , and such that the two arcs and are both painted. The test cases are such that the answer is smaller than .
Input
2 0 1 1 0 3 0 1 1 1 0 0 1 1 0 3 0 1 0 0 0 1 0 0 0 5 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0
Output
1 1 0 4