Start of the solution for Remy paints the fence problem - http://www.codechef.com/OCT14/problems/FATCHEF