#include #include #include #include using namespace std; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (auto &a : A) cin >> a; vector idx(N); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return A[i] < A[j]; }); long long ret = 0, lo = N, hi = 0; for (auto i : idx) { lo = lo < i ? lo : i; hi = hi > i ? hi : i; ret += (lo + 1) * (N - hi); } cout << ret << '\n'; }