This is a personal UVa OJ solution set. Feel free to review, but DO NOT submit it directly.