#!/bin/python import sys modF = int(1e9) + 7 def solve(A): # Return the sum of S(S(A)) modulo 10^9+7. B = S(S(A)) total = 0 for b in B: total = (total + b) % modF return total def S(A): B = [] for k in xrange(len(A)): for i in xrange(0, len(A) - k): j = i + k + 1 B.append(max(A[i:j])) return B if __name__ == "__main__": n = int(raw_input().strip()) A = map(int, raw_input().strip().split(' ')) result = solve(A) print result