#P2015. ACSL 2016-2017 Junior Division Contest #4 ACSL Skyscraper

ACSL 2016-2017 Junior Division Contest #4 ACSL Skyscraper

Descended from other Latin square puzzle types, Skyscrapers is a Japanese creation. It received its first broad exposure at the 1st World Puzzle Championship in NYC in 1992 when publisher Sekai Bunka-sha presented a 20 page English edition of their Puzzler magazine to the competitors. In the USA it has been enhanced by Kevin Stone.

This program will use just one row as shown below. The object is to place a skyscraper in each square, with a height from 1 to 5, so that no two skyscrapers in the row have the same height. In addition, the number of visible skyscrapers, as viewed from the direction of each clue, is equal to the value of the clue.

In the example above, looking up from the left 4 skyscrapers are visible: #2, #3, #4 and #5. #1 is blocked by #3. Looking up from the right only one skyscraper is visible. #5 blocks all the others. Therefore the clue on the left would be 4 and the clue on the right would be 1.

INPUT FORMAT

There will be five lines of input. Each line will contain the left and right clue numbers.

OUTPUT FORMAT

For each input line print the number of different arrangements of heights 1 through 5 that can have those clue numbers.

SAMPLE

INPUT

1, 2
1, 5
2, 1
2, 4
3, 5

OUTPUT

6
1
6
4
0