#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX 100

char stack[MAX][MAX];
int top = -1;

// Push string
void push(char *str) {
    strcpy(stack[++top], str);
}

// Pop string
char* pop() {
    return stack[top--];
}

// Check operator
int isOperator(char c) {
    return (c == '+' || c == '-' || c == '*' || c == '/' || c == '^');
}

// Convert prefix to postfix
void prefixToPostfix(char prefix[]) {
    int len = strlen(prefix);

    // Traverse from right to left
    for (int i = len - 1; i >= 0; i--) {
        char ch = prefix[i];

        // Skip spaces
        if (isspace(ch))
            continue;

        if (isalnum(ch)) {
            // Operand → push
            char op[2] = {ch, '\0'};
            push(op);
        }
        else if (isOperator(ch)) {
            if (top < 1) {
                printf("Invalid input\n");
                return;
            }
            char op1[MAX], op2[MAX], temp[MAX];
            strcpy(op1, pop());
            strcpy(op2, pop());
            sprintf(temp, "%s%s%c", op1, op2, ch);
            push(temp);
        }
        else {
            printf("Invalid input\n");
            return;
        }
    }

    // Only one element should remain (final postfix)
    if (top == 0)
        printf("%s\n", stack[top]);
    else
        printf("Invalid input\n");
}

int main() {
    char prefix[MAX];
    // Read a line of input (with spaces)
    fgets(prefix, sizeof(prefix), stdin);

    // Remove newline if present
    prefix[strcspn(prefix, "\n")] = '\0';

    prefixToPostfix(prefix);
    return 0;
}