#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// 飛ばし飛ばしで値を使うイテレータ Rust v1.28以降でしか使えないため独自実装
/// 簡易実装のためインデックスのオーバーフロー等は考慮していない
pub struct StepBy<I> {
    iter: I,
    step: usize,
    first_take: bool,
}
impl<I> StepBy<I> {
    pub fn new(iter: I, step: usize) -> StepBy<I> {
        StepBy {
            iter: iter,
            step: step - 1,
            first_take: true,
        }
    }
}
impl<I> Iterator for StepBy<I>
where
    I: Iterator,
{
    type Item = I::Item;

    fn next(&mut self) -> Option<Self::Item> {
        if self.first_take {
            self.first_take = false;
            self.iter.next()
        } else {
            self.iter.nth(self.step)
        }
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        let inner_hint = self.iter.size_hint();
        if self.first_take {
            let f = |n| {
                if n == 0 {
                    0
                } else {
                    1 + (n - 1) / (self.step + 1)
                }
            };
            (f(inner_hint.0), inner_hint.1.map(f))
        } else {
            let f = |n| n / (self.step + 1);
            (f(inner_hint.0), inner_hint.1.map(f))
        }
    }
}
impl<I> ExactSizeIterator for StepBy<I> where I: ExactSizeIterator {}
////////////////////////////////////////////////////////////////////////////////////////////////////

trait IteratorExt: Iterator + Sized {
    // ref: https://qiita.com/vain0x/items/512784ff60ce599dccae#vec
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }

    // step_by は v1.28.0 以降でしか使えないため独自実装
    fn stepby(self, step: usize) -> StepBy<Self>
    where
        Self: Sized,
    {
        StepBy::new(self, step)
    }
}

impl<T: Iterator> IteratorExt for T {}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// 逆順ソート ReverseがRust v1.19以降でしか使えないため独自実装
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
// 逆順ソートここまで
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
/// べき乗のmodを効率的に求める関数
/// ref: https://algorithmbeginner.blogspot.com/2018/02/blog-post_23.html
fn pow(x: u64, n: u64, modulo: u64) -> u64 {
    let mut res = 1;
    if n > 0 {
        res = pow(x, n / 2, modulo);
        if n % 2 == 0 {
            res = (res * res) % modulo;
        } else {
            res = (((res * res) % modulo) * x) % modulo;
        }
    }
    res
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn dfs(
    depth: usize,
    max_depth: usize,
    mp: usize,
    a: usize,
    b: usize,
    c: usize,
    l: &Vec<usize>,
    A: &usize,
    B: &usize,
    C: &usize,
) -> i64 {
    if depth == max_depth {
        if a > 0 && b > 0 && c > 0 {
            return (a as i64 - *A as i64).abs()
                + (b as i64 - *B as i64).abs()
                + (c as i64 - *C as i64).abs()
                - 30
                + mp as i64;
        } else {
            return 10_i64.pow(9);
        }
    }

    let len_a = a + l[depth];
    let len_b = b + l[depth];
    let len_c = c + l[depth];

    let mp_a = dfs(depth + 1, max_depth, mp + 10, len_a, b, c, l, A, B, C);
    let mp_b = dfs(depth + 1, max_depth, mp + 10, a, len_b, c, l, A, B, C);
    let mp_c = dfs(depth + 1, max_depth, mp + 10, a, b, len_c, l, A, B, C);
    let mp_none = dfs(depth + 1, max_depth, mp, a, b, c, l, A, B, C);

    min(mp_a, min(mp_b, min(mp_c, mp_none)))
}

fn main() {
    let (n, a, b, c) = read!(usize, usize, usize, usize);
    let l: Vec<usize> = read![usize; n];

    let mp = dfs(0, n, 0, 0, 0, 0, &l, &a, &b, &c);
    println!("{}", mp);
}


Measured memory_bytes: 4352