solution to UVA 10810