solution to UVA 11495