solution to UVA 10258