import java.util.*;

public class Solution {

    private PriorityQueue<Integer> minHeap = new PriorityQueue<>();
    private PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);

    public void Insert(Integer num) {
        minHeap.offer(num);
        maxHeap.offer(minHeap.poll());
        if (minHeap.size() < maxHeap.size()) {
            minHeap.offer(maxHeap.poll());
        }
    }

    public Double GetMedian() {
        if (minHeap.size() > maxHeap.size()) {
            return (double) minHeap.peek();
        }
        return (minHeap.peek() + maxHeap.peek()) / 2.0;
    }


}