const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

const input = stdin.split('\n')

const [N, A, B, C] = input[0].split(' ').map(Number)

const [, ...rest] = input
const l = rest.filter(e => e).map(Number)

let mp = 0
const targets = [A, B, C]

const filtered = l.filter(e => {
  let isAorBorC = false

  if (e === A) {
    targets.splice(0, 1)
    isAorBorC = true
  } else if (e === B) {
    targets.splice(1, 1)
    isAorBorC = true
  } else if (e === C) {
    targets.splice(2, 1)
    isAorBorC = true
  }

  return !isAorBorC
})

let diffs = filtered.map(e => {
  const diffA = Math.abs(e - A)
  const diffB = Math.abs(e - B)
  const diffC = Math.abs(e - C)

  return [e, diffA, diffB, diffC]
})

diffs = diffs.filter(v => {
  const [e, diffA, diffB, diffC] = v

  const min = Math.min(diffA, diffB, diffC)

  let isRemoved = false

  if (min <= 10) {
    mp += min

    const removeTarget = {
      [diffA]: A,
      [diffB]: B,
      [diffC]: C,
    }[min]

    const removeIndex = targets.indexOf(removeTarget)

    targets.splice(removeIndex, 1)

    isRemoved = true
  }

  return !isRemoved
})

if (diffs.length > 0 && targets.length > 0) {
  diffs.sort((a, b) => b[0] - a[0])
  targets.filter(t => {
    let isRemoved = false
    diffs.reduce((p, c) => {
      const sum = p[0] + c[0]
      mp += 10

      const abs = Math.abs(t - sum)

      if (abs <= 10) {
        mp += abs
      }
      return [sum]
    })

    return !isRemoved
  })
}

console.log(mp)
