Uva Online Judge problem solution