import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int solve(int[] A) { // Return the sum of S(S(A)) modulo 10^9+7. List lA=new ArrayList(); for(int a:A){ lA.add(a); } BigInteger sum = sum(S(S(lA))).mod(BigInteger.valueOf(7*10^9)); return sum.intValue(); } private static BigInteger sum(List s) { BigInteger sum=BigInteger.ZERO; for(Integer i:s) { sum=sum.add(BigInteger.valueOf(i)); } return sum; } private static List S(List A){ List B = new ArrayList(); for(int k=0;k<=A.size()-1;k++){ for(int i=0;i<=A.size()-k-1;i++){ int j=i+k; B.add(max(A, i, j)); } } return B; } private static int max(List A, int i, int j) { int max=0; for(int k=i;k<=j;k++){ max=Math.max(A.get(k),max); } return max; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for(int a_i = 0; a_i < n; a_i++){ a[a_i] = in.nextInt(); } int result = solve(a); System.out.println(result); in.close(); } }