my $shopsCount = <STDIN> - 0;
my $shops = [];
for(my $i = 0; $i < $shopsCount; $i++) {
    my @s = map{$_-0}split / /, <STDIN>;
    $shops->[$i] = \@s;
}
my $earn = [];
for(my $i = 0; $i < $shopsCount; $i++) {
    my @s = map{$_-0}split / /, <STDIN>;
    $earn->[$i] = \@s;
}

my $earnMax = 0;
sub attempt {
    my @arr = @_;
    if(scalar(@arr) == 10) {
        #print @arr;
        my $er = 0;
        for(my $i = 0; $i < $shopsCount; $i++) {
            my $dup = 0;
            for(my $l = 0; $l < 10; $l++){
                $dup++ if $arr[$l] && $shops->[$i]->[$l];
            }
            #print join('',$earn[$i]),"\n";
            $er += $earn->[$i]->[$dup];
        }
        #print $er;
        $earnMax = $er if $earnMax < $er;
    } else {
        attempt(@arr, 1);
        attempt(@arr, 0);
    }
}
attempt();
print $earnMax;