atcoder#ARC119C. [ARC119C] ARC Wrecker 2
[ARC119C] ARC Wrecker 2
Score: points
Problem Statement
There are buildings along the AtCoder Street, numbered through from west to east. Initially, Buildings have the heights of , respectively.
Takahashi, the president of ARC Wrecker, Inc., plans to choose integers and and make the heights of Buildings all zero. To do so, he can use the following two kinds of operations any number of times in any order:
- Set an integer and increase the heights of Buildings and by each.
- Set an integer and decrease the heights of Buildings and by each. This operation can only be done when both of those buildings have heights of or greater.
Note that the range of depends on .
How many choices of are there where Takahashi can realize his plan?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5
5 8 8 6 6
3
Takahashi can realize his plan for .
For example, for , the following sequence of operations make the heights of Buildings all zero.
- Decrease the heights of Buildings and by each, six times in a row.
- Decrease the heights of Buildings and by each, eight times in a row.
For the remaining seven choices of , there is no sequence of operations that can realize his plan.
7
12 8 11 3 3 13 2
3
Takahashi can realize his plan for .
For example, for , the following figure shows one possible solution.
10
8 6 3 9 5 4 7 2 1 10
1
Takahashi can realize his plan for only.
14
630551244 683685976 249199599 863395255 667330388 617766025 564631293 614195656 944865979 277535591 390222868 527065404 136842536 971731491
8