My solution for UVa problems