public static void main(String[] args)
    {
        ArrayList<Integer> array = readIntegerArrayFromFile();
        
        int sum = 0;
        
        PriorityQueue<Integer> heapLow = new PriorityQueue<Integer>();
        PriorityQueue<Integer> heapHigh = new PriorityQueue<Integer>();
    
        for(Integer x_i : array)
        {
            if(heapLow.size() > 0)
            {
                if(x_i > -(heapLow.peek()))
                {
                    heapHigh.add(x_i);
                }
                else
                {
                    heapLow.add(-x_i);
                }
            }
            else
            {
                heapLow.add(-x_i);
            }

            if(heapLow.size() > heapHigh.size() + 1)
            {
                heapHigh.add(-heapLow.poll());
            }
            else if(heapHigh.size() > heapLow.size())
            {
                heapLow.add(-heapHigh.poll());
            }

            sum += -heapLow.peek();
        }
        
        System.out.println("*** RESULT => " + sum % 10000 + " ***");
    }