UVa Online Judge Solution