solution to UVA 146