import Data.List( elemIndex, inits)
main = do
    n <- readLn::IO Int
    as <- return . map (read::String->Integer) . words =<< getLine
    let revs = reverse as
	sump [] = 0
	sump list = let
			min = minimum list
			Just ix = elemIndex min list
			(solid, remain) = splitAt (ix+1) list
		    in min*(toInteger $ ix+1) + sump remain
    print . sum $ map sump $ inits revs