Part of 2007 Danube Mathematical Competition
Source: Beautiful problem with beautiful combinatorial solution