Hello

Here is the PDF statements page of the 2016 Benelux Algorithm Programming Contest (BAPC 16).

I reduced Problem H with some small observations to this problem:

**Spoiler**

Since I believe there isn't another(totally different) way to solve it and to keep this short, I won't explain how I got to that statement from Problem H.

Now this seems to me like a 100% greedy problem. But I *ALWAYS* get stuck in this same type of problems, I just can't find any way to distribute them. Maybe the small constraints on the number of primes should help?

The only algorithm I know in some similar cases to this is the **Huffman Code** and I don't think it can help here. (maybe some variant of it can?)

Can you help me solve this? Also it would be *awesome* if you would provide any help/links on some problems/tricks to help with such greedies!

Thank you :)