import java.io.*;
import java.util.*;

public class Solution {
    
    class Answer {
        int N;
        List<Integer> init;
        final int MOD = 1000 * 1000 * 1000 + 7;
        
        public int getMax(List<Integer> list, int i, int j) {
            int max = -1;
            for (int k = i; k <= j; k++) {
                max = Math.max( max, list.get(k) );
            }
            return max;
        }
        
        public List<Integer> trasform(List<Integer> list) {
            List<Integer> B = new ArrayList<>();
            for (int k = 0; k <= list.size()-1; k++) {
                for (int i = 0; i <= list.size()-k-1; i++) {
                    int j = i + k;
                    B.add( getMax(list, i, j) );
                }
            }
            return B;
        }
        
        public long solve() {
            List<Integer> ret1 = trasform(init);            
            List<Integer> ret2 = trasform(ret1);
            long sum = 0L;
            for (Integer i : ret2) {
                sum = (sum + i) % MOD;
            }
            return sum;
        }
        
        public void main(FastScanner in, PrintWriter out) {
            N = in.nextInt();
            init = new ArrayList<>();
            for (int i = 0; i < N; i++) init.add(in.nextInt());
            out.println( solve() );
        }
        
        public void p(Object o) { System.out.print(o); }
        public void pl(Object o) { System.out.println(o); }
        public void arp(int[] o) { pl( Arrays.toString(o) ); }
        public void arpp(int[][] o) { 
            for (int i = 0; i < o.length; i++) {
                for (int j = 0; j < o[0].length; j++) { p(o[i][j] + " "); }
                pl("");
            }
        }
        public void ck(Object o1, Object o2) { pl(o1 + " " + o2); }
        public void ckk(Object o1, Object o2, Object o3) { pl(o1 + " " + o2 + " " + o3); }
        public void ckkk(Object o1, Object o2, Object o3, Object o4) { 
            pl(o1 + " " + o2 + " " + o3 + " " + o4);
        }
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        
        Solution problem = new Solution();
        Answer ans = problem.new Answer();
        ans.main(in, out);
        
        out.close();
        in.close();
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try { st = new StringTokenizer(br.readLine()); } 
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        public String nextLine() {
            String str = "";
            try { str = br.readLine();
            } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
        public void close() throws IOException { br.close(); }
    }
}