#!/usr/bin/perl -w

use strict;
use v5.30;

my $sum;
while (<>) {
	chomp;
	my ($code, $id, $csum) = /\A([a-z-]+)-(\d+)\[([a-z]{5})\]/;
	my %hist;
	$hist{$&}++ while ($code =~ /[a-z]/g);
	my $c1;
	for my $l (sort { $hist{$b} <=> $hist{$a} || $a cmp $b } keys %hist) {
		$c1 .= $l;
		last if length $c1 >= length $csum;
	}
	$sum += $id if $csum eq $c1;
}
say $sum;
