UVA Online Judge Solution