#include<iostream>
using namespace std;
struct Stack
{
char data;
Stack *next;
};
Stack *top=NULL;
void push(int item)
{
Stack *New=new Stack;
if(New==NULL)
{
cout<<"Overflow"<<endl;
exit(1);
}
New->data=item;
New->next=NULL;
New->next=top;
top=New;
}
void pop()
{
if(top==NULL)
{
cout<<"Underflow"<<endl;
exit(1);
}
top=top->next;
}
int main()
{
string infix;
getline(cin,infix);
infix="(" +infix+")";
string exp;
for(int i=0;i<infix.size();i++)
{
if(infix[i]>='A' && infix[i]<='Z')
{
exp.push_back(infix[i]);
}
else if(infix[i]=='(')
{
push(infix[i]);
}
else if(infix[i]==')')
{
while(top->data != '(')
{
exp.push_back(top->data);
pop();
}
pop();
}
else
{
while(true)
{
if((infix[i]=='^' || infix[i]=='*' || infix[i]=='/') &&(top->data=='+' || top->data=='-'))
{
push(infix[i]);
break;
}
else if(infix[i]=='^' && (top->data=='*' || top->data=='/'))
{
push(infix[i]);
break;
}
else if(top->data=='(')
{
push(infix[i]);
break;
}
else
{
exp.push_back(top->data);
pop();
}
}
}
}
cout<<exp<<endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnN0cnVjdCBTdGFjawp7CiAgICBjaGFyIGRhdGE7CiAgICBTdGFjayAqbmV4dDsKfTsKICAgU3RhY2sgKnRvcD1OVUxMOwp2b2lkIHB1c2goaW50IGl0ZW0pCnsKICAgIFN0YWNrICpOZXc9bmV3IFN0YWNrOwogICAgaWYoTmV3PT1OVUxMKQogICAgewogICAgICAgIGNvdXQ8PCJPdmVyZmxvdyI8PGVuZGw7CiAgICAgICAgZXhpdCgxKTsKICAgIH0KICAgIE5ldy0+ZGF0YT1pdGVtOwogICAgTmV3LT5uZXh0PU5VTEw7CiAgICBOZXctPm5leHQ9dG9wOwogICAgdG9wPU5ldzsKfQp2b2lkIHBvcCgpCnsKICAgIGlmKHRvcD09TlVMTCkKICAgIHsKICAgICAgICBjb3V0PDwiVW5kZXJmbG93Ijw8ZW5kbDsKICAgICAgICBleGl0KDEpOwogICAgfQogICAgdG9wPXRvcC0+bmV4dDsKfQppbnQgbWFpbigpCnsKICAgIHN0cmluZyBpbmZpeDsKICAgIGdldGxpbmUoY2luLGluZml4KTsKICAgIGluZml4PSIoIiAraW5maXgrIikiOwogICAgc3RyaW5nIGV4cDsKICAgIGZvcihpbnQgaT0wO2k8aW5maXguc2l6ZSgpO2krKykKICAgIHsKICAgICAgICBpZihpbmZpeFtpXT49J0EnICYmIGluZml4W2ldPD0nWicpCiAgICAgICAgewogICAgICAgICAgICBleHAucHVzaF9iYWNrKGluZml4W2ldKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZihpbmZpeFtpXT09JygnKQogICAgICAgIHsKICAgICAgICAgICAgcHVzaChpbmZpeFtpXSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYoaW5maXhbaV09PScpJykKICAgICAgICB7CiAgICAgICAgICAgIHdoaWxlKHRvcC0+ZGF0YSAhPSAnKCcpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGV4cC5wdXNoX2JhY2sodG9wLT5kYXRhKTsKICAgICAgICAgICAgICAgIHBvcCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHBvcCgpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICB3aGlsZSh0cnVlKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZigoaW5maXhbaV09PSdeJyB8fCBpbmZpeFtpXT09JyonIHx8IGluZml4W2ldPT0nLycpICYmKHRvcC0+ZGF0YT09JysnIHx8IHRvcC0+ZGF0YT09Jy0nKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBwdXNoKGluZml4W2ldKTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UgaWYoaW5maXhbaV09PSdeJyAmJiAodG9wLT5kYXRhPT0nKicgfHwgdG9wLT5kYXRhPT0nLycpKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHB1c2goaW5maXhbaV0pOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZSBpZih0b3AtPmRhdGE9PScoJykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBwdXNoKGluZml4W2ldKTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UgCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZXhwLnB1c2hfYmFjayh0b3AtPmRhdGEpOwogICAgICAgICAgICAgICAgICAgIHBvcCgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY291dDw8ZXhwPDxlbmRsOwogICAgcmV0dXJuIDA7Cn0=