{-# OPTIONS_GHC -optc-O3 #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Monad.Primitive
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.IntMap as IM

import Data.Time


readIntBS = fst . fromJust . BS.readInt

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map readIntBS . BS.words <$> BS.getLine :: IO [Int]
  fen <- newFenwickTree (2*n+1) :: IO (IOUFenwickTree Int)

  let
    xs = VU.fromList $ sort as
    m = n*(n+1)`div`2
    solve l r
      | l == r = return l
      | l+1 == r = aux (xs VU.! r) >>= \a -> return $ if a then r else l
      | otherwise = do
          a <- aux $ (xs VU.! ((l+r)`div`2))
          if a then
            solve ((l+r)`div`2) r
            else
            solve l ((l+r)`div`2)
        where
          aux x = do

            VUM.set fen 0
            y <- sum <$>
              (forM (map (+(n+1)) . scanl (+) 0 $ map (\a -> if a >= x then 1 else -1) as) $
               \a -> queryFenwickTree fen a >>= \q -> modifyFenwickTree fen a >> return q)
            return $ y >= m`div`2
    
  --x <- getCurrentTime
  print =<< (xs VU.!) <$> solve 0 (n-1)
  --y <- getCurrentTime
  --print $ diffUTCTime y x


type IOUFenwickTree a = VUM.IOVector a

{-# INLINE newFenwickTree #-} 
newFenwickTree :: Int -> IO (IOUFenwickTree Int)
newFenwickTree n = VUM.replicate (n+1) 0

{-# INLINE modifyFenwickTree #-}
modifyFenwickTree :: IOUFenwickTree Int -> Int -> IO ()
modifyFenwickTree tree i = do
  aux i
  where
    size = VUM.length tree
    {-# INLINE aux #-}
    aux j = do
      when (j <= size) $ do
        VUM.unsafeWrite tree j =<< (+1) <$> VUM.unsafeRead tree j
        aux (j + (j .&. (-j)))
        
{-# INLINE queryFenwickTree #-}
queryFenwickTree :: IOUFenwickTree Int -> Int -> IO Int
queryFenwickTree tree i = do
  aux i
  where
    size = VUM.length tree
    {-# INLINE aux #-}
    aux j
      | j <= 0 = return 0
      | otherwise = (+) <$> VUM.unsafeRead tree j <*> aux (j - (j .&. (-j)))
