Updated uva10905 impl