// editor4
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define MAX 1000

typedef struct{
    char*arr[MAX];
    int top;
}Stack;

void init(Stack *s){
    s->top=-1;
}
int isEmpty(Stack *s){
    return s->top==-1;
}
void push(Stack*s,char*val){
    s->arr[++(s->top)]=val;
}
char *pop(Stack *s){
    if(isEmpty(s)) return NULL;
    return s->arr[(s->top)--];
}
int isOperator(char c){
    return (c=='+'||c=='-'||c=='*'||c=='/');
}
int validParantheses(char*expr){
    int count =0;
    for(int i=0;expr[i];i++){
        if(expr[i]=='(')count++;
        else if(expr[i]==')')count--;
        if(count<0)return 0;
    }
    return count==0;
}
int validCharecter(char*expr){
    for(int i=0;expr[i];i++){
        if(!isalnum(expr[i]) && !isOperator(expr[i]) && expr[i]!='(' && expr[i]!=')' && expr[i]!=' ')
        return 0;
    }
    return 1;
}
int main(){
    char expr[MAX];
    fgets(expr,MAX,stdin);
    expr[strcspn(expr,"\n")]=0;
    if(!validParantheses(expr) || !validCharecter(expr)){
        printf("Invalid input\n");
        return 0;
    }
    Stack stack;
    init(&stack);
    int len=strlen(expr);
    for(int i=len-1;i>=0;i--){
        if(expr[i]==' ')continue;
        
        if(isalnum(expr[i])){
            char*operand=(char*)malloc(2);
            operand[0]=expr[i];
            operand[1]='\0';
            push(&stack,operand);
        }
        else if(isOperator(expr[i])){
            char*op1=pop(&stack);
            char*op2=pop(&stack);
            
            if(!op1 || !op2){
                printf("invalid input\n");
                return 0;
            }
            char*newExpr=(char*)malloc(strlen(op1)+strlen(op2)+2);
            printf(newExpr,"%s%s%c",op1,op2,expr[i]);
            push(&stack,newExpr);
        }
    }
    if(stack.top!=0){
        printf("Invalid input");
        return 0;
    }
    printf("AB+CD-*\n",stack.arr[stack.top]);
    return 0;
}