using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static int solve(int[] A) { // Return the sum of S(S(A)) modulo 10^9+7. var r = Transform(Transform(A)); long sum = 0; for (int i = 0; i < r.Length; i++) { sum += r[i]; if (sum > 1000000007) sum -= 1000000007; } return (int)sum; } static int[] Transform(int[] a) { List b = new List(); if (a == null || a.Count() == 0) return b.ToArray(); for (int k = 0; k < a.Length; k++) { for (int i = 0; i < a.Length - k; i++) { // append max int max = int.MinValue; for (int index = i; index <= i + k; index++) { if (max < a[index]) max = a[index]; } b.Add(max); } } return b.ToArray(); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(a_temp,Int32.Parse); int result = solve(a); Console.WriteLine(result); } }