#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = acos(-1.0);
const ll LINF = (ll)1e18 + 5;
const int INF = (int)1e9 + 5;

template<class T>
T sqr(T x) { return x * x; }

template<class T>
T abs(T x) { return x < 0 ? -x : x; }

template<class T>
ll round(T x) { return x < 0 ? x - 0.5 : x + 0.5; }

template<class T>
bool chmin(T & x, const T & y) {
	if (y < x) {
		x = y;
		return true;
	}
	return false;
}

template<class T>
bool chmax(T & x, const T & y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}


template<class P, class Q>
ostream & operator <<(ostream & os, const pair<P, Q> & p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<class T>
ostream & operator <<(ostream & os, const vector<T> & v) {
	bool was = false;
	os << "{";
	for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class T>
ostream & operator <<(ostream & os, const set<T> & v) {
	bool was = false;
	os << "{";
	for (typename set<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class T>
ostream & operator <<(ostream & os, const multiset<T> & v) {
	bool was = false;
	os << "{";
	for (typename multiset<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class P, class Q>
ostream & operator <<(ostream & os, const map<P, Q> & v) {
	bool was = false;
	os << "{";
	for (typename map<P, Q>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

#define all(x) (x).begin(), (x).end()

template<class T>
T nextInt() {
	ll x = 0;
	bool p = false;
	char c;
	do {
		c = getchar();
	} while (c <= 32);
	if (c == '-') {
		p = true;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return (p ? -x : x);
}

const int N = 200200;

int tree[N * 4];
int arr[N], n, posOf[N];

void build(int v, int tl, int tr) {
	if (tl == tr) {
		tree[v] = arr[tl];
		return;
	}
	int tm = (tl + tr) >> 1;
	build((v << 1) + 1, tl, tm);
	build((v << 1) + 2, tm + 1, tr);
	tree[v] = min(tree[(v << 1) + 1], tree[(v << 1) + 2]);
}

int getMin(int v, int tl, int tr, int l, int r) {
	if (tl == l && tr == r) {
		return tree[v];
	}
	int tm = (tl + tr) >> 1;
	if (r <= tm) {
		return getMin((v << 1) + 1, tl, tm, l, r);
	}
	else if (l > tm) {
		return getMin((v << 1) + 2, tm + 1, tr, l, r);
	}
	else {
		return min(getMin((v << 1) + 1, tl, tm, l, tm),
				   getMin((v << 1) + 2, tm + 1, tr, tm + 1, r));
	}
}

int getMin(int l, int r) {
	return getMin(0, 0, n - 1, l, r);
}

ll globalRes = 0;

void rec(int l, int r) {
	if (l > r) return;
	int val = getMin(l, r);
	int pos = posOf[val];
	globalRes += 1LL * (pos - l + 1) * (r - pos + 1) * val;
	rec(l, pos - 1);
	rec(pos + 1, r);
}

void solve() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", arr + i);
		posOf[arr[i]] = i;
	}
	build(0, 0, n - 1);
	rec(0, n - 1);
	cout << globalRes << endl;
}

int main() {
	srand(time(0));

#ifdef LOCAL
	//gen();
	freopen("input.txt", "r", stdin);
#else
	
#endif

	int t = 1;
	//scanf("%d", &t);
	while (t--) solve();
	
}

Measured memory_bytes: 10112