use v5.18;
use warnings;
use List::Util qw( sum0 min max all );
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

use constant INF => 10 ** 9;

my ($N, $A, $B, $C) = splited_read_line;
my @l = map { read_line } 0 .. $N - 1;

sub dfs {
  my ($depth, $str) = @_;
  return $str if $depth == $N;
  map { dfs($depth + 1, $str . $_) } qw/ A B C /, ' ';
}

my $ans = min map {
  my %ts;
  my @r = split //, $_;
  my $concat_cnt = 0;
  for my $i (0 .. $#r) {
    for my $t (qw/ A B C /) {
      if ( $r[$i] eq $t ) {
        $concat_cnt++ if exists $ts{$t};
        $ts{$t} += $l[$i];
      }
    }
  }
  if ( grep { !exists $ts{$_} } qw/ A B C / ) {
    INF;
  }
  else {
    my $mp = 0;
    $mp += $concat_cnt * 10;
    $mp += abs($A - $ts{A});
    $mp += abs($B - $ts{B});
    $mp += abs($C - $ts{C});
    $mp;
  }
} dfs(0, '');

say $ans;