(file name: latin.pl)

Tony schedules the conference talks for the conference. The aim is to fill in a 9 days of 9 slots grid with the talks of lengths from 1 through 9 minutes so that each digit 1 through 9 occurs exactly once in each row, exactly once in each column and exactly once in each of the 9 3-by-3 sub-squares subject to the following constraints. The constraints are on the sum of adjacent squares within each 3-by-3 sub-square. In the illustration below, the symbols <, = and > indicate that the sum of the values on either side (or above and below), the symbol must have sum less than 10, equal to 10 or greater than 10, respectively.

However, Tony finds out that the solutions for his scheduling is not unique. Your problem is to find how many different solutions satisfy all the constraints of the problem: row, column, 3-by-3 box and inequality constraints.

Input format

An input file for LP systems contains the following facts:

Example input for the figure above:
row(1,-1,0,0,-1,0,1).
vertical(2,1,-1,1,1,-1,-1,1,-1,0).
row(3,1,0,-1,0,0,-1).
vertical(4,1,-1,-1,1,-1,1,1,-1,-1).
row(5,-1,-1,1,0,0,-1).
row(6,0,-1,0,1,0,1).
vertical(7,1,1,-1,-1,1,0,-1,1,-1).
row(8,1,-1,1,1,1,-1).
vertical(9,0,0,0,0,0,-1,-1,1,1).
row(10,-1,1,-1,-1,1,1).
row(11,-1,1,-1,1,-1,-1).
vertical(12,-1,1,1,-1,1,1,-1,1,0).
row(13,0,1,1,-1,0,1).
vertical(14,-1,1,-1,-1,1,-1,1,-1,1).
row(15,-1,1,0,1,0,-1).

Output format

The output should contain exactly one fact of the form solutions(S), where S is the number of different solutions for the input problem.

Acknowledgment: thanks to Annie Liu for suggesting related problems.