#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define int long long
int check(char c)
{
switch(c)
{
case '+':return 1;
case '-':return 1;
case '*':return 2;
case '/':return 2;
case '^':return 3;
default:return -1;
}
}
stack<char> a;
vector<char> b;
vector<int> t;
main()
{
string s;
getline(cin,s);
int tmp = s.size()-1;
for(auto c:s)
{
if(c >= '0' && c <= '9')
b.push_back(c);
if(check(c) >= 1 && check(c) <= 3)
{
if(!a.empty())
{
while(!a.empty() && check(c) <= check(a.top()))
{
if(check(c) == check(a.top()) && check(c) == 3)break;
b.push_back(a.top());
a.pop();
}
}
a.push(c);
}
if(c == '(')
a.push(c);
if(c == ')')
{
while(a.top() != '(')
{
b.push_back(a.top());
a.pop();
}
a.pop();
}
if(c == s[tmp])
{
while(!a.empty())
{
b.push_back(a.top());
a.pop();
}
}
}
for(int i = 0;i < b.size();i++)
{
cout << b[i] << ' ';
}
cout << endl;
int x,y,z;
int ans;
for(int i = 0;i < b.size();i++)
{
if(b[i] >= '0' && b[i] <= '9')
{
ans = b[i]-'0';
t.push_back(ans);
}
if(b[i] == '+')
{
x = t.back();
t.pop_back();
y = t.back();
t.pop_back();
z = x+y;
t.push_back(z);
for(int j = 0;j < t.size() ; j++)
{
cout << t[j] << ' ';
}
for(int j = i+1;j < b.size() ; j++)
{
cout << b[j] << ' ';
}
cout << endl;
}
if(b[i] == '-')
{
x = t.back();
t.pop_back();
y = t.back();
t.pop_back();
z = y-x;
t.push_back(z);
for(int j = 0;j < t.size() ; j++)
{
cout << t[j] << ' ';
}
for(int j = i+1;j < b.size() ; j++)
{
cout << b[j] << ' ';
}
cout << endl;
}
if(b[i] == '*')
{
x = t.back();
t.pop_back();
y = t.back();
t.pop_back();
z = x*y;
t.push_back(z);
for(int j = 0;j < t.size() ; j++)
{
cout << t[j] << ' ';
}
for(int j = i+1;j < b.size() ; j++)
{
cout << b[j] << ' ';
}
cout << endl;
}
if(b[i] == '/')
{
x = t.back();
t.pop_back();
y = t.back();
t.pop_back();
z = y/x;
t.push_back(z);
for(int j = 0;j < t.size() ; j++)
{
cout << t[j] << ' ';
}
for(int j = i+1;j < b.size() ; j++)
{
cout << b[j] << ' ';
}
cout << endl;
}
if(b[i] == '^')
{
x = t.back();
t.pop_back();
y = t.back();
t.pop_back();
z = pow(y,x);
t.push_back(z);
for(int j = 0;j < t.size() ; j++)
{
cout << t[j] << ' ';
}
for(int j = i+1;j < b.size() ; j++)
{
cout << b[j] << ' ';
}
cout << endl;
}
}
}