#include<stdio.h>
#include<string.h>
#include<ctype.h>
char stack[200][400];
int top = -1;
void push(char *s){ strcpy(stack[++top],s); } 
char* pop(){ return stack[top--];
int isOp(char c){ return c=='+' || c == '-' || c == '*' || c == '/' || c == '^'; }
int main() {
    char exp[400];
   if (!fgets(exp,sizeof(exp),stdin))
   return 0;
    exp[strcspn(exp,"\n")] = '\0';
    int n=strlen(exp);
    for(int i=n-1;i>=0;i--) {
        char c=exp[i];
        if(c == ' ' || c == '\t') 
        continue;
        if(isalnum(unsigned char)c)) {
            char t[2];
            t[0] = c;
            t[1] = '\0';
            push(t);
         }else if(isOp(c)){
             if(top<1){printf("Invalid input");return 0; }
             char a[400],b[400],t[800];
             strcpy(a,pop());
             strcpy(b,pop));
             sprintf(t,%s%s%c",a,b,c);
             push(t);
            }else if(c == '(' || c == ')'{
                continue;
         }else {
             printf("Invalid input");
             return 0;
        }
    }
     
    if(top!=0){ printf("Invalid input");
    return 0; }
    printf("%s",stack[top]);
    return 0;
}