UVa 10731 bug fix