The median of a set of integers is the midpoint value of the data set for which an equal number of integers are less than and greater than the value. To find the median, you must first sort your set of integers in non-decreasing order, then:

If your set contains an odd number of elements, the median is the middle element of the sorted sample. In the sorted set $\{1,2,3\}$, $2$ is the median.
If your set contains an even number of elements, the median is the average of the two middle elements of the sorted sample. In the sorted set $\{1,2,3,4\}$, $\frac{2+3}{2}=2.5$ is the median.

Given an input stream of $n$ integers, perform the following task for each $i^{\mbox{th}}$ integer:

Add the $i^{\mbox{th}}$ integer to a running list of integers.
Find the median of the updated list (i.e., for the first element through the $i^{\mbox{th}}$ element).
Print the updated median on a new line. The printed value must be a double-precision number scaled to $1$ decimal place (i.e., $12.3$ format).  

Example 

$a=[7,3,5,2]$  

Sorted          Median
[7]             7.0
[3, 7]          5.0
[3, 5, 7]       5.0
[2, 3, 5, 7]    4.0
  
Each of the median values is stored in an array and the array is returned for the main function to print.  

Note:  Add formatting to the print statement.  

Function Description 

Complete the runningMedian function in the editor below.  

runningMedian has the following parameters: 

- int a[n]: an array of integers  

Returns 

- float[n]: the median of the array after each insertion, modify the print statement in main to get proper formatting.    

Input Format

The first line contains a single integer, $n$, the number of integers in the data stream. 

Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains an integer, $a[i]$, to be inserted into the list.

Constraints

$1\leq n\leq10^5$  
$0\leq a[i]\leq10^5$

Sample Input
STDIN   Function
-----   --------
6       a[] size n = 6
12      a = [12, 4, 5, 3, 8, 7]
4
5
3
8
7

Sample Output
12.0
8.0
5.0
4.5
5.0
6.0

Explanation

There are $n=6$ integers, so we must print the new median on a new line as each integer is added to the list:

$list=\{12\},median=12.0$
$list=\{4,12\},\textit{median}=\frac{4+12}{2}=8.0$
$list=\{4,5,12\},\textit{median}=5.0$
$list=\{3,4,5,12\},\textit{median}=\frac{4+5}{2}=4.5$
$list=\{3,4,5,8,12\},\textit{median}=5.0$
$list=\{3,4,5,7,8,12\},\textit{median}=\frac{5+7}{2}=6.0$

Difficulty: MEDIUM_HARD

Solutions:
import heapq
(L, H) = ([], [])
for _ in range(int(input())):
	a = int(input())
	if not H:
		heapq.heappush(H, a)
	elif len(H) > len(L):
		if H[0] < a:
			b = heapq.heappushpop(H, a)
			heapq.heappush(L, -b)
		else:
			heapq.heappush(L, -a)
	elif -L[0] > a:
		b = -heapq.heappushpop(L, -a)
		heapq.heappush(H, b)
	else:
		heapq.heappush(H, a)
	if len(H) > len(L):
		print('%.1f' % H[0])
	else:
		print('%.1f' % ((H[0] - L[0]) / 2))


def left_child(k):
	return 2 * k + 1

def right_child(k):
	return 2 * k + 2

def parent(k):
	return (k - (2 if k % 2 == 0 else 1)) // 2

def swap(heap, j, k):
	(heap[j], heap[k]) = (heap[k], heap[j])

def push(heap, val):
	heap.append(val)
	siftdown(heap)

def pop(heap):
	k = len(heap) - 1
	swap(heap, 0, k)
	result = heap.pop()
	siftup(heap)
	return result

def peek(heap):
	return heap[0]

def siftdown(heap):
	child = len(heap) - 1
	p = parent(child)
	while child > 0:
		if heap[p] > heap[child]:
			swap(heap, p, child)
			(child, p) = (p, parent(p))
		else:
			break

def siftup(heap):
	size = len(heap)
	p = 0
	(l, r) = (left_child(p), right_child(p))
	while r < size:
		c = l if heap[l] < heap[r] else r
		if heap[c] < heap[p]:
			swap(heap, c, p)
			p = c
			(l, r) = (left_child(p), right_child(p))
		else:
			break
	if l < size and heap[l] < heap[p]:
		swap(heap, l, p)
(max_heap, min_heap) = ([], [])
max_heap_size = min_heap_size = 0
median = 0
n = int(input())
for _ in range(n):
	val = int(input())
	if val > median:
		push(min_heap, val)
		min_heap_size += 1
	else:
		push(max_heap, -val)
		max_heap_size += 1
	if min_heap_size > max_heap_size + 1:
		push(max_heap, -pop(min_heap))
		max_heap_size += 1
		min_heap_size -= 1
	elif max_heap_size > min_heap_size + 1:
		push(min_heap, -pop(max_heap))
		min_heap_size += 1
		max_heap_size -= 1
	if min_heap_size < max_heap_size:
		median = -float(peek(max_heap))
	elif max_heap_size < min_heap_size:
		median = float(peek(min_heap))
	else:
		median = (peek(min_heap) - peek(max_heap)) / 2.0
	print(median)


def find_median(ls):
	t_res = []
	order_l = []
	for (i, item) in enumerate(ls):
		if i == 0:
			order_l.append(item)
		elif item >= order_l[-1]:
			order_l.append(item)
		elif item <= order_l[0]:
			order_l.insert(0, item)
		else:
			length = len(order_l)
			(low, high, res) = (0, length - 1, -1)
			while high >= low:
				middle = (high + low) // 2
				if order_l[middle] == item:
					res = middle
					break
				if order_l[middle] > item:
					if order_l[middle - 1] < item:
						res = middle
						break
					high = middle - 1
				if order_l[middle] < item:
					if order_l[middle + 1] > item:
						res = middle + 1
						break
					low = middle + 1
			order_l.insert(res, item)
		length = len(order_l)
		if length % 2 == 1:
			middle = order_l[length // 2]
		else:
			middle = (order_l[length // 2] + order_l[length // 2 - 1]) / 2
		t_res.append('{:.1f}'.format(middle))
	return t_res
n = int(input())
res = []
for _ in range(n):
	res.append(int(input()))
m_res = find_median(res)
for i in m_res:
	print(i)


import heapq, math
from heapq import heappush
from heapq import heappop
N = int(input())
maxH = []
heappush(maxH, 100000)
minH = []
heappush(minH, 0)
for n in range(0, N):
	i = int(input())
	if i > maxH[0]:
		heappush(maxH, i)
	else:
		heappush(minH, -1 * i)
	diff = len(maxH) - len(minH)
	if diff == 2:
		i = heappop(maxH)
		heappush(minH, -1 * i)
		diff = 0
	elif diff == -1:
		i = heappop(minH)
		heappush(maxH, -1 * i)
		diff = 1
	if diff == 0:
		print((maxH[0] - minH[0]) / 2.0)
	else:
		print(maxH[0] / 1.0)


import bisect
col = []
for i in range(int(input())):
	bisect.insort_left(col, int(input()))
	mid = len(col) // 2
	values = col[mid - i % 2:mid + 1]
	print(sum(values) / len(values))


class Heap:

	def __init__(self, is_min=True):
		self.data = []
		self.is_min = is_min

	def compare(self, i, j):
		if self.is_min:
			return self.data[i] < self.data[j]
		else:
			return self.data[i] > self.data[j]

	def __getitem__(self, i):
		return self.data[i]

	def __bool__(self):
		return bool(self.size)

	def swim(self, i):
		while i != 0 and i // 2 >= 0:
			j = i // 2
			if i % 2 == 0:
				j -= 1
			if self.compare(j, i):
				break
			(self.data[i], self.data[j]) = (self.data[j], self.data[i])
			i = j

	def sink(self, i):
		l = len(self.data)
		while 2 * i + 1 < l:
			next = 2 * i + 1
			if next + 1 < l and self.compare(next + 1, next):
				next = next + 1
			if self.compare(i, next):
				break
			(self.data[i], self.data[next]) = (self.data[next], self.data[i])
			i = next

	def pop(self):
		(self.data[0], self.data[self.size - 1]) = (self.data[self.size - 1], self.data[0])
		ret = self.data.pop()
		self.sink(0)
		return ret

	def append(self, n):
		self.data.append(n)
		self.swim(len(self.data) - 1)

	@property
	def size(self):
		return len(self.data)
n = int(input())
min_heap = Heap(True)
max_heap = Heap(False)
for i in range(n):
	d = int(input())
	if not min_heap or d > min_heap[0]:
		min_heap.append(d)
	else:
		max_heap.append(d)
	if min_heap.size > max_heap.size + 1:
		max_heap.append(min_heap.pop())
	elif max_heap.size > min_heap.size + 1:
		min_heap.append(max_heap.pop())
	if min_heap.size == max_heap.size:
		median = float(min_heap[0] + max_heap[0]) / 2
	elif min_heap.size > max_heap.size:
		median = min_heap[0]
	else:
		median = max_heap[0]
	print('{:.1f}'.format(median))


from heapq import heappush, heappop
n = int(input())
min_heap = []
max_heap = []

def add_to_heaps(num):
	if len(min_heap) == 0 and len(max_heap) == 0:
		heappush(min_heap, num)
	elif len(max_heap) == 0:
		if num < min_heap[0]:
			heappush(max_heap, -num)
		else:
			tmp = heappop(min_heap)
			heappush(max_heap, -tmp)
			heappush(min_heap, num)
	else:
		if num >= min_heap[0]:
			heappush(min_heap, num)
		elif num < min_heap[0] and num > -max_heap[0]:
			if len(min_heap) >= len(max_heap):
				heappush(max_heap, -num)
			else:
				heappush(min_heap, num)
		elif num <= -max_heap[0]:
			heappush(max_heap, -num)
		if len(max_heap) - len(min_heap) > 0:
			heappush(min_heap, -heappop(max_heap))
		elif len(min_heap) - len(max_heap) > 1:
			heappush(max_heap, -heappop(min_heap))
	assert 0 <= len(min_heap) - len(max_heap) <= 1
for i in range(n):
	num = int(input())
	add_to_heaps(num)
	if len(min_heap) > len(max_heap):
		median = float(min_heap[0])
	else:
		assert len(min_heap) == len(max_heap)
		median = (min_heap[0] - max_heap[0]) / 2
	print(median)


import array
import sys
import math

def nice_print(x):
	print('%.1f' % x)

def bisect_insert(a, left, right, x):
	the_range = right - left
	middle = int(math.floor(the_range / 2)) + left
	if a[middle] == x:
		a.insert(middle, x)
	elif a[middle] < x:
		if the_range == 0:
			a.insert(middle, x)
		elif the_range == 1:
			a.insert(middle + 1, x)
		else:
			bisect_insert(a, middle, right, x)
	elif the_range == 0:
		a.insert(max(0, middle - 1), x)
	elif the_range == 1:
		a.insert(max(0, middle - 2), x)
	else:
		bisect_insert(a, left, middle, x)

def do():
	n_numbers = int(sys.stdin.readline()) - 1
	a = array.array('d')
	n = int(sys.stdin.readline())
	a.append(n)
	nice_print(n)
	while n_numbers > 0:
		n = int(sys.stdin.readline())
		bisect_insert(a, 0, len(a), n)
		m = 0
		if len(a) % 2 == 0:
			prev = len(a) // 2 - 1
			next = prev + 1
			m = (a[prev] + a[next]) / 2
		else:
			pos = len(a) // 2
			m = a[pos]
		nice_print(m)
		n_numbers -= 1
do()


import heapq as hq
minheap = []
maxheap = []
N = int(input())
for i in range(0, N):
	x = int(input())
	if i % 2 == 0:
		hq.heappush(maxheap, -1 * x)
		if len(minheap) == 0:
			x = -1 * maxheap[0]
			print(float(x))
			continue
		elif -1 * maxheap[0] > minheap[0]:
			toMin = -1 * hq.heappop(maxheap)
			toMax = hq.heappop(minheap)
			hq.heappush(minheap, toMin)
			hq.heappush(maxheap, -1 * toMax)
		x = -1 * maxheap[0]
		print(float(x))
	else:
		toMin = -1 * hq.heappushpop(maxheap, -1 * x)
		hq.heappush(minheap, toMin)
		x = (-1 * maxheap[0] + minheap[0]) / 2.0
		print(x)


import heapq

class solution:

	def inputList(self, nums):
		if len(nums) < 1:
			return []
		lower = [-nums[0]]
		upper = []
		out = [float(nums[0])]
		for i in range(1, len(nums)):
			if i % 2 == 0:
				d1 = nums[i]
				d2 = heapq.heappop(upper)
				heapq.heappush(lower, -min(d1, d2))
				heapq.heappush(upper, max(d1, d2))
				out.append(round(float(-lower[0]), 1))
			else:
				d1 = nums[i]
				d2 = -heapq.heappop(lower)
				heapq.heappush(upper, max(d1, d2))
				heapq.heappush(lower, -min(d1, d2))
				out.append(round((-lower[0] + upper[0]) / 2, 1))
		return out
n = int(input())
nums = []
for i in range(n):
	nums.append(int(input()))
sol = solution()
result = sol.inputList(nums)
for item in result:
	print(item)


import bisect

def median(nums):
	if len(nums) % 2 == 0:
		return (nums[len(nums) // 2 - 1] + nums[len(nums) // 2]) / 2
	else:
		return nums[len(nums) // 2]
t = int(input())
nums = []
for _ in range(t):
	if nums == []:
		nums.append(int(input()))
		print(float(nums[0]))
		continue
	n = int(input())
	numLen = len(nums)
	bisect.insort(nums, n)
	print(float(median(nums)))


from abc import ABCMeta, abstractmethod

class Heap:
	__metaclass__ = ABCMeta

	def __init__(self):
		self.items = []

	@abstractmethod
	def insert(self, e):
		pass

	def top(self):
		return self.items[0]

	def parent(self, i):
		return i // 2

	def left(self, i):
		return i * 2

	def right(self, i):
		return i * 2 + 1

	def size(self):
		return len(self.items)

	def extract(self):
		v = self.items[0]
		self.items[0] = self.items[-1]
		self.items.pop()
		self.heapify(0)
		return v

	@abstractmethod
	def heapify(self, i):
		pass

class MinHeap(Heap):

	def insert(self, e):
		self.items.append(e)
		i = self.size() - 1
		while i > 0 and self.items[self.parent(i)] >= self.items[i]:
			(self.items[i], self.items[self.parent(i)]) = (self.items[self.parent(i)], self.items[i])
			i = self.parent(i)

	def heapify(self, i):
		(l, r) = (self.left(i), self.right(i))
		if l < self.size() and self.items[i] > self.items[l]:
			smallest = l
		else:
			smallest = i
		if r < self.size() and self.items[smallest] > self.items[r]:
			smallest = r
		if smallest != i:
			(self.items[i], self.items[smallest]) = (self.items[smallest], self.items[i])
			self.heapify(smallest)

class MaxHeap(Heap):

	def insert(self, e):
		self.items.append(e)
		i = self.size() - 1
		while i > 0 and self.items[self.parent(i)] <= self.items[i]:
			(self.items[i], self.items[self.parent(i)]) = (self.items[self.parent(i)], self.items[i])
			i = self.parent(i)

	def heapify(self, i):
		(l, r) = (self.left(i), self.right(i))
		if l < self.size() and self.items[i] < self.items[l]:
			largest = l
		else:
			largest = i
		if r < self.size() and self.items[largest] < self.items[r]:
			largest = r
		if largest != i:
			(self.items[i], self.items[largest]) = (self.items[largest], self.items[i])
			self.heapify(largest)
maxheap = MaxHeap()
minheap = MinHeap()
n = int(input())
median = int(input())
print(float(median))
maxheap.insert(median)
for i in range(1, n):
	num = int(input())
	if num > median:
		minheap.insert(num)
	else:
		maxheap.insert(num)
	if maxheap.size() > minheap.size() + 1:
		v = maxheap.extract()
		minheap.insert(v)
	if minheap.size() > maxheap.size() + 1:
		v = minheap.extract()
		maxheap.insert(v)
	if i % 2 == 1:
		median = (maxheap.top() + minheap.top()) / 2
	elif minheap.size() > maxheap.size():
		median = minheap.top()
	else:
		median = maxheap.top()
	print(float(median))


count = int(input())

def rough_bin_search(l, val):
	mid = start = 0
	end = len(l)
	while start < end:
		mid = (start + end) // 2
		if l[mid] == val:
			break
		elif start == mid:
			if val > l[mid]:
				mid = mid + 1
			break
		elif l[mid] < val:
			start = mid
		else:
			end = mid
	return mid
l = []
while count > 0:
	count -= 1
	val = int(input())
	l.insert(rough_bin_search(l, val), val)
	if len(l) % 2 == 1:
		print('{:.1f}'.format(l[len(l) // 2]))
	else:
		lowmid = l[len(l) // 2 - 1]
		upmid = l[len(l) // 2]
		median = (lowmid + upmid) / 2.0
		print('{:.1f}'.format(median))


from heapq import heappush, heappop
heap_lower = []
heap_upper = []
N = int(input())
for i in range(0, N):
	k = int(input())
	if heap_upper and heap_upper[0] < k:
		heappush(heap_upper, k)
	else:
		heappush(heap_lower, -k)
	while len(heap_lower) > len(heap_upper) + 1:
		heappush(heap_upper, -heappop(heap_lower))
	while len(heap_lower) + 1 < len(heap_upper):
		heappush(heap_lower, -heappop(heap_upper))
	if len(heap_upper) > len(heap_lower):
		print(float(heap_upper[0]))
	elif len(heap_upper) < len(heap_lower):
		print(-float(heap_lower[0]))
	else:
		print((-heap_lower[0] + heap_upper[0]) / 2.0)


import heapq

class MinHeap:

	def __init__(self):
		self._heap = []

	def extract_min(self):
		return heapq.heappop(self._heap)

	def find_min(self):
		return self._heap[0]

	def insert(self, n):
		heapq.heappush(self._heap, n)

class MaxHeap:

	def __init__(self):
		self._heap = []

	def insert(self, n):
		heapq.heappush(self._heap, -n)

	def extract_max(self):
		return -heapq.heappop(self._heap)

	def find_max(self):
		return -self._heap[0]
N = int(input())
min_heap = MinHeap()
max_heap = MaxHeap()
for i in range(N):
	a = int(input())
	if i == 0:
		max_heap.insert(a)
		print(float(a))
	elif i == 1:
		b = max_heap.find_max()
		if b < a:
			min_heap.insert(a)
		else:
			b = max_heap.extract_max()
			max_heap.insert(a)
			min_heap.insert(b)
		print((a + b) / 2)
	elif i % 2 == 0:
		left = max_heap.find_max()
		right = min_heap.find_min()
		if a > right:
			right = min_heap.extract_min()
			min_heap.insert(a)
			max_heap.insert(right)
		else:
			max_heap.insert(a)
		left = max_heap.find_max()
		print(float(left))
	else:
		left = max_heap.find_max()
		right = min_heap.find_min()
		if a < left:
			left = max_heap.extract_max()
			max_heap.insert(a)
			min_heap.insert(left)
		else:
			min_heap.insert(a)
		left = max_heap.find_max()
		right = min_heap.find_min()
		print((left + right) / 2)


import bisect
import sys
from math import floor
array = []
for line in sys.stdin.readlines()[1:]:
	n = int(line.strip())
	bisect.insort_right(array, n)
	if len(array) == 1:
		print('%.1f' % array[0])
	elif len(array) % 2 == 0:
		idx = floor(len(array) / 2) - 1
		print('%.1f' % ((array[idx] + array[idx + 1]) / 2))
	else:
		print('%.1f' % array[len(array) // 2])


from bisect import insort
size = int(input())
lst = []

def median(sortedLst):
	lstLen = len(lst)
	index = (lstLen - 1) // 2
	if lstLen % 2:
		return sortedLst[index] * 1.0
	else:
		return (sortedLst[index] + sortedLst[index + 1]) / 2.0
for i in range(size):
	nr = int(input())
	insort(lst, nr)
	print(median(lst))


from math import floor, log
import heapq

def log2(x):
	return log(x) / log(2)

class Heap(object):

	def __init__(self, max_=False, col=[]):
		self.max_heap = max_
		self.array = list(col)
		self.Heapify()

	def Add(self, val):
		heapq.heappush(self.array, val)

	def Heapify(self):
		heapq.heapify(self.array)

	def last_index(self):
		return len(self.array) - 1

	def get_top(self):
		if self.Size() > 0:
			return self.array[0]
		else:
			return None

	def HeapPushPop(self, val):
		return heapq.heappushpop(self.array, val)

	def HeapReplace(self, val):
		return heapq.heapreplace(self.array, val)

	def extract_top(self):
		return heapq.heappop(self.array)

	def __str__(self):
		return str(self.array)

	def __repr__(self):
		return str(self)

	def Size(self):
		return len(self.array)

	def __getitem__(self, key):
		return self.array[key]

	def __setitem__(self, key, val):
		self.array[key] = val

class MaxHeap(Heap):

	def __init__(self, col=[]):
		colinv = [-x for x in col]
		Heap.__init__(self, True, colinv)

	def Add(self, val):
		Heap.Add(self, -val)

	def extract_top(self):
		val = Heap.extract_top(self)
		return -val

	def __getitem__(self, key):
		return -self.array[key]

	def __setitem__(self, key, val):
		self.array[key] = -val

	def get_top(self):
		val = Heap.get_top(self)
		return -val if val else None

	def HeapReplace(self, val):
		return -Heap.HeapReplace(self, -val)

	def HeapPushPop(self, val):
		return -Heap.HeapPushPop(self, -val)

class MinHeap(Heap):

	def __init__(self, col=[]):
		Heap.__init__(self, False, col)

def GetMedian(heap1, heap2):
	sz1 = heap1.Size()
	sz2 = heap2.Size()
	if sz2 == sz1:
		res = (heap2.get_top() + heap1.get_top()) / 2
	else:
		res = heap1.get_top() if sz1 > sz2 else heap2.get_top()
	return float(res)

def AddNumberToHeaps(over, under, n):
	sz_over = over.Size()
	sz_under = under.Size()
	if sz_under > sz_over:
		top_under = under.get_top() or -1
		if n < top_under:
			tmp = under.HeapReplace(n)
			over.Add(tmp)
		else:
			over.Add(n)
	else:
		top_over = over.get_top() or 100000000000.0
		if n > top_over:
			tmp = over.HeapReplace(n)
			under.Add(tmp)
		else:
			under.Add(n)

def ProcessMedian(lst):
	under = MaxHeap()
	over = MinHeap()
	res = []
	for n in lst:
		AddNumberToHeaps(over, under, n)
		res.append(GetMedian(under, over))
	return res

def GetValuesFromConsole():
	T = int(input())
	nums = []
	for it in range(T):
		nums.append(int(input()))
	return nums
nums = GetValuesFromConsole()
res = ProcessMedian(nums)
for val in res:
	print(val)


import bisect

def median(midlist):
	lens = len(midlist)
	if lens % 2 != 0:
		midl = int(lens / 2)
		res = midlist[midl]
	else:
		odd = int(lens / 2) - 1
		ev = int(lens / 2)
		res = float(midlist[odd] + midlist[ev]) / float(2)
	return res
tc = int(input())
ar = []
while tc > 0:
	tc -= 1
	bisect.insort(ar, int(input()))
	print(float(median(ar)))


import heapq

class MedianIntegerStream:

	def __init__(self):
		self.min_heap = list()
		self.max_heap = list()
		self.total_numbers = 0

	def insert(self, number):
		if self.total_numbers % 2 != 0:
			num_for_min_heap = -1 * heapq.heappushpop(self.max_heap, -1 * number)
			heapq.heappush(self.min_heap, num_for_min_heap)
			self.total_numbers += 1
			return
		heapq.heappush(self.max_heap, -1 * number)
		self.total_numbers += 1
		if len(self.min_heap) == 0:
			return
		if -1 * self.max_heap[0] <= self.min_heap[0]:
			return
		num_for_min_heap = -1 * heapq.heappop(self.max_heap)
		num_for_max_heap = heapq.heappop(self.min_heap)
		heapq.heappush(self.max_heap, -1 * num_for_max_heap)
		heapq.heappush(self.min_heap, num_for_min_heap)

	def get_median(self):
		if self.total_numbers % 2 != 0:
			return -1 * self.max_heap[0]
		return (-1 * self.max_heap[0] + self.min_heap[0]) / 2
stream = MedianIntegerStream()
for _ in range(int(input())):
	stream.insert(int(input()))
	print('%.1f' % stream.get_median())


num = int(input())
lst = []

def binary_search(lst, number):
	first = 0
	last = len(lst) - 1
	midpoint = 0
	while first <= last:
		midpoint = (first + last) // 2
		if lst[midpoint] == number:
			return midpoint
		elif number < lst[midpoint]:
			last = midpoint - 1
		else:
			first = midpoint + 1
	if first > last:
		return first
	else:
		return last

def find_median(lst):
	length = len(lst)
	if length % 2 == 0:
		return lst[length // 2] / 2 + lst[length // 2 - 1] / 2
	else:
		return lst[length // 2]
for i in range(num):
	number = int(input())
	lst.insert(binary_search(lst, number), number)
	print(float(find_median(lst)))


from heapq import heappush, heappushpop
n = int(input())
lo = []
hi = []
for i in range(n):
	a = int(input())
	if lo and a > -lo[0]:
		if len(hi) > len(lo):
			heappush(lo, -heappushpop(hi, a))
			m = (hi[0] - lo[0]) / 2
		else:
			heappush(hi, a)
			if len(hi) > len(lo):
				m = hi[0]
			else:
				m = (hi[0] - lo[0]) / 2
	elif len(lo) > len(hi):
		heappush(hi, -heappushpop(lo, -a))
		m = (hi[0] - lo[0]) / 2
	else:
		heappush(lo, -a)
		if len(lo) > len(hi):
			m = -lo[0]
		else:
			m = (hi[0] - lo[0]) / 2
	print('{:.1f}'.format(m))


import sys, heapq
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
minHeap = []
maxHeap = []
median = 0
for line in lines:
	element = int(line.strip())
	if element > median:
		heapq.heappush(minHeap, element)
	else:
		heapq.heappush(maxHeap, element * -1)
	if len(minHeap) - len(maxHeap) > 1:
		heapq.heappush(maxHeap, heapq.heappop(minHeap) * -1)
	elif len(maxHeap) - len(minHeap) > 1:
		heapq.heappush(minHeap, heapq.heappop(maxHeap) * -1)
	if len(minHeap) > len(maxHeap):
		median = minHeap[0]
	elif len(minHeap) < len(maxHeap):
		median = maxHeap[0] * -1
	else:
		median = (minHeap[0] + maxHeap[0] * -1) / 2
	print(float(median))


from heapq import heappush, heappushpop

def printn(n):
	print('{:.01f}'.format(n))
N = int(input())
for i in range(min(N, 2)):
	a = int(input())
	if i == 0:
		printn(a)
		max_heap = [-a]
	else:
		printn((a + -max_heap[0]) / 2)
		if a >= -max_heap[0]:
			min_heap = [a]
		else:
			min_heap = [-max_heap[0]]
			max_heap = [-a]
for i in range(2, N):
	a = int(input())
	if i % 2:
		if len(max_heap) < (i + 1) // 2:
			if a <= -max_heap[0]:
				heappush(max_heap, -a)
			else:
				a = heappushpop(min_heap, a)
				heappush(max_heap, -a)
		elif a >= min_heap[0]:
			heappush(min_heap, a)
		else:
			a = -heappushpop(max_heap, -a)
			heappush(min_heap, a)
		printn((min_heap[0] + -max_heap[0]) / 2)
	elif a <= -max_heap[0]:
		heappush(max_heap, -a)
		printn(-max_heap[0])
	else:
		heappush(min_heap, a)
		printn(min_heap[0])


from heapq import *
N = int(input())
lower = []
upper = []
midlow = midup = 0
for i in range(N):
	val = float(input())
	if val >= midup:
		heappush(upper, val)
		midup = val
	else:
		heappush(lower, -val)
		midlow = val
	if len(upper) > len(lower) + 1:
		heappush(lower, -heappop(upper))
	if len(lower) > len(upper) + 1:
		heappush(upper, -heappop(lower))
	if lower:
		midlow = -lower[0]
	if upper:
		midup = upper[0]
	if len(lower) == len(upper):
		print((midlow + midup) / 2.0)
	elif len(lower) > len(upper):
		print(midlow)
	else:
		print(midup)


import bisect
col = []
for i in range(int(input())):
	bisect.insort_left(col, int(input()))
	mid = len(col) // 2
	values = col[mid - i % 2:mid + 1]
	print(sum(values) / len(values))


from bisect import insort
from math import floor, ceil
lst = []
for i in range(int(input().strip())):
	insort(lst, int(input().strip()))
	m = (lst[floor(i / 2)] + lst[ceil(i / 2)]) / 2
	print('%.1f' % m)


import heapq
n = int(input().strip())
num_list = []
less = []
more = []
equal = []
for i in range(n):
	num = int(input().strip())
	if i == 0:
		median = num
		num_list.append(num)
	elif i < 3:
		num_list.append(num)
		num_list.sort()
		if len(num_list) % 2 == 0:
			index = len(num_list) // 2 - 1
			median = (num_list[index] + num_list[index + 1]) / 2
		else:
			index = len(num_list) // 2
			median = num_list[index]
		if i == 2:
			less.append(-1 * num_list[1])
			less.append(-1 * num_list[0])
			more.append(num_list[2])
			heapq.heapify(less)
			heapq.heapify(more)
			nodes = 3
	elif nodes % 2 == 0:
		heapq.heappush(less, -1 * num)
		if less[0] * -1 > more[0]:
			temp = heapq.heappop(less) * -1
			heapq.heappush(less, -1 * heapq.heappop(more))
			heapq.heappush(more, temp)
		nodes += 1
		median = -1 * less[0]
	else:
		heapq.heappush(more, num)
		if less[0] * -1 > more[0]:
			temp = heapq.heappop(less) * -1
			heapq.heappush(less, -1 * heapq.heappop(more))
			heapq.heappush(more, temp)
		nodes += 1
		median = (-1 * less[0] + more[0]) / 2
	print('{0:.1f}'.format(median))


import heapq
maxx = []
minx = []

def get_median(x):
	if len(minx) > 0 and x < minx[0] and (len(minx) >= len(maxx)) or (len(maxx) > 0 and x < -maxx[0]):
		if len(maxx) > len(minx):
			max_v = -heapq.heappop(maxx)
			heapq.heappush(minx, max_v)
		heapq.heappush(maxx, -x)
	else:
		if len(minx) > len(maxx):
			min_v = heapq.heappop(minx)
			heapq.heappush(maxx, -min_v)
		heapq.heappush(minx, x)
	if len(maxx) > len(minx):
		return float(-maxx[0])
	elif len(minx) > len(maxx):
		return float(minx[0])
	else:
		return float((minx[0] - maxx[0]) / 2)

def local():
	with open('../../tests/find-median/1.txt') as f:
		n = int(f.readline())
		while n > 0:
			num = int(f.readline())
			res = get_median(int(num))
			print('{:.1f}'.format(res))
			n -= 1

def server():
	n = int(input())
	while n > 0:
		num = input()
		res = get_median(int(num))
		print('{:.1f}'.format(res))
		n -= 1
server()


num = int(input().strip())
import heapq
smaller = []
bigger = []
j = 0
for run in range(num):
	i = int(input().strip())
	if j == 0:
		smaller.append(-1 * i)
		heapq.heapify(smaller)
		j += 1
	elif -1 * i < smaller[0]:
		if len(bigger) == 0:
			bigger.append(i)
			heapq.heapify(bigger)
		else:
			heapq.heappush(bigger, i)
	else:
		heapq.heappush(smaller, -1 * i)
	if len(bigger) - len(smaller) > 1:
		trans = heapq.heappop(bigger)
		heapq.heappush(smaller, -1 * trans)
	elif len(smaller) - len(bigger) > 1:
		trans = heapq.heappop(smaller)
		heapq.heappush(bigger, -1 * trans)
	if len(bigger) == len(smaller):
		med = (-1 * smaller[0] + bigger[0]) / 2
	elif len(bigger) - len(smaller) == 1:
		med = bigger[0]
	elif len(smaller) - len(bigger) == 1:
		med = -1 * smaller[0]
	print('{:.1f}'.format(med))


import heapq
less = []
more = []

def med():
	if not less and (not more):
		return 9e+99
	if len(less) > len(more):
		return -less[0]
	return (more[0] - less[0]) / 2
for i in range(int(input())):
	x = float(input())
	if x < med():
		heapq.heappush(less, -x)
	else:
		heapq.heappush(more, x)
	while more and -less[0] > more[0] or len(less) > len(more) + 1:
		heapq.heappush(more, -heapq.heappop(less))
	while len(more) > len(less):
		heapq.heappush(less, -heapq.heappop(more))
	print(med())


import heapq

class OnlineMedian(object):

	def __init__(self):
		self.small = []
		self.large = []

	def add(self, elm):
		if len(self.small) + len(self.large) == 0:
			self.small.append(-elm)
		elif elm > self.median():
			heapq.heappush(self.large, elm)
		else:
			heapq.heappush(self.small, -elm)
		self.balance()

	def balance(self):
		if len(self.small) > len(self.large) + 1:
			move = heapq.heappop(self.small)
			heapq.heappush(self.large, -move)
		elif len(self.large) > len(self.small) + 1:
			move = heapq.heappop(self.large)
			heapq.heappush(self.small, -move)

	def median(self):
		med = None
		if not len(self.small):
			med = self.large[0]
		elif not len(self.large):
			med = -self.small[0]
		elif len(self.small) > len(self.large):
			med = -self.small[0]
		elif len(self.large) > len(self.small):
			med = self.large[0]
		else:
			med = (self.large[0] - self.small[0]) / 2
		return float(med)

def main():
	size = int(input(''))
	med = OnlineMedian()
	for _ in range(size):
		med.add(int(input('')))
		print('%.1f' % med.median())
main()


import math, heapq
minH = []
maxH = []
median = [10 ** 6]
for _ in range(int(input())):
	temp = float(input())
	if temp >= median[-1]:
		heapq.heappush(minH, temp)
	else:
		heapq.heappush(maxH, -temp)
	lenMin = len(minH)
	lenMax = len(maxH)
	if lenMin - lenMax == 2:
		heapq.heappush(maxH, -heapq.heappop(minH))
		lenMin -= 1
		lenMax += 1
	elif lenMax - lenMin == 2:
		heapq.heappush(minH, abs(heapq.heappop(maxH)))
		lenMin += 1
		lenMax -= 1
	if lenMin == lenMax:
		median.append((abs(maxH[0]) + minH[0]) / 2)
	elif lenMin > lenMax:
		median.append(minH[0])
	else:
		median.append(abs(maxH[0]))
print('\n'.join([str(x) for x in median[1:]]))


import heapq

def median(min_heap, max_heap):
	if len(min_heap) == len(max_heap):
		return (min_heap[0] - max_heap[0]) / 2
	else:
		return -max_heap[0]
N = int(input())
min_heap = []
max_heap = []
for i in range(N):
	a = int(input())
	if min_heap and a > min_heap[0]:
		heapq.heappush(min_heap, a)
		if len(min_heap) > len(max_heap):
			heapq.heappush(max_heap, -heapq.heappop(min_heap))
	else:
		heapq.heappush(max_heap, -a)
		if len(max_heap) > len(min_heap) + 1:
			heapq.heappush(min_heap, -heapq.heappop(max_heap))
	print('{0:0.1f}'.format(median(min_heap, max_heap)))


import heapq

def median(min_heap, max_heap):
	if len(min_heap) == len(max_heap):
		return (min_heap[0] - max_heap[0]) / 2
	else:
		return -max_heap[0]
N = int(input())
min_heap = []
max_heap = []
for i in range(N):
	a = int(input())
	if min_heap and a > min_heap[0]:
		heapq.heappush(min_heap, a)
		if len(min_heap) > len(max_heap):
			heapq.heappush(max_heap, -heapq.heappop(min_heap))
	else:
		heapq.heappush(max_heap, -a)
		if len(max_heap) > len(min_heap) + 1:
			heapq.heappush(min_heap, -heapq.heappop(max_heap))
	print('{0:0.1f}'.format(median(min_heap, max_heap)))


import bisect
N = int(input())
x = int(input())
print('%.1f' % x)
a = [x]
for i in range(2, N + 1):
	x = int(input())
	bisect.insort(a, x)
	if i % 2 == 0:
		median = (a[i // 2 - 1] + a[i // 2]) / 2.0
	else:
		median = float(a[i // 2])
	print('%.1f' % median)


import heapq

def median(min_heap, max_heap):
	if len(min_heap) == len(max_heap):
		return (min_heap[0] - max_heap[0]) / 2
	else:
		return -max_heap[0]
N = int(input())
min_heap = []
max_heap = []
for i in range(N):
	a = int(input())
	if min_heap and a > min_heap[0]:
		heapq.heappush(min_heap, a)
		if len(min_heap) > len(max_heap):
			heapq.heappush(max_heap, -heapq.heappop(min_heap))
	else:
		heapq.heappush(max_heap, -a)
		if len(max_heap) > len(min_heap) + 1:
			heapq.heappush(min_heap, -heapq.heappop(max_heap))
	print('{0:0.1f}'.format(median(min_heap, max_heap)))


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []
		self.size = 0

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.size += 1
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


class heap:

	def __init__(self):
		self.arr = []
		self.size = 0

	def get_top(self):
		if self.size > 0:
			return self.arr[0]

	def left_child(self, i):
		return 2 * i + 1

	def right_child(self, i):
		return 2 * i + 2

	def parent(self, i):
		return (i - 1) // 2

	def bubble_up(self, i):
		curr = i
		while curr > 0:
			par = self.parent(curr)
			if self.arr[curr] < self.arr[par]:
				(self.arr[curr], self.arr[par]) = (self.arr[par], self.arr[curr])
				curr = par
			else:
				break

	def bubble_down(self, i):
		curr = i
		while self.left_child(curr) < self.size:
			if self.right_child(curr) >= self.size or self.arr[self.left_child(curr)] <= self.arr[self.right_child(curr)]:
				chil = self.left_child(curr)
			else:
				chil = self.right_child(curr)
			if self.arr[curr] > self.arr[chil]:
				(self.arr[curr], self.arr[chil]) = (self.arr[chil], self.arr[curr])
				curr = chil
			else:
				break

	def add(self, v):
		self.arr.append(v)
		self.bubble_up(self.size)
		self.size += 1

	def delete(self, v):
		i = self.arr.index(v)
		if i == self.size - 1:
			self.arr.pop()
			self.size -= 1
			return
		self.arr[i] = self.arr.pop()
		self.size -= 1
		self.bubble_up(i)
		self.bubble_down(i)
minh = heap()
maxh = heap()
for _ in range(int(input())):
	v = int(input())
	if maxh.size == 0 or v <= -maxh.get_top():
		maxh.add(-v)
	else:
		minh.add(v)
	while abs(maxh.size - minh.size) > 1:
		if maxh.size > minh.size:
			top = -maxh.get_top()
			minh.add(top)
			maxh.delete(-top)
		else:
			top = minh.get_top()
			maxh.add(-top)
			minh.delete(top)
	if maxh.size == minh.size:
		print((minh.get_top() - maxh.get_top()) / 2)
	elif maxh.size == minh.size + 1:
		print(float(-maxh.get_top()))
	else:
		print(float(minh.get_top()))


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


import heapq
N = int(input())
if N == 1:
	print('{:.1f}'.format(int(input())))
elif N == 2:
	print('{:.1f}'.format((int(input()) + int(input())) / 2.0))
else:
	maxh = []
	minh = []
	(x, y) = (int(input()), int(input()))
	if x < y:
		heapq.heappush(maxh, -x)
		heapq.heappush(minh, y)
	else:
		heapq.heappush(maxh, -y)
		heapq.heappush(minh, x)
	print('{:.1f}'.format(x))
	print('{:.1f}'.format((x + y) / 2.0))
	for i in range(2, N):
		z = int(input())
		if i % 2 == 0:
			if z <= minh[0]:
				heapq.heappush(maxh, -z)
			else:
				aux = heapq.heapreplace(minh, z)
				heapq.heappush(maxh, -aux)
			print('{:.1f}'.format(float(-maxh[0])))
		else:
			if z > -maxh[0]:
				heapq.heappush(minh, z)
			else:
				aux = heapq.heapreplace(maxh, -z)
				heapq.heappush(minh, -aux)
			print('{:.1f}'.format((-maxh[0] + minh[0]) / 2.0))


class Heap:

	def __init__(self, ismin=True):
		self.arr = []
		self.m = ismin

	def swap(self, i, j):
		temp = self.arr[i]
		self.arr[i] = self.arr[j]
		self.arr[j] = temp

	def heapifyUp(self, i):
		if i == 0:
			return
		if self.m:
			if self.arr[i] < self.arr[i // 2]:
				self.swap(i, i // 2)
				self.heapifyUp(i // 2)
		elif self.arr[i] > self.arr[i // 2]:
			self.swap(i, i // 2)
			self.heapifyUp(i // 2)

	def heapifyDown(self, i):
		if self.m:
			if i * 2 < len(self.arr):
				j = i * 2
				m = self.arr[j]
				if j + 1 < len(self.arr) and m > self.arr[j + 1]:
					j = j + 1
					m = self.arr[j]
				if m < self.arr[i]:
					self.swap(i, j)
					self.heapifyDown(j)
		elif i * 2 < len(self.arr):
			j = i * 2
			m = self.arr[j]
			if j + 1 < len(self.arr) and m < self.arr[j + 1]:
				j = j + 1
				m = self.arr[j]
			if m > self.arr[i]:
				self.swap(i, j)
				self.heapifyDown(j)

	def add(self, v):
		self.arr.append(v)
		self.heapifyUp(len(self.arr) - 1)

	def root(self):
		return self.arr[0]

	def len(self):
		return len(self.arr)

	def remove(self, v):
		k = len(self.arr) - 1
		i = self.arr.index(v)
		self.swap(i, k)
		del self.arr[k]
		self.heapifyDown(i)
n = int(input().strip())
r = Heap()
l = Heap(ismin=False)
i = 0
while i < n:
	if i % 2 == 0:
		l.add(int(input().strip()))
		if r.len() > 0 and r.root() < l.root():
			t = r.root()
			r.remove(t)
			r.add(l.root())
			l.remove(l.root())
			l.add(t)
		print('%.1f' % (l.root() / 1.0))
	else:
		r.add(int(input().strip()))
		if r.root() < l.root():
			t = r.root()
			r.remove(t)
			r.add(l.root())
			l.remove(l.root())
			l.add(t)
		print('%.1f' % ((l.root() + r.root()) / 2.0))
	i += 1


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


def min_heapify(A, i):
	l = i * 2 + 1
	r = i * 2 + 2
	n = len(A)
	i_sm = i
	if l < n and A[l] < A[i]:
		i_sm = l
	if r < n and A[r] < A[i_sm]:
		i_sm = r
	if i != i_sm:
		(A[i], A[i_sm]) = (A[i_sm], A[i])
		min_heapify(A, i_sm)

def max_heapify(A, i):
	l = i * 2 + 1
	r = i * 2 + 2
	n = len(A)
	i_lg = i
	if l < n and A[l] > A[i]:
		i_lg = l
	if r < n and A[r] > A[i_lg]:
		i_lg = r
	if i != i_lg:
		(A[i], A[i_lg]) = (A[i_lg], A[i])
		max_heapify(A, i_lg)

def min_bubble_up(A, i):
	p = (i - 1) // 2
	if p >= 0 and A[i] < A[p]:
		(A[p], A[i]) = (A[i], A[p])
		min_bubble_up(A, p)

def max_bubble_up(A, i):
	p = (i - 1) // 2
	if p >= 0 and A[i] > A[p]:
		(A[p], A[i]) = (A[i], A[p])
		max_bubble_up(A, p)

def extract_max(A):
	n = len(A)
	i_n = n - 1
	if n < 1:
		raise ValueError('Heap underflow')
	elif n == 1:
		return A.pop(0)
	elif n > 1:
		m = A[0]
		A[0] = A.pop(i_n)
		max_heapify(A, 0)
		return m

def extract_min(A):
	n = len(A)
	i_n = n - 1
	if n < 1:
		raise ValueError('Heap underflow')
	elif n == 1:
		return A.pop(0)
	elif n > 1:
		m = A[0]
		A[0] = A.pop(i_n)
		min_heapify(A, 0)
		return m

def min_insert(A, z):
	A.append(z)
	n = len(A)
	if n > 1:
		i_n = n - 1
		min_bubble_up(A, i_n)

def max_insert(A, z):
	A.append(z)
	n = len(A)
	if n > 1:
		i_n = n - 1
		max_bubble_up(A, i_n)

def get_median(A, B):
	l_a = len(A)
	l_b = len(B)
	if l_a == 0 and l_b == 0:
		return 0
	if l_a == l_b:
		return abs(A[0] + B[0]) / 2.0
	elif l_a > l_b:
		return A[0]
	elif l_b > l_a:
		return B[0]

def rebalance(MAX, MIN):
	l_max = len(MAX)
	l_min = len(MIN)
	if abs(l_max - l_min) > 1:
		if l_max > l_min:
			z = extract_max(MAX)
			min_insert(MIN, z)
		elif l_min > l_max:
			z = extract_min(MIN)
			max_insert(MAX, z)

def update(z, MAX, MIN):
	if len(MAX) == 0 and len(MIN) == 0 or z < MAX[0]:
		max_insert(MAX, z)
	else:
		min_insert(MIN, z)
	if abs(len(MAX) - len(MIN)) > 1:
		rebalance(MAX, MIN)
hmax = []
hmin = []
q = int(input())
for i in range(0, q):
	try:
		x = int(input())
	except Exception as e:
		pass
	update(x, hmax, hmin)
	print('{:3.1f}'.format(get_median(hmax, hmin)))


import sys
import math
import heapq

class MidHeap:

	def __init__(self):
		self.minH = []
		self.minS = 0
		self.maxH = []
		self.maxS = 0

	def median(self):
		if self.minS == 0 and self.maxS == 0:
			return 0
		if self.minS > self.maxS:
			med = self.minH[0]
		elif self.maxS > self.minS:
			med = self.maxH[0] * -1
		else:
			med = (float(self.minH[0]) + self.maxH[0] * -1) / 2
		return float(med)

	def insert(self, x):
		if x > self.median():
			heapq.heappush(self.minH, x)
			self.minS = self.minS + 1
		else:
			heapq.heappush(self.maxH, x * -1)
			self.maxS = self.maxS + 1
		if self.minS - self.maxS > 1:
			heapq.heappush(self.maxH, heapq.heappop(self.minH) * -1)
			self.minS = self.minS - 1
			self.maxS = self.maxS + 1
		elif self.maxS - self.minS > 1:
			heapq.heappush(self.minH, heapq.heappop(self.maxH) * -1)
			self.minS = self.minS + 1
			self.maxS = self.maxS - 1

	def printHeaps(self):
		print('MinH: ', self.minH)
		print('MaxH: ', self.maxH)
t = int(input().strip())
midH = MidHeap()
for a0 in range(t):
	x = int(input().strip())
	midH.insert(x)
	print(midH.median())


class SortedList:

	def __init__(self):
		self.list = []

	def insert(self, value):
		if len(self.list) == 0:
			self.list.append(value)
		elif self.list[0] > value:
			self.list.insert(0, value)
		elif self.list[-1] < value:
			self.list.append(value)
		else:
			front = 0
			end = len(self.list) - 1
			while True:
				mid = (front + end) // 2
				if self.list[mid] < value:
					if front == mid:
						self.list.insert(mid + 1, value)
						return
					else:
						front = mid
				elif self.list[mid] > value:
					end = mid
				elif self.list[mid] == value:
					self.list.insert(mid, value)
					return

	def get_median(self):
		if len(self.list) % 2 == 0:
			return (self.list[len(self.list) // 2] + self.list[len(self.list) // 2 - 1]) / 2
		else:
			return self.list[len(self.list) // 2]
n = int(input())
a = SortedList()
for i in range(n):
	a.insert(int(input()))
	print('{:.1f}'.format(a.get_median()))


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


import heapq

class MedianTracker:

	def __init__(self):
		self.first_half = []
		self.second_half = []

	def insert(self, item):
		if self.first_half == [] or item < -self.first_half[0]:
			heapq.heappush(self.first_half, -item)
		else:
			heapq.heappush(self.second_half, item)
		self.rebalance()

	def rebalance(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len - second_len > 1:
			elt = -heapq.heappop(self.first_half)
			heapq.heappush(self.second_half, elt)
		elif second_len - first_len > 1:
			elt = -heapq.heappop(self.second_half)
			heapq.heappush(self.first_half, elt)

	def median(self):
		first_len = len(self.first_half)
		second_len = len(self.second_half)
		if first_len > second_len:
			result = -self.first_half[0]
		elif second_len > first_len:
			result = self.second_half[0]
		else:
			result = (-self.first_half[0] + self.second_half[0]) / 2
		return '{:.1f}'.format(result)
t = int(input())
mt = MedianTracker()
for _ in range(t):
	mt.insert(int(input()))
	print(mt.median())


from heapq import heappush, heappop
N = int(input())
min_heap = []
max_heap = []
for i in range(N):
	num = int(input())
	if i == 0:
		heappush(max_heap, -num)
		print('{0:.1f}'.format(float(num)))
		continue
	elif num <= -max_heap[0]:
		heappush(max_heap, -num)
	else:
		heappush(min_heap, num)
	if len(max_heap) < len(min_heap) - 1:
		heappush(max_heap, -heappop(min_heap))
	elif len(min_heap) < len(max_heap) - 1:
		heappush(min_heap, -heappop(max_heap))
	current_median = float(0)
	if len(min_heap) == len(max_heap):
		current_median = (float(-max_heap[0]) + float(min_heap[0])) / float(2)
	elif len(min_heap) > len(max_heap):
		current_median = float(min_heap[0])
	else:
		current_median = float(-max_heap[0])
	print('{0:.1f}'.format(current_median))


import heapq
N = int(input())
maxheap = []
minheap = []

def get_median():
	lmin = len(minheap)
	lmax = len(maxheap)
	if lmax > lmin:
		return float(-maxheap[0])
	elif lmin > lmax:
		return float(minheap[0])
	else:
		return float((minheap[0] - maxheap[0]) / 2)
for _ in range(N):
	v = int(input())
	if not minheap:
		heapq.heappush(minheap, v)
	elif v < minheap[0]:
		heapq.heappush(maxheap, -v)
	elif v > minheap[0]:
		heapq.heappush(minheap, v)
	else:
		heapq.heappush(minheap, v)
	lmin = len(minheap)
	lmax = len(maxheap)
	if lmin - 1 > lmax:
		heapq.heappush(maxheap, -heapq.heappop(minheap))
	elif lmax - 1 > lmin:
		heapq.heappush(minheap, -heapq.heappop(maxheap))
	print('{:.1f}'.format(get_median()))


class Heap(object):
	MAX_HEAP = 1
	MIN_HEAP = 2

	def __init__(self, heap_type=MIN_HEAP):
		self.__heap = []
		if heap_type == self.MIN_HEAP:
			self.__comparator = lambda x, y: x < y
		else:
			self.__comparator = lambda x, y: x > y

	def sift_up(self, i):
		j = (i - 1) // 2
		while i > 0 and j >= 0 and self.__comparator(self.__heap[i], self.__heap[j]):
			(self.__heap[i], self.__heap[j]) = (self.__heap[j], self.__heap[i])
			i = j
			j = (i - 1) // 2

	def sift_down(self, i):
		while i < len(self.__heap):
			j = 2 * i + 1
			if 2 * i + 2 < len(self.__heap) and self.__comparator(self.__heap[2 * i + 2], self.__heap[2 * i + 1]):
				j += 1
			if j < len(self.__heap) and self.__comparator(self.__heap[j], self.__heap[i]):
				(self.__heap[i], self.__heap[j]) = (self.__heap[j], self.__heap[i])
				i = j
			else:
				break

	def add(self, x):
		self.__heap.append(x)
		self.sift_up(len(self.__heap) - 1)

	def rem(self, x):
		i = self.__heap.index(x)
		if i == len(self.__heap) - 1:
			self.__heap.pop()
			return
		else:
			self.__heap[i] = self.__heap.pop()
		if i == 0:
			self.sift_down(i)
		elif self.__comparator(self.__heap[i], self.__heap[(i - 1) // 2]):
			self.sift_up(i)
		else:
			self.sift_down(i)

	def top(self):
		return self.__heap[0] if len(self.__heap) > 0 else None

	def size(self):
		return len(self.__heap)

	def __repr__(self):
		return '|' + ','.join((str(x) for x in self.__heap)) + '|'

class MedianFinder(object):

	def __init__(self):
		self._max_heap = Heap(Heap.MAX_HEAP)
		self._min_heap = Heap(Heap.MIN_HEAP)
		self.cur_median = None

	def add_number(self, num):
		if self._max_heap.size() == self._min_heap.size() == 0 and self.cur_median is None:
			self.cur_median = num
		else:
			median = self.get_median()
			if num < median:
				if self.cur_median is not None:
					self._min_heap.add(self.cur_median)
					self._max_heap.add(num)
					self.cur_median = None
				else:
					max_elem = self._max_heap.top()
					if num <= max_elem:
						self._max_heap.rem(max_elem)
						self._max_heap.add(num)
						self.cur_median = max_elem
					else:
						self.cur_median = num
			elif self.cur_median is not None:
				self._max_heap.add(self.cur_median)
				self._min_heap.add(num)
				self.cur_median = None
			else:
				min_elem = self._min_heap.top()
				if num >= min_elem:
					self._min_heap.rem(min_elem)
					self._min_heap.add(num)
					self.cur_median = min_elem
				else:
					self.cur_median = num

	def get_median(self):
		if self.cur_median is not None:
			return self.cur_median
		else:
			if self._max_heap.size() == 0 and self._min_heap.size() == 0:
				return None
			return (self._max_heap.top() + self._min_heap.top()) / 2 if self.cur_median is None else self.cur_median

	def __repr__(self):
		out = 'L{} {} R{}'.format(self._max_heap, self.cur_median, self._min_heap)
		return out
Q = int(input().strip())
median_finder = MedianFinder()
for q in range(Q):
	v = int(input().strip())
	median_finder.add_number(v)
	print('{0:.1f}'.format(median_finder.get_median()))


import heapq
left = []
right = []

def output(n):
	print('{0:.1f}'.format(n))
for t in range(int(input())):
	n = int(input())
	if not left or -left[0] >= n:
		heapq.heappush(left, -n)
	else:
		heapq.heappush(right, n)
	if len(left) > len(right) + 1:
		heapq.heappush(right, -heapq.heappop(left))
	elif len(right) > len(left) + 1:
		heapq.heappush(left, -heapq.heappop(right))
	if len(left) == len(right):
		output((-left[0] + right[0]) / 2)
	elif len(left) < len(right):
		output(right[0])
	else:
		output(-left[0])


import math

def heapPush(heap, value):
	current = len(heap)
	heap.append(value)
	parent = int(math.floor((current - 1) / 2))
	while parent >= 0:
		if heap[current] < heap[parent]:
			temp = heap[parent]
			heap[parent] = heap[current]
			heap[current] = temp
			current = parent
			parent = int(math.floor((current - 1) / 2))
		else:
			break

def heapPop(heap):
	if not heap:
		return None
	head = heap[0]
	end = heap.pop()
	heap[0] = end
	siftDown(heap, 0)
	return head

def siftDown(heap, start):

	def leftChild(heap, i):
		chIndex = 2 * int(i) + 1
		if len(heap) >= chIndex + 1:
			return chIndex
		else:
			return None

	def rightChild(heap, i):
		chIndex = 2 * int(i) + 2
		if len(heap) >= chIndex + 1:
			return chIndex
		else:
			return None
	current = start
	while leftChild(heap, current) != None:
		lChild = leftChild(heap, current)
		rChild = rightChild(heap, current)
		swap = current
		if heap[lChild] < heap[swap]:
			swap = lChild
		if rChild and heap[rChild] < heap[swap]:
			swap = rChild
		if swap == current:
			return
		else:
			temp = heap[current]
			heap[current] = heap[swap]
			heap[swap] = temp
			current = swap

def main():
	heapA = []
	heapB = []
	N = int(input())
	for i in range(N):
		new = int(input())
		if not heapA or new < abs(heapA[0]):
			neg = -1 * new
			heapPush(heapA, neg)
		else:
			heapPush(heapB, new)
		diff = abs(len(heapA) - len(heapB))
		if len(heapA) > len(heapB):
			if diff > 1:
				switch = -1 * heapPop(heapA)
				heapPush(heapB, switch)
				val1 = -1.0 * heapA[0]
				val2 = 1.0 * heapB[0]
				median = (val1 + val2) / 2.0
			else:
				median = -1.0 * heapA[0]
		elif len(heapA) < len(heapB):
			if diff > 1:
				switch = -1 * heapPop(heapB)
				heapPush(heapA, switch)
				val1 = -1.0 * heapA[0]
				val2 = 1.0 * heapB[0]
				median = (val1 + val2) / 2.0
			else:
				median = heapB[0] / 1.0
		else:
			val1 = -1.0 * heapA[0]
			val2 = 1.0 * heapB[0]
			median = (val1 + val2) / 2.0
		print(median)
main()


N = int(input().strip())
median = None
lt = [0 for dummy in range(N)]
gt = [0 for dummy in range(N)]

def okay(a, b, heapType):
	if heapType == 'max':
		return a >= b
	else:
		return a <= b

def replaceRoot(heap, newVal, heapSize, heapType):
	heap[0] = newVal
	curr = 0
	leftInd = 1
	rightInd = 2
	while leftInd < heapSize:
		leftOkay = okay(heap[curr], heap[leftInd], heapType)
		rightOkay = rightInd >= heapSize or okay(heap[curr], heap[rightInd], heapType)
		if leftOkay and rightOkay:
			break
		if leftOkay and (not rightOkay):
			indToSwap = rightInd
		elif rightOkay and (not leftOkay):
			indToSwap = leftInd
		elif heapType == 'max':
			indToSwap = leftInd if heap[leftInd] > heap[rightInd] else rightInd
		else:
			indToSwap = rightInd if heap[leftInd] > heap[rightInd] else leftInd
		temp = heap[curr]
		heap[curr] = heap[indToSwap]
		heap[indToSwap] = temp
		curr = indToSwap
		leftInd = 2 * curr + 1
		rightInd = 2 * curr + 2

def heapSize(N_i):
	if N_i % 2 == 0:
		return int(N_i / 2)
	else:
		return int((N_i - 1) / 2)

def getParent(ind):
	if ind % 2 == 0:
		return int((ind - 2) / 2)
	else:
		return int((ind - 1) / 2)

def heapAdd(heap, newVal, heapSize, heapType):
	heap[heapSize] = newVal
	curr = heapSize
	while curr > 0 and (not okay(heap[getParent(curr)], heap[curr], heapType)):
		temp = heap[curr]
		heap[curr] = heap[getParent(curr)]
		heap[getParent(curr)] = temp
		curr = getParent(curr)
for N_i in range(N):
	val = int(input().strip())
	if median == None:
		if N_i == 0:
			median = val
		elif val >= lt[0] and val <= gt[0]:
			median = val
		elif val < lt[0]:
			median = lt[0]
			replaceRoot(lt, val, heapSize(N_i), 'max')
		else:
			median = gt[0]
			replaceRoot(gt, val, heapSize(N_i), 'min')
	else:
		if val <= median:
			heapAdd(lt, val, heapSize(N_i), 'max')
			heapAdd(gt, median, heapSize(N_i), 'min')
		else:
			heapAdd(lt, median, heapSize(N_i), 'max')
			heapAdd(gt, val, heapSize(N_i), 'min')
		median = None
	if median != None:
		print('%0.1f' % median)
	else:
		print('%0.1f' % ((lt[0] + gt[0]) / 2))


class Heap:

	def __init__(self, size, mult):
		self.data = [int()] * size
		self.index = 0
		self.multiplier = mult

	def add(self, value):
		value *= self.multiplier
		self.data[self.index] = value
		pos = self.index
		self.index += 1
		while pos > 0 and value < self.data[int(pos / 2)]:
			self.data[pos] = self.data[int(pos / 2)]
			pos = int(pos / 2)
		self.data[pos] = value

	def remove(self, value):
		index = self.data.index(value)

	def pop(self):
		value = self.data[0]
		self.index -= 1
		swapVal = self.data[self.index]
		self.data[0] = swapVal
		self.reheap(0)
		self.data[self.index] = 0
		return value

	def reheap(self, index):
		left = 2 * index
		right = 2 * index + 1
		smallest = index
		if left < self.index and self.data[left] < self.data[smallest]:
			smallest = left
		if right < self.index and self.data[right] < self.data[smallest]:
			smallest = right
		if smallest != index:
			temp = self.data[index]
			self.data[index] = self.data[smallest]
			self.data[smallest] = temp
			self.reheap(smallest)

class Median:

	def __init__(self, size):
		self.minHeap = Heap(size, 1)
		self.maxHeap = Heap(size, -1)
		self.size = size
		self.count = 0

	def insert(self, val):
		self.count += 1
		if self.minHeap.index == 0 or self.minHeap.data[0] < val:
			self.minHeap.add(val)
		else:
			self.maxHeap.add(val)
		self.rebalance()

	def rebalance(self):
		if self.maxHeap.index > self.minHeap.index:
			while self.maxHeap.index > self.minHeap.index:
				self.minHeap.add(self.maxHeap.pop() * -1)
		elif self.minHeap.index > self.maxHeap.index:
			while self.minHeap.index > self.maxHeap.index:
				self.maxHeap.add(self.minHeap.pop())
		if self.maxHeap.data[0] * -1 > self.minHeap.data[0] and self.maxHeap.index > 0 and (self.minHeap.index > 0):
			temp1 = self.maxHeap.pop() * -1
			temp2 = self.minHeap.pop()
			self.maxHeap.add(temp2)
			self.minHeap.add(temp1)

	def print(self):
		if self.count % 2 != 0:
			if self.maxHeap.index > self.minHeap.index:
				print(float(self.maxHeap.data[0] * -1))
			else:
				print(float(self.minHeap.data[0]))
		else:
			print((self.maxHeap.data[0] * -1 + self.minHeap.data[0]) / 2)
x = int(input())
medianTrack = Median(x)
for i in range(x):
	num = int(input())
	medianTrack.insert(num)
	medianTrack.print()


import heapq
(L, H) = ([], [])
for _ in range(int(input())):
	a = int(input())
	if not H:
		heapq.heappush(H, a)
	elif len(H) > len(L):
		if H[0] < a:
			b = heapq.heappushpop(H, a)
			heapq.heappush(L, -b)
		else:
			heapq.heappush(L, -a)
	elif -L[0] > a:
		b = -heapq.heappushpop(L, -a)
		heapq.heappush(H, b)
	else:
		heapq.heappush(H, a)
	if len(H) > len(L):
		print('%.1f' % H[0])
	else:
		print('%.1f' % ((H[0] - L[0]) / 2))


import sys
import bisect

class sortlist:

	def __init__(self, list):
		self.list = list
		self.sort()

	def sort(self):
		(l, i) = ([], 0)
		for i in range(len(self.list)):
			bisect.insort(l, self.list[i])
		self.list = l
		self.len = i

	def insert(self, value):
		bisect.insort(self.list, value)
		self.len += 1

	def search(self, value):
		left = bisect.bisect_left(self.list, value)
		if abs(self.list[min([left, self.len - 1])] - value) >= abs(self.list[left - 1] - value):
			return self.list[left - 1]
		else:
			return self.list[left]
n = int(input().strip())
a = sortlist([])
a_i = 0
for a_i in range(n):
	a_t = int(input().strip())
	a.insert(a_t)
	if a_i == 0:
		print(float(a_t))
	elif a_i == 1:
		print((a.list[0] + a.list[1]) / 2)
	elif a_i % 2:
		print(float((a.list[a_i // 2] + a.list[a_i // 2 + 1]) / 2))
	else:
		print(float(a.list[a_i // 2]))


from bisect import insort
n = int(input())
lst = []
even = False
for i in range(n):
	insort(lst, int(input()))
	if even:
		print(0.5 * (lst[i // 2] + lst[i // 2 + 1]))
		even = False
	else:
		print(1.0 * lst[i // 2])
		even = True


from heapq import *
iterations = int(input())
low = []
high = []
for i in range(iterations):
	number = float(input())
	if len(low) == 0:
		low.append(-1 * number)
	elif len(high) == 0:
		heappush(low, -1 * number)
		high.append(-1 * heappop(low))
	elif number > high[0]:
		heappush(high, number)
	elif number <= high[0]:
		heappush(low, -1 * number)
	diff = abs(len(low) - len(high))
	if diff == 2:
		if len(low) > len(high):
			removed = -1 * heappop(low)
			heappush(high, removed)
		else:
			removed = -1 * heappop(high)
			heappush(low, removed)
		diff = 0
	if diff == 0:
		print((abs(low[0]) + high[0]) / 2)
	elif diff == 1:
		if len(low) > len(high):
			print(-1 * low[0])
		else:
			print(high[0])


import heapq

class MedianTracker:

	def __init__(self):
		self.lower_half = []
		self.upper_half = []

	def insert(self, element):
		if len(self.lower_half) == len(self.upper_half):
			heapq.heappush(self.lower_half, -heapq.heappushpop(self.upper_half, -element))
		else:
			heapq.heappush(self.upper_half, -heapq.heappushpop(self.lower_half, element))

	def median(self):
		if len(self.lower_half) == len(self.upper_half):
			return (self.lower_half[0] - self.upper_half[0]) / 2.0
		else:
			return self.lower_half[0]
n = int(input())
median = MedianTracker()
for i in range(n):
	element = int(input())
	median.insert(element)
	print('{0:.1f}'.format(median.median()))


import heapq as q
N = int(input().strip())
maxl = []
minl = []

def getMedian(maxl, minl):
	lenMin = len(minl)
	lenMax = len(maxl)
	totalLen = lenMax + lenMin
	if totalLen % 2 == 0 and totalLen != 0:
		a = maxl[0]
		b = -minl[0]
		return (a + b) / 2
	elif lenMin > lenMax:
		return -minl[0]
	else:
		return maxl[0]

def rebalance2(maxl, minl):
	while len(maxl) > len(minl):
		a = q.heappop(maxl)
		q.heappush(minl, -a)
	while len(minl) > len(maxl):
		a = q.heappop(minl)
		q.heappush(maxl, -a)
m = -1
for _ in range(N):
	a = int(input().strip())
	if a > m:
		q.heappush(maxl, a)
	else:
		q.heappush(minl, -a)
	rebalance2(maxl, minl)
	m = getMedian(maxl, minl)
	print(float(m))


class Heap:

	def __init__(self, hType='MIN'):
		self.d = [None]
		if hType == 'MIN':
			self.compare = lambda x, y: x <= y
		else:
			self.compare = lambda x, y: y <= x

	def add(self, v):
		self.d.append(v)
		index = len(self.d) - 1
		while index >= 1:
			parent = index // 2
			if parent <= 0:
				break
			if self.compare(self.d[index], self.d[parent]):
				(self.d[index], self.d[parent]) = (self.d[parent], self.d[index])
				index = parent
			else:
				break

	def size(self):
		return len(self.d) - 1

	def top(self):
		if self.size() <= 0:
			return None
		return self.d[1]

	def pop(self):
		if self.size() <= 0:
			return None
		top = self.d[1]
		last = self.d.pop()
		if self.size() > 0:
			self.d[1] = last
			index = 1
			while index:
				(c1, c2) = (index * 2, index * 2 + 1)
				mc = None
				if c1 >= 1 and c1 < len(self.d):
					if c2 <= 0 or c2 >= len(self.d):
						mc = c1
					elif self.compare(self.d[c1], self.d[c2]):
						mc = c1
					else:
						mc = c2
				if not mc:
					break
				if self.compare(self.d[mc], self.d[index]):
					(self.d[mc], self.d[index]) = (self.d[index], self.d[mc])
					index = mc
				else:
					break
		return top

	def __str__(self):
		return str(self.d[1:])
total = int(input())
maxHeap = Heap('MAX')
minHeap = Heap()
ls = []
for i in range(total):
	v = int(input())
	ls.append(v)
	median = 0.0
	maxHeap.add(v)
	minHeap.add(maxHeap.pop())
	if minHeap.size() - maxHeap.size() > 1:
		maxHeap.add(minHeap.pop())
	if minHeap.size() > maxHeap.size():
		median = minHeap.top()
	else:
		median = (maxHeap.top() + minHeap.top()) * 0.5
	median = int(median * 10.0)
	print(median / 10.0)


import heapq
smaller = []
bigger = []
for _ in range(int(input())):
	a = int(input())
	if len(smaller) <= 0 or a > -1 * smaller[0]:
		heapq.heappush(bigger, a)
	else:
		heapq.heappush(smaller, -1 * a)
	while len(smaller) - len(bigger) not in [0, 1]:
		if len(smaller) > len(bigger):
			heapq.heappush(bigger, -1 * heapq.heappop(smaller))
		else:
			heapq.heappush(smaller, -1 * heapq.heappop(bigger))
	if len(smaller) - len(bigger) == 1:
		print(float(-1 * smaller[0]))
	elif len(smaller) - len(bigger) == 0:
		print((-1 * smaller[0] + bigger[0]) / 2)


from heapq import *
import sys
size = int(sys.stdin.readline())
ltheap = []
gtheap = []
for i in range(size):
	n = int(sys.stdin.readline())
	if i == 0:
		heappush(gtheap, n)
	else:
		mid = gtheap[0]
		if n <= mid:
			heappush(ltheap, -1 * n)
		else:
			heappush(gtheap, n)
	if len(gtheap) > len(ltheap) + 1:
		mid = heappop(gtheap)
		heappush(ltheap, -1 * mid)
	elif len(ltheap) > len(gtheap) + 1:
		mid = -1 * heappop(ltheap)
		heappush(gtheap, mid)
	if len(gtheap) == len(ltheap):
		median = (-1 * ltheap[0] + gtheap[0]) / 2
	elif len(gtheap) > len(ltheap):
		median = gtheap[0]
	else:
		median = -1 * ltheap[0]
	print('%.1f' % median)