CODECHEF: Remy paints the fence

http://www.codechef.com/OCT14/problems/FATCHEF/