import java.io.*;

class Museum {

  Museum (int w) {
    walkmen = w;
    cash = 0;
  }

  synchronized void hire (int c,int n) {
    // 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.
    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);
    notify ();
  }

  synchronized void replace (int n) {

    // Always accept replacements immediately.
    // Once the pool and deposits have been updated,
    // notify any other helper waiting for Walkmen.
    System.out.println("Replacing "+n);
    walkmen +=n;
    cash -= n;
    notify ();
  }

  private static int walkmen;
  private static int cash;
}
