/*
第一次接触建树解题
简单建树、历编,求和问题
解题思路:递归
方法一:只保留树的节点部分
方法二:建一棵完整的树
cin.clear()清除
*/
/*方法一:
#include <iostream>
#include <string>
using namespace std;
bool ok;
bool tree_sum(int n,int sum)
{
char ch;
cin>>ch;
int v;
if(!((cin>>v)==0))
{
n+=v;
bool t;
t=tree_sum(n,sum)|tree_sum(n,sum);
if(!ok && !t)
ok=(n==sum);
cin>>ch;
return true;
}
else
{
cin.clear();
cin>>ch;
return false;
}
}
int main()
{
int sum;
while(!((cin>>sum)==0))
{
ok=false;
tree_sum(0,sum);
cout<<(ok?"yes":"no")<<endl;
}
return 0;
}
*/
//////////////////////////////////方法二:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
bool ok;
struct Node
{
Node *lchild,*rchild;
};
Node *creat_tree(int n,int sum)
{
char ch;
cin>>ch;
int v;
if(!((cin>>v)==0))
{
n+=v;
Node *root=(Node *)malloc(sizeof(Node));
root->lchild=creat_tree(n,sum);
root->rchild=creat_tree(n,sum);
if(!ok && root->lchild==NULL && root->rchild==NULL)
ok=(n==sum);
cin>>ch;
return root;
}
else
{
cin.clear();
cin>>ch;
return NULL;
}
}
int main()
{
int sum;
while(!((cin>>sum)==0))
{
ok=false;
creat_tree(0,sum);
cout<<(ok?"yes":"no")<<endl;
}
return 0;
}