solution for uva 1346