#arc058c. [arc058_c]Iroha and Haiku
[arc058_c]Iroha and Haiku
Problem Statement
Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
Iroha is looking for -Haiku (defined below) in integer sequences.
Consider all integer sequences of length whose elements are between and , inclusive. Out of those sequences, how many contain an -Haiku?
Here, an integer sequence is said to contain an -Haiku if and only if there exist four indices such that all of the following are satisfied:
Since the answer can be extremely large, print the number modulo .
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the number of the sequences that contain an -Haiku, modulo .
Sample Input 1
3 5 7 5
Sample Output 1
1
Here, the only sequence that contains a -Haiku is \[5, 7, 5\].
Sample Input 2
4 5 7 5
Sample Output 2
34
Sample Input 3
37 4 2 3
Sample Output 3
863912418
Sample Input 4
40 5 7 5
Sample Output 4
562805100