Language: C++

// author: Saman Mahdanian
#include <iostream>
#include <cstring>

using namespace std;
const int N = 1e5 + 10;

#define int long long

int n, a[N], _cnt[2 * N];
long long get_le (int);

int32_t main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	long long int g  = 2e9;
	long long int le = 0;
	while (g - le > 1) {
		int med = (g + le) / 2;
		if (get_le(med) * 2 > (n * (n + 1)) / 2)
			g = med;
		else
			le = med;
	}

	cout << g << endl;
}

/*
*/

long long get_le (int x) {
	memset (_cnt, 0, sizeof _cnt);
	int* cnt = &_cnt[N];
	cnt[0] = 1;
	int cur = 0, p = 0;
	long long res = 0;

	for (int i = 0; i < n; i++) {
		int val = a[i] <= x? +1 : -1;
		cur += val * cnt[p];
		cur = max(cur, 0);
		res += cur;
		p += val;
		cnt[p]++;
	}
	return res;
} 

// SamMHD :: 05/12/2018 15:52:56 :: Another Nemidoonam-Che-Kooftie...

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:8:13: error: 'long long long' is too long for GCC
    8 | #define int long long
      |             ^~~~
a.cc:18:19: note: in expansion of macro 'int'
   18 |         long long int g  = 2e9;
      |                   ^~~
a.cc:8:18: error: 'long long long' is too long for GCC
    8 | #define int long long
      |                  ^~~~
a.cc:18:19: note: in expansion of macro 'int'
   18 |         long long int g  = 2e9;
      |                   ^~~
a.cc:8:13: error: 'long long long' is too long for GCC
    8 | #define int long long
      |             ^~~~
a.cc:19:19: note: in expansion of macro 'int'
   19 |         long long int le = 0;
      |                   ^~~
a.cc:8:18: error: 'long long long' is too long for GCC
    8 | #define int long long
      |                  ^~~~
a.cc:19:19: note: in expansion of macro 'int'
   19 |         long long int le = 0;
      |                   ^~~
a.cc: In function 'long long int get_le(long long int)':
a.cc:44:26: error: no matching function for call to 'max(long long int&, int)'
   44 |                 cur = max(cur, 0);
      |                       ~~~^~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:44:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |                 cur = max(cur, 0);
      |                       ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided