uva 216, make the code more concise