Problem 08C. Find Median from Data Stream ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

Values arrive one at a time (n of them). After each arrival, report the median of all values seen so far. If the count so far is even, report the lower of the two middle values (this keeps every answer an integer).

Input format

The first line contains one integer n. The second line contains n space-separated integers — the values, in arrival order.

Output format

Print n lines: the median after each arrival.

Constraints

1 ≤ n ≤ 2 ⋅ 105

 − 109 ≤ value ≤ 109

Sample tests

No. Standard input Standard output
1
4
5 15 1 3
5
5
5
3
2
1
7
7

0.031s 0.008s 16