import sys


def solve(line):
    signal_patterns_str, output_digits_str = line.split(" | ")

    signal_patterns = [frozenset(word) for word in signal_patterns_str.split()]
    output_digits = [frozenset(word) for word in output_digits_str.split()]

    [pattern_4] = [p for p in signal_patterns if len(p) == 4]
    [pattern_7] = [p for p in signal_patterns if len(p) == 3]

    pattern_to_number = {}

    for pattern in signal_patterns:
        if len(pattern) == 2:
            pattern_to_number[pattern] = 1
        elif len(pattern) == 3:
            pattern_to_number[pattern] = 7
        elif len(pattern) == 4:
            pattern_to_number[pattern] = 4
        elif len(pattern) == 5:
            if len(pattern & pattern_7) == 3:
                pattern_to_number[pattern] = 3
            elif len(pattern & pattern_4) == 2:
                pattern_to_number[pattern] = 2
            else:
                pattern_to_number[pattern] = 5
        elif len(pattern) == 6:
            if len(pattern & pattern_4) == 4:
                pattern_to_number[pattern] = 9
            elif len(pattern & pattern_7) == 3:
                pattern_to_number[pattern] = 0
            else:
                pattern_to_number[pattern] = 6
        else:
            pattern_to_number[pattern] = 8

    output_value = 0

    for digit in output_digits:
        output_value *= 10
        output_value += pattern_to_number[digit]

    return output_value


def main():
    answer = sum(solve(line) for line in list(sys.stdin))
    print(answer)


if __name__ == "__main__":
    main()
