Help me in solving THREECOL problem

How this problem could be solved?

Link: THREECOL Problem - CodeChef