Part of 2013 Canadian Mathematical Olympiad Qualification Repechage
Source: Canadian Repêchage 2013: Problem 5