#include <stdio.h>
#include <algorithm>

using namespace std;

int N, a[212345], tmp = 0;
__int64 ans;

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) { scanf("%d", &a[i]); }

	for (int l = 0; l < N; ++l) {
		for (int r = l; r < N; ++r) {
			for (int i = l; i <= r; ++i) {
				if (i == l) { tmp = a[i]; }
				if (tmp > a[i]) { tmp = a[i]; }
			}
			ans += tmp;
		}
	}

	printf("%I64d", ans);

	return 0;
}