# Original solution
def examA():
    X = SI()
    d = defaultdict(int)
    for s in X:
        if s=="T" and d["S"]>=1:
            d["S"] -=1
        else:
            d[s] += 1
    ans = d["S"] + d["T"]
    print(ans)
    return

def examB():
    # じゅっぴーさんの
    # https://juppy.hatenablog.com/entry/2019/02/11/%E8%9F%BB%E6%9C%AC_python_AVL%E6%9C%A8_%E6%A4%9C%E7%B4%A2%E6%8B%A1%E5%BC%B5_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0
    ###############################################################################
    # root.search(x): ◯.data == x のものが存在するある場合それを出力、ない場合Noneを出力
    # root.insert(x): ◯.data == xが存在する場合Falseを出力、ない場合◯.data == x なる頂点を作る
    # y.to_s(): 頂点yのdataを出力
    # y.left_s(): 頂点yのleftを出力(ない場合はNone)
    # root.search_lower(x,None): ○.dataがxより小さいものの中で最も大きいものを出力、ない場合Noneを出力
    # root.search_higher(x,None): xより大きいものの中で最も小さいものを出力、ない場合Noneを出力
    ################################################################################
    class Avltree:
        def __init__(self, key=None):
            self.key = key
            self.left = None
            self.right = None
            self.balance = "Even"

        def search(self, key):
            if self.key == None:
                return None
            if self.key > key:
                if self.left == None:
                    return None
                else:
                    return self.left.search(key)
            if self.key < key:
                if self.right == None:
                    return None
                else:
                    return self.right.search(key)
            return self  # self.key == keyの場合

        def search_lower(self, key, key_lower):
            if self.key == None:
                return key_lower
            if self.key > key:
                if self.left == None:
                    return key_lower
                else:
                    return self.left.search_lower(key, key_lower)
            if self.key < key:
                key_lower = self.key
                if self.right == None:
                    return key_lower
                else:
                    return self.right.search_lower(key, key_lower)
            # self.key == keyの場合
            if self.left == None:
                return key_lower
            else:
                if key_lower == None:
                    return self.left.end_higher(self.left.key)
                else:
                    return max(key_lower, self.left.end_higher(self.left.key))

        def search_higher(self, key, key_higher):
            if self.key == None:
                return key_higher
            if self.key > key:
                key_higher = self.key
                if self.left == None:
                    return key_higher
                else:
                    return self.left.search_higher(key, key_higher)
            if self.key < key:
                if self.right == None:
                    return key_higher
                else:
                    return self.right.search_higher(key, key_higher)
            # self.key == keyの場合
            if self.right == None:
                return key_higher
            else:
                if key_higher == None:
                    return self.right.end_lower(self.right.key)
                else:
                    return min(key_higher, self.right.end_lower(self.right.key))

        def end_lower(self, end_lower_key):
            if self.left == None:
                return end_lower_key
            else:
                end_lower_key = self.left.key
                return self.left.end_lower(end_lower_key)

        def end_higher(self, end_higher_key):
            if self.right == None:
                return end_higher_key
            else:
                end_higher_key = self.right.key
                return self.right.end_higher(end_higher_key)

        def DoubleRightRotation(self):
            tl = self.left
            self.left = tl.right.right
            tl.right.right = self  # selfはそのノード
            tlr = tl.right
            tl.right = tlr.left
            tlr.left = tl
            if tlr.balance == "Left":
                tlr.right.balance = "Right"
                tlr.left.balance = "Even"
            elif tlr.balance == "Right":
                tlr.right.balance = "Even"
                tlr.left.balance = "Left"
            elif tlr.balance == "Even":
                tlr.right.balance = "Even"
                tlr.left.balance = "Even"
            tlr.balance = "Even"
            return tlr

        def DoubleLeftRotation(self):
            tr = self.right
            self.right = tr.left.left
            tr.left.left = self
            trl = tr.left
            tr.left = trl.right
            trl.right = tr
            if trl.balance == "Right":
                trl.left.balance = "Left"
                trl.right.balance = "Even"
            elif trl.balance == "Left":
                trl.left.balance = "Even"
                trl.right.balance = "Right"
            elif trl.balance == "Even":
                trl.left.balance = "Even"
                trl.right.balance = "Even"
            trl.balance = "Even"
            return trl

        def SingleLeftRotation(self):
            tr = self.right
            tr.balance = "Even"
            self.balance = "Even"
            self.right = tr.left
            tr.left = self
            return tr

        def SingleRightRotation(self):
            tl = self.left
            tl.balance = "Even"
            self.balance = "Even"
            self.left = tl.right
            tl.right = self
            return tl

        def replace(self, p, v):  # 親ノードpの下にある自分(self)をvに置き換える。
            if p.left == self:
                p.left = v
            else:
                p.right = v

        def insert(self, key):  # rootでのみ呼ばれる挿入
            if self.key == None:  # rootを含むrotationはしないことにする。
                self.key = key
                return self
            if key < self.key:
                if self.left == None:
                    self.left = Avltree(key)
                else:
                    self.left.insertx(self, key)
            elif key > self.key:
                if self.right == None:
                    self.right = Avltree(key)
                else:
                    self.right.insertx(self, key)
            else:  # key == self.key:
                pass  # do not overwrite

        def insertx(self, p, key):  # replaceを呼ぶために一つ上の親を持っているinsert
            if self.key > key:
                if self.left == None:
                    self.left = Avltree(key)
                else:
                    if not self.left.insertx(self, key):  # 左の木が生長しなければ、
                        return False  # 成長しない
                if self.balance == "Right":
                    self.balance = "Even"
                    return False
                elif self.balance == "Even":
                    self.balance = "Left"
                    return True  # 成長した
                elif self.balance == "Left":
                    if self.left.balance == "Right":
                        self.replace(p, self.DoubleRightRotation())
                    elif self.left.balance == "Left":
                        self.replace(p, self.SingleRightRotation())
                    return False  # rotationを行うと成長しない
            if self.key < key:
                if self.right == None:
                    self.right = Avltree(key)
                else:
                    if not self.right.insertx(self, key):
                        return False
                if self.balance == "Left":
                    self.balance = "Even"
                    return False
                elif self.balance == "Even":
                    self.balance = "Right"
                    return True
                elif self.balance == "Right":
                    if self.right.balance == "Left":
                        self.replace(p, self.DoubleLeftRotation())
                    elif self.right.balance == "Right":
                        self.replace(p, self.SingleLeftRotation())
                    return False
            return False  # self.key == keyの時は何もしないので成長もしない

        def to_s(self):
            return self.key

        def left_s(self):
            if self.left == None:
                return None
            return (self.left).key

        def right_s(self):
            if self.right == None:
                return None
            return (self.right).key

    ################################################################
    N = I()
    A = LI()
    lst = [0] * N
    for i in range(N):
        lst[A[i]-1] = i
    AVL = Avltree()
    ans = 0
    for a in range(1,N+1):
        i = lst[a-1]
        l = AVL.search_lower(i,None)
        r = AVL.search_higher(i,None)
        AVL.insert(i)
        #print(l,r)
        if l==None:
            l = -1
        if r==None:
            r = N
        ans += (i-l)*(r-i)*a
        #print(l,r,i,ans)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

# Optimized solution
def examA():
    X = SI()
    d = defaultdict(int)
    for s in X:
        if s=="T" and d["S"]>=1:
            d["S"] -=1
        else:
            d[s] += 1
    ans = d["S"] + d["T"]
    print(ans)
    return

def examB():
    # 参考 earlgrey_yh
    class Node:
        def __init__(self, key, height):
            self.key = key  # ノードの木
            self.height = height  # このノードを根とする部分木の高さ
            self.left = None
            self.right = None

        def size(self, n): return 0 if n is None else n.height

        def bias(self):  # 左の方が高いと正、右が高いと負の値を返す
            return self.size(self.left) - self.size(self.right)

        # 木の高さの計算
        def calcSize(self):
            self.height = 1 + max(self.size(self.left), self.size(self.right))

    class AVLTree:
        def __init__(self):
            self.root = None  # 根
            self.change = False  # 修正フラグ

        ###############
        # 回転操作, 修正操作
        ###############
        def rotateL(self, n):  # ノードnの左回転
            r = n.right;
            rl = r.left
            r.left = n;
            n.right = rl
            r.left.calcSize()
            r.calcSize()
            return r

        def rotateR(self, n):
            l = n.left;
            lr = l.right
            l.right = n;
            n.left = lr
            l.right.calcSize()
            l.calcSize()
            return l

        def rotateLR(self, n):  # 二重回転;左回転→右回転
            n.left = self.rotateL(n.left)
            return self.rotateR(n)

        def rotateRL(self, n):
            n.right = self.rotateR(n.right)
            return self.rotateL(n)

        def balanceL(self, n):
            if not self.change: return n
            h = n.height
            if n.bias() == 2:
                if n.left.bias() >= 0:
                    n = self.rotateR(n)
                else:
                    n = self.rotateLR(n)
            else:
                n.calcSize()
            self.change = (h != n.height)
            return n

        def balanceR(self, n):
            if not self.change: return n
            h = n.height
            if n.bias() == -2:
                if n.right.bias() <= 0:
                    n = self.rotateL(n)
                else:
                    n = self.rotateRL(n)
            else:
                n.calcSize()
            self.change = (h != n.height)
            return n

        ###############
        # Nodeの追加
        ###############
        def insert(self, key):
            self.root = self.insert_sub(self.root, key)

        def insert_sub(self, t, key):  # 新たなノードの挿入。初期位置は根。
            if t is None:
                self.change = True
                return Node(key, 1)
            if key < t.key:
                t.left = self.insert_sub(t.left, key)
                return self.balanceL(t)
            elif key > t.key:
                t.right = self.insert_sub(t.right, key)
                return self.balanceR(t)
            else:
                self.change = False
                return t

        ###############
        # Nodeの探索
        ###############

        def search(self, key, lower, higher):
            t = self.root
            lb, hb = lower, higher
            while t:
                if key < t.key:
                    hb = t.key
                    t = t.left
                else:
                    lb = t.key
                    t = t.right
            return lb, hb
    N = I()
    A = LI()
    lst = [0] * N
    for i in range(N):
        lst[A[i]-1] = i
    AVL = AVLTree()
    ans = 0
    for a in range(1,N+1):
        i = lst[a-1]
        l, r = AVL.search(i,-1,N)
        AVL.insert(i)
        #print(l,r)
        ans += (i-l)*(r-i)*a
        #print(l,r,i,ans)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""