solve UVa 10387