#include using namespace std; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define __fix ios_base::sync_with_stdio(0); cin.tie(0); typedef long long LL; typedef long double LD; typedef pair < int, int > PII; typedef pair < LL, LL > PLL; typedef pair < LD, LD > PDD; vector < string > vec; map < char, int > C, M; LL val = 0; int score(char z) { if(2 <= z && z <= 10) return z; return 10; } int mod = 0; int last = -1; void apply(int ty) { if(ty == 1) { val++; val += M['J'] * score(vec[0][0]); mod++,last = ty; } if(ty == 2) { for(auto x: C) { if(x.second >= 2) { val *= 2; mod++,last = ty; break; } } } if(ty == 3) { bool ok = 1; for(auto c: C) { if(c.second == 0) ok = 0; } if(ok) { val *= 2; mod++,last = ty; } } if(ty == 4) { int b1 = C['C'] + C['S']; int r1 = C['H'] + C['D']; val += abs(b1 - r1); if(abs(b1 - r1) != 0) mod++,last = ty; } if(ty == 5) { if(val % 2 == 0) { mod++,last = ty; int cp = val; for(int d = 1; d <= cp; d++) { if(cp % d == 0) val += d; } } } if(ty == 6) { if(M[7] == 4) { mod++,last = ty; val -= 121; } } if(ty == 7) { if(val >= 0) { bool ok = 0; for(int i = 2; i <= 10; i++) if(M[i] > 0) { ok = 1; val += i; break; } if(!ok) { val += 10; } mod++,last = ty; } } if(ty == 8) { if(val < 0) { val *= -1; mod++,last = ty; } } if(ty == 9) { if(C['D'] >= 3) { val++; mod++,last = ty; for(int i = 0; i < 5; i++) { if(vec[i][0] == 6) { M[6]--; M[9]++; vec[i][0] = 9; } else if(vec[i][0] == 9) { M[9]--; M[6]++; vec[i][0] = 6; } else if(vec[i][0] == 2) { M[2]--; M[5]++; vec[i][0] = 5; } else if(vec[i][0] == 5) { M[5]--; M[2]++; vec[i][0] = 2; } } } } if(ty == 10) { vector < int > help = {2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A'}; for(int i = 0; i + 5 <= sz(help); i++) { bool ok2 = 1; for(int j = i; j < i + 5; j++) if(M[help[j]] == 0) ok2 = 0; if(ok2) { val += 5 * M['A']; mod++,last = ty; break; } } } if(ty == 11) { if(mod > 8) { mod++,last = ty; val += __builtin_popcountll(val); } } if(ty == 12) { if(M[2] > 0) { mod++; apply(last); last = ty; } } if(ty == 13) { if(M[2] > 0) val += abs(val); } } int main() { __fix C['D'] = 0; C['H'] = 0; C['C'] = 0; C['S'] = 0; for(int i = 0; i < 5; i++) { string s; cin >> s; if(sz(s) == 3) { char s1 = 10; char s2 = s[2]; s = ""; s.push_back(s1); s.push_back(s2); } else if('2' <= s[0] && s[0] <= '9') { s[0] -= '0'; } M[s[0]]++; C[s[1]]++; val += score(s[0]); vec.push_back(s); // cout << (int)s[0] << " " << s[1] << "\n"; } // cout << val << "\n"; for(int i = 1; i <= 13; i++) apply(i); // cout << i << " " << val << "\n"; cout << val << "\n"; return 0; }