#!/bin/python3 import sys def solve(A, count = 0): # Return the sum of S(S(A)) modulo 10^9+7. if count > 1: return sum(A) % (10 ** 9 + 7) B = [[] for _ in range(len(A))] for i in range(len(A)): curr_max = -1 for j in range(i, len(A)): element = A[j] index = j - i if element > curr_max: B[index].append(element) curr_max = element else: B[index].append(curr_max) C = [] for ls in B: C.extend(ls) return solve(C, count + 1) if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = solve(a) print(result)