UVA problem 151