Even Three is Odd

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

The boboness of a sequence of integers (x_1,x_2,,x_n)(x\_1, x\_2, \dots, x\_n) is _i=3nw(maxx_i2,x_i1,x_i)\prod\limits\_{i = 3}^n w(\max\\{x\_{i - 2}, x\_{i - 1}, x\_i\\}). Here, 1x_in1 \leq x\_i \leq n, and the values w(1),w(2),,w(n)w(1), w(2), \dots, w(n) are given.

Bobo would like to know the sum of boboness of all sequences satisfying 1x_in1 \leq x\_i \leq n. As this sum can be very large, he is interested only in the answer modulo (109+7)(10^9+7).

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains an integer nn (3n20003 \leq n \leq 2000).

The second line contains nn integers w(1),w(2),,w(n)w(1), w(2), \dots, w(n) (1w(i)1091 \leq w(i) \leq 10^9).

It is guaranteed that the sum of nn does not exceed 20002000.

출력

For each test case, output an integer which denotes the sum taken modulo (109+7)(10^9+7).