#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=300010;
const int M=100010;
const int maxn=100000;
using namespace std;

int n;
int a[M],b[M];
LL num[N],tot;

int lowbit(int x){
	return x&(-x);
}

LL GET(int x){
	LL res=num[0];
	while(x>0){
		res+=num[x];
		x-=lowbit(x);
	}
	return res;
}

void ADD(int x){
	while(x<=200000){
		num[x]++;
		x+=lowbit(x);
	}
}

int CHK(int x){
	rep(i,0,200000)num[i]=0;
	ADD(maxn);
	int now=100000;
	LL res=0;
	rep(i,1,n){
		if(a[i]<=x)now++;
		  else now--;
		res+=GET(now-1);
		ADD(now);
	}
	if(res>=(tot/2+1))return 1;
	return 0;
}

int main(){
	scanf("%d",&n);
	tot=(LL)(n+1)*n/2;
	rep(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	int R=unique(b+1,b+n+1)-b-1;
	int L=1,ans=0;
	while(L<=R){
		int mid=(L+R)>>1;
		if(CHK(b[mid]))R=mid-1,ans=b[mid];
		  else L=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}
### Prompt

Please formulate a Cpp solution to the following problem:

We will define the median of a sequence b of length M, as follows:

* Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.



For example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.

Snuke comes up with the following problem.

You are given a sequence a of length N. For each pair (l, r) (1 \leq l \leq r \leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a. We will list m_{l, r} for all pairs (l, r) to create a new sequence m. Find the median of m.

Constraints

* 1 \leq N \leq 10^5
* a_i is an integer.
* 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:


N
a_1 a_2 ... a_N


Output

Print the median of m.

Examples

Input

3
10 30 20


Output

30


Input

1
10


Output

10


Input

10
5 9 5 9 8 9 3 5 4 3


Output

8

### Response

```cpp
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=300010;
const int M=100010;
const int maxn=100000;
using namespace std;

int n;
int a[M],b[M];
LL num[N],tot;

int lowbit(int x){
	return x&(-x);
}

LL GET(int x){
	LL res=num[0];
	while(x>0){
		res+=num[x];
		x-=lowbit(x);
	}
	return res;
}

void ADD(int x){
	while(x<=200000){
		num[x]++;
		x+=lowbit(x);
	}
}

int CHK(int x){
	rep(i,0,200000)num[i]=0;
	ADD(maxn);
	int now=100000;
	LL res=0;
	rep(i,1,n){
		if(a[i]<=x)now++;
		  else now--;
		res+=GET(now-1);
		ADD(now);
	}
	if(res>=(tot/2+1))return 1;
	return 0;
}

int main(){
	scanf("%d",&n);
	tot=(LL)(n+1)*n/2;
	rep(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	int R=unique(b+1,b+n+1)-b-1;
	int L=1,ans=0;
	while(L<=R){
		int mid=(L+R)>>1;
		if(CHK(b[mid]))R=mid-1,ans=b[mid];
		  else L=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}
```