https://www.codechef.com/SNFL16MR/problems/BEAUTY/
I am trying to solve this problem for a long time. Cannot find any editorial by googling. Can you please help me out? Looking by the constraints it seems like a bitmask dp problem, but can't find anything :'(