#P1788D. Moving Dots

    ID: 286 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>binary searchbrute forcecombinatoricsmathtwo pointers*2000

Moving Dots

Description

We play a game with nn dots on a number line.

The initial coordinate of the ii-th dot is xix_i. These coordinates are distinct. Every dot starts moving simultaneously with the same constant speed.

Each dot moves in the direction of the closest dot (different from itself) until it meets another dot. In the case of a tie, it goes to the left. Two dots meet if they are in the same coordinate, after that, they stop moving.

After enough time, every dot stops moving. The result of a game is the number of distinct coordinates where the dots stop.

Because this game is too easy, calculate the sum of results when we play the game for every subset of the given nn dots that has at least two dots. As the result can be very large, print the sum modulo 109+710^9+7.

The first line contains one integer nn (2n30002 \leq n \leq 3000).

The next line contains nn integers x1,x2,,xnx_1, x_2, \ldots, x_n (1x1<x2<<xn1091 \leq x_1 < x_2 < \ldots < x_n \leq 10^9), where xix_i represents the initial coordinate of ii-th dot.

Print the sum of results modulo 109+710^9+7.

Input

The first line contains one integer nn (2n30002 \leq n \leq 3000).

The next line contains nn integers x1,x2,,xnx_1, x_2, \ldots, x_n (1x1<x2<<xn1091 \leq x_1 < x_2 < \ldots < x_n \leq 10^9), where xix_i represents the initial coordinate of ii-th dot.

Output

Print the sum of results modulo 109+710^9+7.

Sample Input 1

4
1 2 4 6

Sample Output 1

11

Sample Input 2

5
1 3 5 11 15

Sample Output 2

30

Note

In the first example, for a subset of size 22, two dots move toward each other, so there is 11 coordinate where the dots stop.

For a subset of size 33, the first dot and third dot move toward the second dot, so there is 11 coordinate where the dots stop no matter the direction where the second dot moves.

For [1,2,4,6][1, 2, 4, 6], the first and second dots move toward each other. For the third dot, initially, the second dot and the fourth dot are the closest dots. Since it is a tie, the third dot moves left. The fourth dot also moves left. So there is 11 coordinate where the dots stop, which is 1.51.5.

Because there are 66 subsets of size 22, 44 subsets of size 33 and one subset of size 44, the answer is 61+41+1=116 \cdot 1 + 4 \cdot 1 + 1 = 11.

In the second example, for a subset of size 55 (when there are dots at 11, 33, 55, 1111, 1515), dots at 11 and 1111 will move right and dots at 33, 55, 1515 will move left. Dots at 11, 33, 55 will eventually meet at 22, and dots at 1111 and 1515 will meet at 1313, so there are 22 coordinates where the dots stop.