{-# LANGUAGE TupleSections #-}

import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed
import Prelude hiding (filter, map, maximum, replicate, tail)

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = h2!maxIndex h2
  where
  u = tail v
  m = maximum u
  h0 = accumulate (+) (replicate (m+1) 0) $ map (,1) u :: Vector Int
  h1 = accumulate (+) h0 $ map (,1) . filter (<=m) $ map succ u
  h2 = accumulate (+) h1 $ map (,1) . filter (0<=) $ map pred u