#!/bin/python3 comment = ''' A is an zero-index arr 0 < i < j < len(A); A(sub i-j) is a subarray of A B is a list that is empty for loop 0 to len(A)-1 ''' import sys def solve(A, iteration): # Return the sum of S(S(A)) modulo 10^9+7. B = [] # plus one because when we slice the subarr we want to get the position after the last item for k in range(len(A)+1): for i in range(len(A)-k+1): j = i + k if i >= 0 & j <= len(A): subarr = A[i:j] if len(subarr) > 0: B.append(max(subarr)) if iteration == 1: print(sum(B) % 1000000007) return sum(B); else: solve(B, iteration+1) if __name__ == "__main__": n = int(raw_input().strip()) a = map(int, raw_input().strip().split(' ')) result = solve(a, 0)