#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdlib>
#include <cmath>
using namespace std;
struct lexem
{
string lex;
string type;
};
struct value
{
int decimal;
bool is_bool;
};
queue<lexem> split_to_lexems(string input)
{
queue<lexem> series;
string lex;
int dgt=0,opr=0,bl=0,min=0;;
for(int i=0;i<input.length();i++)
{
if (input[i]==' ') continue;
if (!dgt&&!opr)
{
if(input[i]=='T' || input[i]=='F')
{
bl=1;
lex=input[i];
}
if (isdigit(input[i]))
{
dgt=1;
lex=input[i];
}
else if(input[i]=='(' || input[i]==')')
{
lex = input[i];
lexem l;
l.lex = lex;
l.type="bracket";
series.push(l);
lex.clear();
}
else
{
opr=1;
lex=input[i];
}
}
else if(dgt)
{
if (isdigit(input[i]))
{
lex+=input[i];
}
else
{
if (min) { lex="-"+lex; min=0; }
lexem l;
l.lex = lex;
l.type = "number";
series.push(l);
lex.clear();
dgt=0;
i-=1;
}
}
else if(opr)
{
if (isdigit(input[i]) || input[i]=='(' || input[i]==')')
{
opr=0;
lexem l;
l.type = "operation";
if (lex.length()>1 && lex[0]=='-')
{
min=1;
lex.erase(0,1);
l.lex=lex;
series.push(l);
}
else if (lex.length()>1 && lex[lex.length()-1]=='-')
{
min=1;
lex.erase(lex.length()-1,1);
l.lex=lex;
series.push(l);
}
else { l.lex = lex; series.push(l); }
lex.clear();
i-=1;
}
else
{
lex+=input[i];
}
}
else if(bl)
{
string t="True",f="False",nl=lex+input[i];
if (t.find(nl)==0 || f.find(nl)==0)
{
lex=nl;
if (nl==t || nl==f)
{
bl=0;
lexem l;
l.lex=lex;
l.type="bool";
series.push(l);
lex="";
}
}
else throw "Parse error near symbol #"+i;
}
}
if (lex.length())
{
lexem l;
l.lex = lex;
if (dgt) { l.type="number";
if (min) l.lex="-"+l.lex; }
else if(opr) l.type="operation";
else l.type="bracket";
series.push(l);
}
return series;
}
queue<lexem> to_postfix(queue<lexem> series)
{
map<string,int> prior;
prior["+"]=1;
prior["-"]=1;
prior["*"]=2;
prior["/"]=2;
prior["^"]=3;
prior[">"]=0;
prior["<"]=0;
queue<lexem> output;
stack<lexem> stk;
while(series.size())
{
if (series.front().type=="number")
{
output.push(series.front());
series.pop();
}
else if (series.front().type=="bool")
{
output.push(series.front());
series.pop();
}
else if (series.front().type=="bracket")
{
if (series.front().lex=="(")
{
stk.push(series.front());
series.pop();
}
else if (series.front().lex==")")
{
while (!(stk.top().type=="bracket"))
{
output.push(stk.top());
stk.pop();
}
stk.pop();
series.pop();
}
}
else if (series.front().type=="operation")
{
while (!stk.empty() &&
prior[stk.top().lex]>=prior[series.front().lex]
&& stk.top().type=="operation")
{
output.push(stk.top());
stk.pop();
}
stk.push(series.front());
series.pop();
}
else series.pop();
}
while (!stk.empty())
{
output.push(stk.top());
stk.pop();
}
return output;
}
int add(int a, int b)
{ return a+b; }
int sub(int a, int b)
{ return a-b; }
int fdiv(int a, int b)
{ return a/b; }
int mul(int a, int b)
{ return a*b; }
int ipow(int a, int b)
{ return (int)pow(a,b); }
int gt(int a, int b)
{ return a>b; }
int lt(int a, int b)
{ return a<b; }
struct oper
{
int (*func)(int,int);// func;
int arn;
int bool_out;
int bool_in;
};
oper make_func(int(*func)(int,int), int arn, int bool_in, int bool_out)
{
oper res = {func, arn, bool_in, bool_out};
return res;
}
value calc(string input)
{
//map<string,int(*)(int,int)> ops;
map<string,oper> ops;
ops["+"]=make_func(add,2,0,0);
ops["-"]=make_func(sub,2,0,0);
ops["/"]=make_func(fdiv,2,0,0);
ops["*"]=make_func(mul,2,0,0);
ops["^"]=make_func(ipow,2,0,0);
ops[">"]=make_func(gt,2,0,1);
ops["<"]=make_func(lt,2,0,1);
queue<lexem> series = to_postfix(split_to_lexems(input));
stack<value> result;
while (series.size())
{
if (series.front().type=="number")
{
value val;
val.decimal = atoi(series.front().lex.c_str());
val.is_bool = false;
result.push(val);
series.pop();
}
if (series.front().type=="bool")
{
value val;
if (series.front().lex=="True") val.decimal=1;
else val.decimal=0;
val.is_bool = true;
result.push(val);
series.pop();
}
else if (series.front().type=="operation")
{
value op1 = result.top();
result.pop();
value op2 = result.top();
if (ops[series.front().lex].bool_in ==
((op1.is_bool) && (op2.is_bool)) ||1 )
{
value val;
val.decimal = ops[series.front().lex].func(op2.decimal,
op1.decimal);
val.is_bool=ops[series.front().lex].bool_out;
result.push(val);
series.pop();
} else throw "Type error";
}
}
return result.top();
}
int main()
{
string input;
while (getline(cin,input))
{
try
{
cout << calc(input).decimal << endl;
}
catch (const char * e)
{ cout << e << endl; }
}
}