import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val n = sc.nextInt
    val a = sc.nextInt
    val b = sc.nextInt
    val c = sc.nextInt

    val iSeq = Seq(a,b,c)

    val ll = List.fill(n)(sc.nextInt)

    val res =
      (1 to Math.pow(4,n).toInt).foldLeft(Int.MaxValue){ case (min, l) =>
        val temp = s"%0${n}d".format(Samples.l_adic(l,4).mkString.toInt).split("(?<=.)") zip ll

        val sum = temp.foldLeft( Array((0,0),(0,0),(0,0),(0,0)) ){case (arr, (i,num)) =>
          i match{
            case "0" => val x = arr(0); arr.update(0, (x._1 + num, x._2 + 1) ) ; arr
            case "1" => val x = arr(1); arr.update(1, (x._1 + num, x._2 + 1) ) ; arr
            case "2" => val x = arr(2); arr.update(2, (x._1 + num, x._2 + 1) ) ; arr
            case "3" => val x = arr(3); arr.update(3, (x._1 + num, x._2 + 1) ) ; arr
          }
        }
        val sumSeq = sum.tail.map(_._1).toSeq
        val jointNum = sum.tail.map(_._2 - 1).sum

        if( sumSeq.count(_ == 0 ) > 0) min
        else {
          Math.min( (sumSeq zip iSeq).map(t => Math.abs(t._1 - t._2)).sum + 10 * jointNum, min)
        }
      }
    println(res)
  }
}