import java.io.*;

class Museum {

    private static int walkmen;
    private static int cash;
    
    Museum( int w) {
        walkmen = w;
        cash = 0;        
    }
    
    /* 
        If there are not enough Walkmen left,
        wait until someone at another counter returns
        some and notifies us accordingly.
        If the returns are not enough, we'll carry on
        waiting.
    */
    synchronized void hire(int c, int n) {
        System.out.println("Counter " + c + " wants " + n);
            while( walkmen < n ) {
                try{
                    wait();
                } catch(InterruptedException e) {}
            } 
        
        /*
            Hire out the Walkmen and take the deposit.
            Let the customers at this counter "walk away"
            by relinquishing control of the monitor with
            a notify call.
        */
        walkmen -= n;
        cash += n;
        System.out.println("Counter " + c + " acquires " + n);
        System.out.println("Pool status: " +
            " Deposits " + cash + " Total " + (walkmen+cash) +
            " Walkmen " + walkmen);
        notifyAll();
    }   
    
    
    /*
        Always accept replacements immeadiately.
        Once the pool and deposits have been updated,
        notify any other helper waiting for Walkmen.
    */
    synchronized void replace( int n) {
        System.out.println("Replacing " + n);
        walkmen += n;
        cash -= n;
        notifyAll();
    }
}