#include <stdio.h>
#include <stdlib.h>

int comp[3];
int N, A, B, C, MP = 0;
int *l;

int main (void) {
  scanf("%d %d %d %d", &N, &A, &B, &C);
  l = malloc(sizeof(int) * N);
  
  for (int i = 0; i < N; i++) {
    scanf("%d", &(l[i]));
  }
  
  while (1) {
    finishCheck();
    extend();
    shorten();
  }
  
  return 0;
}

void extend() {
  for (int i = 0; i < N; i++) {
    if ((A - l[i]) >= 0 && (A - l[i]) <= 10 && comp[0] == 0) {
      MP += (A - l[i]);
      l[i] = -9999;
      comp[0] = 1;
    }
    if ((B - l[i]) >= 0 && (B - l[i]) <= 10 && comp[1] == 0) {
      MP += (B - l[i]);
      l[i] = -9999;
      comp[1] = 1;
    }
    if ((C - l[i]) >= 0 && (C - l[i]) <= 10 && comp[2] == 0) {
      MP += (C - l[i]);
      l[i] = -9999;
      comp[2] = 1;
    }
  }
  return;
}

void shorten() {
  for (int i = 0; i < N; i++) {
    if ((l[i] - A) >= 0 && (l[i] - A) <= 10 && comp[1] == 0) {
      MP += (l[i] - A);
      l[i] = -9999;
      comp[0] = 1;
    }
    if ((l[i] - B) >= 0 && (l[i] - B) <= 10 && comp[1] == 0) {
      MP += (l[i] - B);
      l[i] = -9999;
      comp[1] = 1;
    }
    if ((l[i] - C) >= 0 && (l[i] - C) <= 10 && comp[1] == 0) {
      MP += (l[i] - C);
      l[i] = -9999;
      comp[2] = 1;
    }
  }
  return;
}

