{--{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

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.IntMap as IM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM

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 <- VUM.replicate (2*n+2) 0 :: IO (VUM.IOVector 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
            let as' = map (+(n+1)) . scanl (+) 0 $ map (\a -> if a >= x then 1 else -1) as

            --s <- getCurrentTime
            VUM.set fen 0
            y <- sum <$> (forM as' $ \a -> queryFenwickTree fen a >>= \q -> modifyFenwickTree fen a >> return q)
            print y
            --t <- getCurrentTime
            --print $ diffUTCTime t s

            return $ y >= m`div`2
            
    size = 2*n+2

  print =<< (xs VU.!) <$> solve 0 (n-1)

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)))
--}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE FlexibleContexts #-}
{-# 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.Int
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 <- VUM.replicate (2*n+2) 0 :: IO (VUM.IOVector Int64)
     
  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 -> sumFen a >>= \q -> addFen a >> return q)
                --print y
                return $ y >= (fromIntegral $ m`div`2)
                
     
    size = 2*n+2
     
    {-# INLINE addFen #-}
    addFen :: Int -> IO ()
    addFen j = do
      when (j <= size) $ do
        VUM.unsafeWrite fen j =<< (+1) <$> VUM.unsafeRead fen j
        addFen (j + (j .&. (-j)))
     
    {-# INLINE sumFen #-}
    sumFen :: Int -> IO Int64
    sumFen j
      | j <= 0 = return 0
      | otherwise = (+) <$> VUM.unsafeRead fen j <*> sumFen (j - (j .&. (-j)))
     
  --x <- getCurrentTime
  print =<< (xs VU.!) <$> solve 0 (n-1)
  --y <- getCurrentTime
  --print $ diffUTCTime y x
