solution to UVA 11340