package com.company;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Rullete {

    static boolean isStraight (List<String> list){
        Boolean[] arr = new Boolean[13];

        for (String s : list) {
            String c = rank(s);
            switch (c){
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "10":
                    arr[Integer.parseInt(c) -2] = true;
                    break;
                case "J":
                    arr[9] = true;
                    break;
                case "Q":
                    arr[10] = true;
                    break;
                case "K":
                    arr[11] = true;
                    break;
                case "A":
                    arr[12] = true;
                    break;
            }
        }

        int c = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]){
                ++c;
            } else {
                if (c != 0){
                    return false;
                }
            }
            if (c == 5) {
                return true;
            }
        }
        return false;
    }

    static String rank(String card){
        return card.substring(0, card.length() -1);
    }

    static int score(String card){
        String val = card.substring(0, card.length() -1);
        switch (val){
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
            case "7":
            case "8":
            case "9":
            case "10": return Integer.parseInt(val);
            default: return 10;
        }
    }

    static char suit(String card){
        return card.charAt(card.length()-1);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader isr = new BufferedReader(new InputStreamReader(System.in));

        String input = isr.readLine();
        ArrayList<String> cards = new ArrayList<>(Arrays.asList(input.split(" ")));

        int value = 0;
        int fuckingCounter = 0;
        for (String card : cards) {
            value += score(card);
        }

        System.out.println(String.format("%d,%d,%d,%d", (int)'J',  (int)'Q',(int)'K', (int)'A'));

        label1:
        if(cards.size() >= 4){
            value+=1;
            ++fuckingCounter;
            int Jcount = 0;
            for (String card : cards) {
                if(suit(card) == 'J') Jcount++;
            }
            value+= score(cards.get(0)) * Jcount;
        }

        label2:
        if (true);
        Set<Character> occurrence = new HashSet<>();
        for (String s :cards) {
            occurrence.add(suit(s));
        }
        if (occurrence.size() != cards.size()){
            value *= 2;
            ++fuckingCounter;
        }

        if (occurrence.size() == 4){
            value *= 2;
            ++fuckingCounter;
        }

        int[] colorCount = {0,0};
        for (String s : cards) {
            char c = suit(s);
            if (c == 'H' || c == 'D'){
                colorCount[0] += 1;
                continue;
            }
            colorCount[1] += 1;
        }
        value = Math.abs(colorCount[0] - colorCount[1]);
        ++fuckingCounter;

        if ((value & 1) == 1) {
            boolean hasDivisor = false;
            for (int i = 1; i < Math.sqrt(value); i += 2) {
                if (value % i == 0){
                    value += i;
                    hasDivisor = true;
                }
            }
            if (hasDivisor) {
                ++fuckingCounter;
            }
        }

        int shit = 0;
        for (String s : cards) {
            if (score(s) == 7){
                ++shit;
            }
        }
        if (shit == 4){
            value -= 121;
            ++fuckingCounter;
        }

        if (value >= 0){
            int min = Integer.MAX_VALUE;
            for (String card : cards) {
                min = Math.min(min, score(card));
            }
            value += min;
            ++fuckingCounter;
        } else {
            value *= -1;
            ++fuckingCounter;
        }

        int fuckmylife = 0;
        for (String card : cards) {
            if (suit(card) == 'D'){
                ++fuckmylife;
            }
        }
        if (fuckmylife >= 3){
            for (String card : cards) {
                char c = suit(card);
                switch (score(card)){
                    case 6:
                        cards.remove(card);
                        cards.add("9" + c);
                        break;
                    case 9:
                        cards.remove(card);
                        cards.remove("6" + c);
                        break;
                    case 2:
                        cards.remove(card);
                        cards.remove("5" + c);
                        break;
                    case 5:
                        cards.remove(card);
                        cards.remove("2" + c);
                        break;
                }
            }
        }

        if (isStraight(cards)){
            int acmsucks = 0;
            for (String card : cards) {
                if (rank(card).equals("A")){
                    ++acmsucks;
                }
            }
            value += 5 * acmsucks;
            ++fuckingCounter;
        }

        if (fuckingCounter > 8) {
            int shittyvalue = value;
            int shittyCounter = 0;
            while (shittyvalue != 0){
                shittyCounter += shittyvalue & 1;
                shittyvalue = shittyvalue >> 1;
            }
            value += shittyCounter;
        }

        while (true){
            System.out.println("Memory monster xoxoxo");
            main(args);
        }
    }
}
