import sys

# card = rank, suit

RANKS = list(map(str, range(1, 11))) + [c for c in 'JQKA']
SUITS = 'DHCS'

def all_dividers(x):
    ans = []
    for i in range(1, x + 1):
        if x % i == 0:
            ans.append(i)
    return ans

def superfactor(x):
    primes = {}
    i = 2
    while (x > 1):
        if x % i == 0:
            primes[i] = 0
            while (x % i == 0):
                x = x // i
                primes[i] += 1
        i += 1
    ans = []
    for k, v in primes.items():
        ans.append(k ** v)
    return max(ans)

def _the_straight(hand):
    for i in range(len(RANKS) - 4):
        t = True
        straight = RANKS[i:i + 5]
        for c in hand:
            if c[0] not in straight:
                t = False
                break
        if t:
            for s in straight:
                if s not in [c[0] for c in hand]:
                    t = False
                    break
        if t:
            return True
    return False

def score(card):
    rank = card[0]
    if rank in 'JQKA':
        return 10
    else:
        return int(rank)

def has_suits(card, suits):
    return card[1] in suits

def has_rank(card, rank):
    return card[0] == rank

def count_rank(hand, rank):
    return sum([has_rank(c, rank) for c in hand])

def count_suits(hand, suits):
    return sum([has_suits(c, suits) for c in hand])

def f1(hand, value, modified, last_rule):
    if len(hand) >= 4:
        value += 1
    value += count_rank(hand, 'J') * score(hand[0])
    return value, hand, modified, last_rule

def f2(hand, value, modified, last_rule):
    for s in SUITS:
        if count_suits(hand, s) >= 2:
            return 2 * value, hand, modified, last_rule
    return value, hand, modified, last_rule

def f3(hand, value, modified, last_rule):
    c = 0
    for s in SUITS:
        if count_suits(hand, s):
            c += 1
    if c == 4:
        return 2 * value, hand, modified, last_rule
    return value, hand, modified, last_rule

def f4(hand, value, modified, last_rule):
    c1 = count_suits(hand, 'CS')
    c2 = count_suits(hand, 'HD')
    return value + abs(c1 - c2), hand, modified, last_rule


def f5(hand, value, modified, last_rule):
    if value % 2 == 0:
        value += sum(all_dividers(value))
    return value, hand, modified, last_rule

def f6(hand, value, modified, last_rule):
    if count_rank(hand, '7') == 4:
        return value - 121, hand, modified, last_rule
    return value, hand, modified, last_rule

def f7(hand, value, modified, last_rule):
    if value >= 0:
        value += min([score(c) for c in hand])
    return value, hand, modified, last_rule

def f8(hand, value, modified, last_rule):
    if value < 0:
        return -value, hand
    return value, hand, modified, last_rule

def f9(hand, value, modified, last_rule):
    if count_suits(hand, 'D') >= 3:
        value += 1
        d = {'6': '9', '9': '6', '2': '5', '5': '2'}
        for r in RANKS:
            if r not in d:
                d[r] = r
        hand = [(d[c[0]], c[1]) for c in hand]
    return value, hand, modified, last_rule

def f10(hand, value, modified, last_rule):
    if _the_straight(hand):
        value += 5 * count_rank(hand, 'A')
    return value, hand, modified, last_rule

def f11(hand, value, modified, last_rule):
    if modified > 8:
        value += bin_repr()
    return value, hand, modified, last_rule

def f12(hand, value, modified, last_rule):
    if count_rank(hand, '2'):
        value, hand, modified, last_rule = _apply(last_rule, hand, value, modified, last_rule)
    return value, hand, modified, last_rule

def f13(hand, value, modified, last_rule):
    if count_rank(hand, '2'):
        value *= 2
    return value, hand, modified, last_rule

def _apply(f, hand, value, modified, last_rule):
    value2, hand2, modified, last_rule = f(hand, value, modified, last_rule)
    # print (f, value2, hand2)
    if value2 != value:
        return value2, hand2, modified + 1, f
    else:
        return value2, hand2, modified, last_rule


s = sys.stdin.readline()
cards = s.split()
hand = [(c[:-1], c[-1]) for c in cards]

value = sum(score(c) for c in hand)

modified = 0
last_rule = None
value, hand, modified, last_rule = _apply(f1, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f2, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f3, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f4, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f5, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f6, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f7, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f8, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f9, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f10, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f11, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f12, hand, value, modified, last_rule)
value, hand, modified, last_rule = _apply(f13, hand, value, modified, last_rule)

print(value)
