uva 10905 impl in java