#!/bin/python3 import sys from collections import deque import itertools def S(A): # Just small changes to the original text... B = deque() for k in range(len(A)): for i in range(len(A) - k): j = i + k # B.append(max(A[i:j+1])) B.append(max(itertools.islice(A, i, j+1))) # return list(B) return B def solve(A): # Return the length of the longest possible sequence of moves modulo 10^9+7 return int(sum(S(S(A))) % (1e9 + 7)) if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = solve(a) print(result)