const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const N = Number(lines[0]);
const A = lines[1].split(' ').map(Number);

let sum = 0;

for (let l = 0; l < N; l++) {
	let min = A[l];
	for (let r = l; r < N; r++) {
		min = Math.min(min, A[r]);
		sum += min;
	}
}

console.log(sum);