#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100
int isoperator(char c){
    return(c == '+' || c == '-' | c == '*' || c =='/');
}
int isValidChar(char c){
    return (isalnum(c) || isOperator(c) || c == ')');
}
int main(){
    char prefix[MAX];
    fgets(prefix, sizeof(prefix),stdin);
    prefix[strcspn(prefix, "\n")] = '\0';
    char stack[MAX][MAX];
    int top = -1;int valid = 1;
    int paren = 0;
    int len = strlen(prefix);
    for(int i = len - 1;i >= 0; i--){
        char c = prefix[i];
        if(c == ' ') continue;
        if(!isValidChar(c)) valid = 0;
        if(c == ')') paren++;
        else if(c == '('){
            paren --;
            if(paren < 0) valid = 0;
        }
        if(!valid) break;
        if(isalnum(c)){
            char temp[2] = {c, '\0'};
            top++;
            strcpy(stack[top], temp);
        }
        else if(isOperator(c)){
            if(top <1){
                valid = 0; break;
            }
            char op1[MAX],op2[MAX], temp[MAX];
            strcpy(op1,stack[top--]);
                strcpy(op2,stack[top--]);
                    sprintf(temp,"%s %s %c",op1, op2, c);
                    top++;
                    strcpy(stack[top],temp);
            
        }
    }
    if(!valid || paren != 0 || top != 0){
        printf("Invalid input");
    }
    else{
        printf("%s", stack[top]);
    }
    return 0;
}