UVA Problem 10082 solved