import sys 
import numpy as np

N = int(sys.stdin.readline())
P = np.array([int(x) for x in sys.stdin.readline().split()])

SUM = np.sum([np.sum([min(P[l:r+1]) for r in range(l, N)]) for l in range(N)])

print(SUM)  