import Control.Applicative ((<$>)) main :: IO () main = getLine >> solve <$> map read <$> words <$> getLine >>= print solve :: [Int] -> Int solve xs = sum $ zipWith f xs (pyramid xs) where pyramid xs = [1..h] ++ [h-1, h-2..1] ++ repeat 0 where h = floor . sqrt . fromIntegral . sum $ xs f x y | x >= y = x - y | otherwise = 0