http://cemc.math.uwaterloo.ca/contests/computing/2007/stage1/seniorEn.pdf