import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Shhin */ public class Solution { static int[][] calc(int[] A) { int length = A.length; int B[][]=new int[((length)*(length+1))/2][2]; //if time out error use DP int p=0; int j=0; for (int k = 0; k <= length - 1; k++) { for (int i = 0; i <= (length - k - 1); i++) { j = i + k; // System.out.print(" " + i); // System.out.println(""); // System.out.print(" " + j); B[p][0]=i; B[p][1]=j; // System.out.println(""); //System.out.print("k="+k+" p="+p); p++; } } return B; } static public ArrayList myNumbers(int[] A,int[][] B) { ArrayList numbers = new ArrayList<>(); numbers.clear(); int i,j; for(int count = 0; count < B.length; count++) { i=B[count][0]; j=B[count][1]; int[] temp=Arrays.copyOfRange(A,i,j+1); /* for (int k = 0; k < temp.length; k++) { System.out.print("dinf "+temp[k]); }System.out.println("ho");*/ Arrays.sort(temp); numbers.add(temp[temp.length-1]); } /* for (int k = 0; k < numbers.size(); k++) { System.out.println("OUR NUMBERS"+numbers.get(k)); }*/ return numbers; } static long add( ArrayList arrli) { long sum=0; for (int i = 0; i arrli = new ArrayList(); //1st case array list arrli.clear(); arrli.addAll(myNumbers(A,B)); // int C[][]=calc1(arrli); int[] A1= arrli.stream().mapToInt(i->i).toArray(); int C[][]=calc(A1); /* for(int i = 0; i < C.length; i++) { //or use inhanced iterator System.out.print("...."+C[i][0]+" "+C[i][1]); }*/ ArrayList arrli1 = new ArrayList(); //1st case array list arrli1.addAll(myNumbers(A1,C)); long modulo=1000000000+7; k=add(arrli1)%modulo; return k; // Return the sum of S(S(A)) modulo 10^9+7. } 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(); } long result = solve(a); System.out.println(result); in.close(); } }