UVA 499 in Java