uva 548 impl in java - partial