using System;
using Algorithm;

public class Program
{
    private int N, X, Y, Z;
    private int[] A;
    private long LenM;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        // len(m) = (N+1)N/2
        // xが答え 
        // x mにx以上がceil(len(m)/2)以上最大

        LenM = (long) (N + 1) * N / 2;

        int max = 1000000001;
        int min = 0;
        while (max - min > 1)
        {
            int med = (max + min) / 2;
            if (Check(med))
            {
                min = med;
            }
            else
            {
                max = med;
            }
        }
        Console.WriteLine(min);
    }

    // m[l,r]のうちx以上がceil(len(m)/2)以上か?
    private bool Check(int x)
    {
        // m[l,r] A[l,r]の中央値
        // m[l,r]のうちx以上がいくつか?
        // Aを x未満なら-1 以上なら1に置き換える
        int[] ar = new int[N];
        for (int i = 0; i < N; i++)
        {
            ar[i] = A[i] < x ? -1 : 1;
        }
        // Σ ar[l,r]>=0 がいくつか?

        int[] sum = new int[N + 1];

        // Σ ar[l,r] = sum[r] - sum[l]

        sum[0] = 100000;

        for (int i = 0; i < N; i++)
        {
            sum[i + 1] = sum[i] + ar[i];
        }

        var st = new SegTree(200001);
        // sum[l] <= sum[r] の lr がいくつあるか
        long result = 0;
        foreach (int i in sum)
        {
            result += st.Query(0, i + 1);
            st[i]++;
        }
        return result >= (LenM + 1) / 2;
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

namespace Algorithm
{
    using N = Int64;

    class SegTree
    {
        private readonly N[] Array;
        private readonly int len;

        public SegTree(int size)
        {
            len = 1;
            while (len < size)
            {
                len *= 2;
            }

            Array = new N[len * 2];
        }

        public void Update(N item, int index)
        {
            index += len;
            Array[index] = item;
            while (index > 1)
            {
                index /= 2;
                Array[index] = Array[index * 2] + Array[index * 2 + 1];
            }
        }

        private N Q(int left, int right, int k, int l, int r)
        {
            if (left <= l && r <= right)
            {
                return Array[k];
            }

            if (r <= left || right <= l)
            {
                return 0;
            }

            return Q(left, right, k * 2, l, (l + r) / 2) + Q(left, right, k * 2 + 1, (l + r) / 2, r);
        }

        public N Query(int left, int right)
        {
            return Q(left, right, 1, 0, len);
        }

        public N this[int i]
        {
            get { return Array[i + len]; }
            set { Update(value, i); }
        }
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 45608