output_description: Print the minimum amount of MP needed to achieve the objective.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N A B C
      l_1
      l_2
      :
      l_N
attempt: def c_synthetic_kadomatsu(N, A, B, C, L):
      from itertools import permutations
  
      # for j in range(1, N):
      #     for k in range(1, N - j):
      #         for l in range(1, N - j - k + 1):
      #             print(j, k, l, L[:j], L[j:j + k], L[j + k:j + k + l])
      ans = float("inf")
      for perm in permutations(range(N)):
          for j in range(1, N):
              for k in range(1, N - j):
                  for l in range(1, N - j - k + 1):
                      cost = 0
                      s, t, u = perm[:j], perm[j : j + k], perm[j + k : j + k + l]
                      a, b, c = [], [], []
                      for _s in s:
                          a.append(L[_s])
                      for _t in t:
                          b.append(L[_t])
                      for _u in u:
                          c.append(L[_u])
                      cost += (len(a) + len(b) + len(c) - 3) * 10
                      cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
                      ans = min(ans, cost)
      return ans
  
  
  N, A, B, C = [int(i) for i in input().split()]
  L = [int(input()) for _ in range(N)]
  print(c_synthetic_kadomatsu(N, A, B, C, L))
  
problem_description: Statement
  
  You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
  l_N, respectively.
  
  Your objective is to use some of these bamboos (possibly all) to obtain three
  bamboos of length A, B, C. For that, you can use the following three kinds of
  magics any number:
  
    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
    * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
    * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
  
  At least how much MP is needed to achieve the objective?
samples: [{"input": "5 100 90 80\n    98\n    40\n    30\n    21\n    80", "output": "23\n    \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n  1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n  2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n  3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n  4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n    100\n    100\n    90\n    90\n    90\n    80\n    80\n    80", "output": "0\n    \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n    300\n    333\n    400\n    444\n    500\n    555\n    600\n    666", "output": "243"}]