Question
The Magical Container

In a mystical laboratory, an alchemist named Shina had N magical containers, each filled with liquids of varying strengths: S1, S2, ..., SN. She needed to create three specific mixtures with strengths X, Y, and Z for an important event within a least time
To achieve this, Shina could use three magical actions:

  • Increase the strength of any container by 1, taking 1 second.
  • Decrease the strength of any container by 1, taking 1 second.
  • Combine two containers of strengths Si and Sj into one container of strength Si + Sj, taking 10 seconds.
Input
The first line of the input contains 4 integers N, X, Y and Z
The next N contains single integer each, S1, S2, ... , SN.

Constraints:
3 ≤ N ≤ 10
1 ≤ X < Y < Z ≤ 103
1 ≤ Si ≤ 103
Output
Print the least time needed by Shina.
Example
Sample Input
5 100 90 80
99
81
40
30
22
Sample Output
24
Explanation
1) Shina will create a mixture with a strength of 100 by increasing the strength of the first container (99) using the first magical action.
2) She will create a mixture with a strength of 80 by decreasing the strength of the second container (81) using the second magical action.
3) For the mixture with a strength of 90, Shina will first decrease the strength of the last container (22) by 2 using the second magical action, resulting in strengths of 40, 30, and 20. Then, she will merge the containers with strengths 40 and 30 to create a container of strength 70. Finally, she will merge the 70 with the 20 to create a mixture of strength 90.

Online