Author:  A. Klenin  Time limit:  1 sec  
Input file:  input.txt  Memory limit:  256 Mb  
Output file:  output.txt 
Human spaceship has discovered an abandoned alien vessel in the interstellar space. Aboard the vessel, various recordings were found and xenoarcheologists have started to decipher them.
First, they were able to recognize numerals and convert them to the human notation. The next step is converting dates.
Alien dates are apparently measured in 4 units (as opposed to 3 human units — years, months and days). Also, unlike the human one, alien calendar is regular — for each unit, its ratio to the next one is whole and fixed. The problem is to find those ratios.
One of records seemed to be an astronomical log, describing and dating various notable cosmic events. Scientists were able to identify some of the events, and determine the corresponding dates. Surprisingly, the smallest unit of the alien calendar happened to be exactly equal to one Earth day.
Your program must, given the list of alien and corresponding human dates, determine all possible sets of unit ratios for the alien calendar.
All human dates are correct. You may assume that the ratios are in the range from 2 to 100.
The human calendar have 12 months, containing 31, 28 or 29, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31 days. The second month has 29 days if the year is either divisible by 400 or divisible by 4 and not divisible by 100.
Input file contains an integer N — the number of dates, followed by N groups of 7 numbers each: u_{i} v_{u} w_{i} t_{i} d_{i} m_{i} y_{i}. In the group, u_{i} v_{u} w_{i} t_{i} are numbers comprising ith alien date, in order from the smallest to the largest unit, d_{i} m_{i} y_{i} are day, month and year of the same date in the human calendar.
Output file must contain an integer M — number of possible calendars.
1 ≤ N ≤ 10;
1 ≤ u_{i}, v_{i}, w_{i} ≤ 100;
1 ≤ t_{i} ≤ 10000;
1 ≤ d_{i} ≤ 31;
1 ≤ m_{i} ≤ 12;
1600 ≤ y_{i} < 10000;
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 

