The boboness of a sequence of integers (x_1,x_2,…,x_n) is ∏_i=3nw(maxx_i−2,x_i−1,x_i). Here, 1≤x_i≤n, and the values w(1),w(2),…,w(n) are given.
Bobo would like to know the sum of boboness of all sequences satisfying 1≤x_i≤n. As this sum can be very large, he is interested only in the answer modulo (109+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 n (3≤n≤2000).
The second line contains n integers w(1),w(2),…,w(n) (1≤w(i)≤109).
It is guaranteed that the sum of n does not exceed 2000.
For each test case, output an integer which denotes the sum taken modulo (109+7).