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