local mmi, mma = math.min, math.max local n = io.read("*n") local t = {} for i = 1, n do t[i] = 0 end for i = 1, n do local a = io.read("*n") + 1 t[a] = i end local left, right = n + 1, 0 local ret = 0 for i = 1, n do local p = t[i] left = mmi(left, p) right = mma(right, p) ret = ret + left * (n + 1 - right) end ret = tostring(1LL * ret):gsub("LL", "") print(ret)