You play a darts game with the following rules.
- You may throw up to 4 arrows at the target. You do not have to throw all 4, and you may throw none at all.
- The target is divided into $N$ regions, and region $i$ is labeled with a score $P_i$. Several arrows may stick in the same region, and each one adds that region's score again.
- Let $S$ be the total score of the regions where your arrows stick. This is the basis of your points.
- For a predetermined value $M$: if $S \le M$, your score is exactly $S$. However, if $S$ exceeds $M$, your score becomes $0$.
Given the scores written on the target and the value of $M$, write a program that finds the maximum score you can obtain.