code for uva problem