#!/bin/python3 import sys def s(a): b=[] for k in range(len(a)): for i in range(len(a)-k): j=i+k t=[] for m in range(i,j+1): t.append(a[m]) temp=max(t) b.append(temp) return b def solve(A): # Return the length of the longest possible sequence of moves modulo 10^9+7. A=s(A) A=s(A) l=len(A) sum=0 for i in range(l): sum=sum+A[i] sum=sum%(10**9) return sum if __name__ == "__main__": n = int(input().strip()) A = list(map(int, input().strip().split(' '))) result = solve(A) print(result)