solved an uva problem after long time