using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static List getList (int[] A) { List B = new List(); for (int k=0; kj) Array.Copy(A, j, tmp, 0, offset); else Array.Copy(A, i, tmp, 0, offset); B.Add(tmp.Max()); } } } return B; } static int solve(int[] A) { // Return the sum of S(S(A)) modulo 10^9+7. List B = getList(A); int [] X = B.ToArray(); List S = getList(X); int sum = 0; foreach(int i in S) { sum = sum + i; } return sum; } 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); } }