#!/bin/python import sys import collections def maxSlideWindow(A,w): B = [-1]*(len(A) - w + 1) n = len(A) Q = collections.deque() for i in range(0,w): while len(Q) > 0 and A[i] >= A[Q[-1]]: Q.pop() Q.append(i) for i in range(w,n): B[i-w] = A[Q[0]] while len(Q) > 0 and A[i] >= A[Q[-1]]: Q.pop() while len(Q) > 0 and Q[0] <= i-w: Q.popleft() Q.append(i) B[n-w] = A[Q[0]] return B def maxTran(vec): B = [] for k in range(1,len(vec)+1): B.extend(maxSlideWindow(vec,k)) return B def solve(A): # Return the sum of S(S(A)) modulo 10^9+7. return sum(maxTran(maxTran(A))) % (10**9 + 7) if __name__ == "__main__": n = int(raw_input().strip()) A = map(int, raw_input().strip().split(' ')) result = solve(A) print result