Adam C. Murphy loves shopping. One day, when he was wandering along the avenue, he discovered several stores with florid banners. (A 2*5 example is shown below)
He found them fantastic and decided to get one in order to decorate his fresh new house. Unfortunately, no one meets Adam’s requirement, after visiting all stores nearby. What was worse, all banners left in the stores only have width 1. So he decided to make one himself by sewing them together.
Adam wants to make a banner exactly as he designed. He didn’t want to flip or rotate the materials he had, since he believed that keep it in its original way is more beautiful. And he didn’t want to cut the banners for the same reason.
Each material had different prices, so he wants to make his florid banner with minimum cost.