#!/bin/python3 import sys def solved(a): b = [] n = len(a) for k in range(n): for i in range(n-k): j = i+k if(i == j): c = a[i:j+1] else: c= a[i:j] b.append(max(c)) return b def solve(a): # Return the sum of S(S(A)) modulo 10^9+7. b = solved(a) c = solved(b) total =0 for i in c: total += c[i] return (total % 10**9) +7 if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = solve(a) print(result)