solution for uva 387