Added solution to UVa 547.