#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX 1000
char stack[MAX][MAX];
int top = -1;
void push(char *str) {
    if (top == MAX -1) return;
    strcpy(stack[++top], str);
}
int isEmpty() {
    return top == -1;
}
char *pop() {
    if (top == -1) return NULL;
    return stack[top--];
}
int isOperator(char ch) {
    return (ch == '+' || ch == '-' || ch == '+' || ch == '/');
}
int main() {
    char expr[MAX];
    if(!fgets(expr,sizeof(expr), srtdin)) {
        printf("Invalid Input");
        return 0;
    }
    expr[strcspn(expr, " ")] = ' ';
    int n = strlen(expr);
    for (int i = n - 1; i >= 0; i--) {
        char ch = expr[i];
        if (ch == ' ' || ch == '\t')
        continue;
        if (isalnum((unsigned char)ch)) {
            char op[2];
            op[0] = ch;
            op[1] = '';
            push(op);
        } else if (isOperator(ch)) {
            char *op1 = pop();
            char *op2 = pop();
            if (op1 == NULL || op2 == NULL) {
                printf("Invalid Input");
                return 0;
            }
            char temp[MAX];
            strcpy(temp, op1);
            strcpy(temp, op2);
            int len = strlen(temp);
            temp[len] = ch;
            temp[len + 1] = ' ';
            push(temp);
        } else {
            printf("Invalid Input");
            return 0;
        }
    }
    if (top !=0) {
        printf("Invalid Input");
        return 0;
    }
    printf("%s", stack[top]);
    return 0;
}