class Buffer {
	private int value;
	private boolean valid = false;

	synchronized void put(int i) throws InterruptedException {
		while (valid)
			wait();
		value = i;
		valid = true;
		notify();
	}

	synchronized int get() throws InterruptedException {
		while (!valid)
			wait();
		valid = false;
		notify();
		return value;
	}
}
