CODECHEF Magical Girl and Colored Liquid Potions

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