传统题 1000ms 256MiB

Love Median

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Love Median

Time limit: 1 seconds

Memory limit: 512 megabytes

Problem Statement

Median plays a very important role in mathematics. Frank has studied the median for a long time. Frank is dazed by a sequence AA. Frank thinks the problem of finding the median of sequence A is too easy. Now, he's going to make the problem a little bit hard.

First, in this problem, we define the median of a sorted sequence XX which length is NN as : X1+N+12X_{\lfloor \frac{1+N+1}{2} \rfloor}.

Let nn be the length of sequence AA. For each pair (l,r)(l,r) (1lrn)(1\leq l\leq r\leq n), We make a new array BB with Al,Al+1,...ArA_l,A_{l+1},...A_r and sort it from small to large. Let ml,rm_{l,r} be the median of the new array BB. We will list ml,rm_{l,r} for all pairs (l,r)(l,r) to create a new sequence MM and sort it from small to large again. Find the median of MM.

Input

The first line contains one integers n(1n105)n(1\leq n\leq 10^5).

The second line contains nn integers denoting A1,A2,...,AnA_1,A_2,...,A_n.

Output

Print a single integer, denoting the answer to the question.

3
10 30 20
30
10
5 9 5 9 8 9 3 5 4 3
8

Note

For the first example the new sequence MM is 10,30,20,30,30,2010,30,20,30,30,20. The median of it after sort is 3030.

福建师范大学第十九届程序设计竞赛正式赛

未参加
状态
已结束
规则
ACM/ICPC
题目
13
开始于
2022-5-22 9:00
结束于
2022-5-22 14:00
持续时间
5 小时
主持人
参赛人数
25