#!/bin/ruby def solve(a) b = Array.new l = a.length for k in 0..l-1 for i in 0..l-k-1 j = i + k b << a[i..j].max end end return b # Return the length of the longest possible sequence of moves modulo 10^9+7. end n = gets.strip.to_i a = gets.strip a = a.split(' ').map(&:to_i) b = solve(solve(a)) puts b.inject(0){|sum,x| sum + x } % (10**9+7)