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. return S(S(A)).Sum() % (1000000000 + 7); } static int[] S(int[] A) { List b = new List(); for(int k =0; k <= A.Length-1; ++k) { for(int i = 0; i <= A.Length-k-1; ++i) { int j = i + k; int[] tmp = new int[j-i+1]; Array.Copy(A, i, tmp, 0, j-i+1); b.Add(tmp.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); } }