output_description: Print the answer.
  
  Note that the answer may not fit into a 32-bit integer.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      a_1 a_2 ... a_N
attempt: from sys import exit, setrecursionlimit
  from functools import reduce
  from itertools import *
  from collections import defaultdict
  from bisect import bisect
  
  
  def read():
      return int(input())
  
  
  def reads():
      return [int(x) for x in input().split()]
  
  
  setrecursionlimit(1000000)
  
  N = read()
  a = [x - 1 for x in reads()]
  b = [0] * N
  for i in range(N):
      b[a[i]] = i
  
  ps = [-1, N]
  res = 0
  for i in range(N):
      p = bisect(ps, b[i])
      print((ps[p] - b[i]), (b[i] - ps[p - 1]), (i + 1))
      res += (ps[p] - b[i]) * (b[i] - ps[p - 1]) * (i + 1)
      ps.insert(p, b[i])
  
  print(res)
  
problem_description: Statement
  
  One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from
  his friend.
  
  Find the following:
  
  ![](https://atcoder.jp/img/agc005/520049e1a049bb9810b398b35d7dcb7f.png)
samples: [{"input": "3\n    2 1 3", "output": "9\n    \n\n* * *"}, {"input": "4\n    1 3 2 4", "output": "19\n    \n\n* * *"}, {"input": "8\n    5 4 8 1 2 6 7 3", "output": "85"}]