The answer code for UVa#10271 developed by Andy Shen.