JOI Open Contest 2012 C

JOI Open Contest 2012 C

This contest is held by Japanese Olympiad in Informatics for contestants of the IOI 2012 and all programmers!
For people who cannot participate in this contest, two more repeats of this contest will be held: