Andy: AC code for UVa#775.