#include using namespace std; typedef long long int ll; typedef double ld; typedef pair ii; typedef vector vi; typedef vector vii; #define PB push_back #define ff first #define ss second #define FOR(prom,a,b) for ( ll prom = (a); prom < (ll)(b); ++prom) #define F(a) FOR(i,0,a) #define FF(a) FOR(j,0,a) //#define M_PI 3.14159265358979323846 #define EPS (1e-10) #define EQ(a,b) (fabs(a-b) <= fabs(a+b)*EPS) #define LINF (1<<62LL) #define DEB cerr<<"DEB: " #define MX 10000 vi divisors(int n) { vi a,b; for(int i=1;i*i<=n;++i){ if(n%i==0) { a.PB(i); b.PB(n/i); } } if(b.back()==a.back())b.pop_back(); while(!b.empty()) { a.PB(b.back()); b.pop_back(); } return a; } struct Card { char t; int v; char f; }; ll score = 0; Card hand[5]; int modified = 0; int lm = 1; void apply1() { int cnt = 0; ++score; F(5) { if(hand[i].f=='J') ++cnt; } score += cnt*hand[0].v; //DEB << score << endl; ++modified; } void apply2() { F(5) { for(int j = i+1; j < 5; ++j ) { if(hand[i].t == hand[j].t) { score *= 2; //DEB << score << endl; ++modified; lm =2; return; } } } } void apply3() { char s[] = {0,0,0,0}; F(5) { if(hand[i].t == 'D') s[0] += 1; if(hand[i].t == 'H') s[1] += 1; if(hand[i].t == 'C') s[2] += 1; if(hand[i].t == 'S') s[3] += 1; } if( s[0] > 0 && s[1]> 0 && s[2]> 0&&s[3]> 0) { score *=2; //DEB << score << endl; lm =3; ++modified; } } void apply4() { char s[] = {0,0,0,0}; F(5) { if(hand[i].t == 'D') s[0] += 1; if(hand[i].t == 'H') s[1] += 1; if(hand[i].t == 'C') s[2] += 1; if(hand[i].t == 'S') s[3] += 1; } if(s[0]+s[1] != s[2]+s[3]) { score += abs(s[0]+s[1]-s[2]-s[3]); //DEB << score << endl; lm =4; ++modified; } } void apply5() { if(score % 2 == 0 ) { vi divis = divisors(score); for(auto i : divis) score += i; //DEB << score << endl; lm =5; ++modified; } } void apply6() { int cnt = 0; F(5) { if(hand[i].v==7) ++cnt; } if(cnt == 4) { score -= 11*11; ++modified; lm=6; } } void apply7() { int mini = 9999; F(5) { mini = min(mini, hand[i].v); } if( score >= 0 ) { score += mini; ++modified; lm =7; } } void apply8() { if( score < 0 ) { score *= -1; ++modified; lm=8; } } void apply9() { char s[] = {0,0,0,0}; F(5) { if(hand[i].t == 'D') s[0] += 1; if(hand[i].t == 'H') s[1] += 1; if(hand[i].t == 'C') s[2] += 1; if(hand[i].t == 'S') s[3] += 1; } if(s[0] >= 3) { score += 1; ++modified; lm=9; F(5) { if( hand[i].v == 6 ) { hand[i].v = 9; } else if ( hand[i].v == 9 ) { hand[i].v = 6; } else if ( hand[i].v == 2) { hand[i].v = 5; } else if ( hand[i].v == 5) { hand[i].v = 2; } } } } void apply10() { vector values; bool hasA = false; F(5) { if(hand[i].f == 'J') values.PB(11); else if(hand[i].f == 'Q') values.PB(12); else if(hand[i].f == 'K') values.PB(13); else if(hand[i].f == 'A') { values.PB(14); hasA = true; } else values.PB(hand[i].v); } sort(values.begin(), values.end()); F(4) { if(values[i]-values[i+1] != -1) return; } if( hasA ) { score += 5; lm =10; ++modified; } } void apply11() { if( modified > 8 ) { bitset<64> n(score); score += n.count(); lm=11; } } void apply12() { bool yes = false; F(5) { if(hand[i].v == 2) yes = true; } if(yes) { switch(lm) { case 1: apply1(); break; case 2: apply2(); break; case 3: apply3(); break; case 4: apply4(); break; case 5: apply5(); break; case 6: apply6(); break; case 7: apply7(); break; case 8: apply8(); break; case 9: apply9(); break; case 10: apply10(); break; case 11: apply11(); break; } } } void apply13() { bool yes = false; F(5) { if(hand[i].v == 2) yes = true; } if(yes) { score *=2; } } Card parse(string & c) { Card car; if(c[0] == 'J' || c[0] == 'Q' || c[0] == 'K' || c[0] == 'A') { car.v = 10; car.f = c[0]; } else if(c.size() == 3) { car.v = 10; car.f = 'D'; } else { car.v = atoi(c.substr(0,1).c_str()); car.f = 'S'; } score+=car.v; car.t = c[c.size()-1]; return car; } int main() { string c; F(5) { cin >> c; hand[i]=parse(c); } apply1(); apply2(); apply3(); apply4(); apply5(); apply6(); apply7(); apply8(); apply9(); apply10(); apply11(); apply12(); apply13(); cout << score << endl; return 0; }