#include<iostream>
#include<fstream>
using namespace std;
ifstream f("date");
struct nod{int info;
nod* st,*dr;};
nod* creare()
{int x;
f>>x;
if(x)
{nod*p=new nod;
p->info=x;
p->st=creare();
p->dr=creare();
return p;}
else return NULL;}
void RSD(nod* R)
{if(R)
{cout<<R->info;
RSD(R->st);
RSD(R->dr);}
}
void fii(nod* R, int x)
{if(R)
{if(x==R->info)
{if(R->st)
cout<<R->st->info<<" ";
if(R->dr)
cout<<R->dr->info<<" ";
}
fii(R->st,x);
fii(R->dr,x);
}
}
int suma(nod* R)
{
if(R)
return R->info+suma(R->st)+suma(R->dr);
else return 0;
}
int main()
{nod* R;
R=creare();
RSD(R);
cout<<endl;
fii(R,3);
cout<<endl;
cout<<suma(R);
}