solution to UVA 422