/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-29 23:39:52
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template <class Monoid, class Function>
class SegmentTree {
 public:
  SegmentTree(const std::vector<Monoid>& data, Monoid identity_element,
              Function function)
      : identity_element_(identity_element), data_(data), function_(function) {
    Build();
  }

  void Update(size_t position, Monoid new_value) {
    position += n_;
    node_[position] = new_value;
    while (position > 0) {
      position >>= 1;
      node_[position] = function_(node_[2 * position], node_[2 * position + 1]);
    }
  }

  // return Query[left, right)
  Monoid Query(int left, int right) {
    Monoid vl = identity_element_, vr = identity_element_;
    for (left += n_, right += n_; left < right; left >>= 1, right >>= 1) {
      if (left & 1) vl = function_(vl, node_[left++]);
      if (right & 1) vr = function_(node_[--right], vr);
    }
    return function_(vl, vr);
  }

  Monoid operator[](size_t position) const { return node_[n_ + position]; }

 private:
  size_t n_;
  Monoid identity_element_;
  std::vector<Monoid> data_;
  std::vector<Monoid> node_;
  Function function_;

  void Build() {
    size_t SIZE = data_.size();
    n_ = 1;
    while (n_ < SIZE) {
      n_ <<= 1;
    }
    node_.assign(2 * n_, identity_element_);
    for (size_t i = 0; i < SIZE; ++i) {
      node_[i + n_] = data_[i];
    }
    for (size_t i = n_ - 1; i > 0; --i) {
      node_[i] = function_(node_[2 * i], node_[2 * i + 1]);
    }
  }
};

constexpr int INF = 1e9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> a(n); cin >> a;

  auto f = [](int x, int y){ return min(x, y); };
  SegmentTree<int, decltype(f)> seg(a, INF, f);

  int64 ans = 0;

  for (int i = 0; i < n; ++i) {
    int low = i, high = n;
    while (high - low > 1) {
      int mid = (high + low) / 2;
      if (seg.Query(i, mid + 1) == a[i]) {
        low = mid;
      } else {
        high = mid;
      }
    }
    //debug(a[i], a[low]);
    int low2 = -1, high2 = i;
    while (high2 - low2 > 1) {
      int mid2 = (high2 + low2) / 2;
      if (seg.Query(mid2, i + 1) == a[i]) {
        high2 = mid2;
      } else {
        low2 = mid2;
      }
    }
    //debug(a[i], a[high2]);
    int64 forward = low - i;
    int64 backward = i - high2;
    //debug(forward, backward);
    ans += (int64) a[i] * (backward + 1) * (forward + 1);
  } 

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3840