# hdu 1427 24点暴力dfs

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int num;
int a[4],x;
const int inf=1<<10;
// 括号改变的运算符的优先级所以
//a@b@c@d            符号的全排列有 3!种可能  由于数字可以调换  ((a@b)@c) @d  等价于 a @ ((b@c)@d )     要想使(i,j,k,l) 的优先级为 a @ ((b@c)@d ) 等价于  j,k,l,i 在 ((a@b)@c) @d 所以这种情况保留一个就好
int calc(int op,int b,int c)
{
switch(op)
{
case 1: return b+c;
case 2: return b-c;
case 3: return b*c;
case 4: if(c!=0&&b%c==0) return b/c;
else return inf;

}
}

bool fun1()  // ((a@b)@c)@d
{
int i,j,k;
int k1,k2,ans;
for(i=1;i<=4;i++)
{
k1=calc(i,a[0],a[1]);
if(k1==inf) continue;
for(j=1;j<=4;j++)
{
k2=calc(j,k1,a[2]);
if(k2==inf) continue;
for(k=1;k<=4;k++)
{
ans=calc(k,k2,a[3]);
if(ans==inf) continue;
if(ans==24)
return 1;
}
}
}
return 0;
}
bool fun2() // (a@b)@(c@d)
{
int i,j,k;
int k1,k2,ans;
for(i=1;i<=4;i++)
{
k1=calc(i,a[0],a[1]);
if(k1==inf) continue;
for(j=1;j<=4;j++)
{
k2=calc(j,a[2],a[3]);
if(k2==inf) continue;
for(k=1;k<=4;k++)
{
ans=calc(k,k1,k2);
if(ans==inf) continue;
if(ans==24)
return 1;
}
}
}
return 0;
}
bool fun3() // (a@(b@c))@d
{
int i,j,k;
double k1,k2,ans;
for(i=1;i<=4;i++)
{
k1=calc(i,a[1],a[2]);
if(k1==inf) continue;
for(j=1;j<=4;j++)
{
k2=calc(j,a[0],k1);
if(k2==inf) continue;
for(k=1;k<=4;k++)
{
ans=calc(k,k2,a[3]);
if(ans==inf) continue;
if(ans==24)
return 1;
}
}
}
return 0;
}

int main()
{
char b[5];
int t,i;

while(1)
{

int f=0;
for(i=0;i<4;i++)
{
if(scanf("%s",b)==EOF) return 0;
if(b[0]=='A')
{
a[i]=1;
continue;
}
if(b[0]=='J')
{
a[i]=11;
continue;
}
if(b[0]=='Q')
{
a[i]=12;
continue;
}
if(b[0]=='K')
{
a[i]=13;
continue;
}
if(b[0]=='1'&&b[1]=='0')//
{
a[i]=10;
continue;
}
a[i]=b[0]-'0';

}
sort(a,a+4);
do{ 						//生成数字的全排列
if(fun1())
{
f=1;
break;
}
if(fun2())
{
f=1;
break;
}
if(fun3())
{
f=1;
break;
}
}while(next_permutation(a,a+4));
if(f)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}

05-13 731

07-16 4787

05-17 316

01-18 212

11-25 1372

04-07 428

01-19 260

02-26 548

08-01 2064

08-21 241