### BUGGY CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Treap():
    class Node():
        def __init__(self, data):
            self.left = None
            self.right = None
            self.data = data
            self.priority = random.random()
            # print(data, self.priority)

        def to_dict(self):
            d = {
                'data': self.data,
            }

            if self.left:
                d['left'] = self.left.to_dict()
            if self.right:
                d['right'] = self.right.to_dict()

            return d

        def __str__(self):
            return json.dumps(self.to_dict(), indent='  ')

    def __init__(self):
        self.__root = None

    def __insert(self, node, data):
        if node is None:
            return self.Node(data)
        if data < node.data:
            node.left = self.__insert(node.left, data)
            if node.priority < node.left.priority:
                node = self.__rotate_right(node)
        else:
            node.right = self.__insert(node.right, data)
            if node.priority < node.right.priority:
                node = self.__rotate_left(node)

        return node

    def __rotate_left(self, node):
        tmp_node = node.right
        node.right = tmp_node.left
        tmp_node.left = node
        return tmp_node

    def __rotate_right(self, node):
        tmp_node = node.left
        node.left = tmp_node.right
        tmp_node.right = node
        return tmp_node

    def insert(self, data):
        self.__root = self.__insert(self.__root, data)
        return self

    def __find_lcr(self, data, node, lv, rv):
        if node is None:
            return lv, None, rv
        if data == node.data:
            return lv, data, rv
        if lv < node.data < data:
            lv = node.data
        if data < node.data < rv:
            rv = node.data
        if data < node.data:
            return self.__find_lcr(data, node.left, lv, rv)
        else:
            return self.__find_lcr(data, node.right, lv, rv)

    def find_lcr(self, data):
        return self.__find_lcr(data, self.__root, -sys.maxsize, sys.maxsize)

    def __hight(self, node):
        if node is None:
            return 0
        lh = 1
        if node.left:
            lh += self.__hight(node.left)

        rh = 1
        if node.right:
            rh += self.__hight(node.right)
        return max(lh, rh)

    @property
    def hight(self):
        return self.__hight(self.__root)


@mt
def slv(N, A):
    ans = 0
    a2i = [0] * (N+1)
    for i, a in enumerate(A):
        a2i[A[i]] = i

    vi = Treap()
    vi.insert(-1)
    vi.insert(N)

    for a in range(1, N+1):
        i = a2i[a]
        l, _, r = vi.find_lcr(i)
        l += 1
        ans += (i - l + 1) * (r - i) * a
        vi.insert(i)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # A = list(range(1, 200000+1))
    # for _ in range(100):
    #     random.shuffle(A)
    #     N = len(A)
    #     print(slv(N, A))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


@mt
def slv(N, A):
    ai = [(a, i) for i, a in enumerate(A)]
    ai.sort()

    lst = SegmentTree([-1] * N, max, -1)
    rst = SegmentTree([N] * N, min, N)
    ans = 0
    for a, i in ai:
        l = lst.query(0, i)
        r = rst.query(i+1, N)
        ans += (i-l) * (r-i) * a
        lst.update(i, i)
        rst.update(i, i)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()