cswork / OAOpen practice workspace

Eat ClubOA #1

Newton's Beautiful Sequence

Estimated MediumJudge-ready

Topics (AI-labelled)HashingIn-place Arrays

Sort each non-empty contiguous subarray of the original array independently. After sorting, the subarray's contribution increases by 1 for each pair of adjacent elements whose difference is greater than 1; a subarray of length 1 also contributes 1. Output the total contribution of all subarrays modulo 10^9+7.

Input

The input is N followed by N integers. This site adopts the constraints listed separately in the statement, 1≤N≤1000 and 1≤sequence[i]≤N; the text of the main constraint line is run together, so this site organizes it according to this readable constraint.

Output

Output the total beauty modulo 10^9+7.

Example 1

Input:

5
2 2 2 1 5

Output:

9

Example 2

Input:

1
1

Output:

1

Example 3

Input:

4
1 3 2 3

Output:

5

Editorial

Loading solution…