{-# LANGUAGE MultiWayIf #-}
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

count :: Int -> Int -> Int
count n i = i * (n-i+1)

solve :: V.Vector Int -> Int
solve v = if V.null v
  then 0
  else (if m == 0 || m == n-1 then n else count n (m+1))*mv + solve l + solve (V.tail r)
  where
    n = V.length v
    m = V.minIndex v
    mv = v V.! m
    (l, r) = V.splitAt m v

main :: IO ()
main = do
  getLine
  a <- V.fromList . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  print $ solve a