uva105 impl in java