Rolling Median


Problem Statement

You are given a list xx of nn integers x=[x1,x2,...,xn]x = [x_1, x_2, ..., x_n].

You wish to determine the median for each prefix of xx. For example given [1,2,9,7][1, 2, 9, 7], you want to determine:

  • The median of [1][1], then
  • The median of [1,2][1, 2], then
  • The median of [1,2,9][1, 2, 9], then
  • The median of [1,2,9,7][1,2,9,7]

Input Format

Your first line of input will contain a single integer nn. Your next line will contain nn integers space-separated representing xx.

Output Format

You should output nn space-separated integers representing the median of each prefix of xx.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5
  • −109≤xi≤109-10^9 \leq x_i \leq 10^9

Sample Cases

Input 1
10
1 2 9 7
Output 1
1 1.5 2 5.5
Explanation 1

There are 7 integers less than 14, being −2,1,2,4,5,6,10-2, 1, 2, 4, 5, 6, 10. There are 4 integers less than 5, being −2,1,2,4-2, 1, 2, 4. There are 6 integers less than 7, being −2,1,2,4,5,6-2, 1, 2, 4, 5, 6.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.