My solution to UVa Online Judge