solution for uva 1339