// editor4

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX 1000

char stack[MAX][MAX];
int top = -1;

// Push string to stack
void push(char str[])
{
    strcpy(stack[++top], str);
}

// Pop string from stack
char* pop()
{
    return stack[top--];
}

// Check valid operator
int isOperator(char ch)
{
    return (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '^');
}

// Check parentheses balance
int isBalanced(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 main()
{
    char prefix[MAX];
    scanf("%s", prefix);

    // Check parentheses balance
    if (!isBalanced(prefix))
    {
        printf("Invalid input");
        return 0;
    }

    int len = strlen(prefix);

    // Scan from right to left
    for (int i = len - 1; i >= 0; i--)
    {
        char ch = prefix[i];

        // Operand
        if (isalnum(ch))
        {
            char temp[2] = {ch, '\0'};
            push(temp);
        }
        // Operator
        else if (isOperator(ch))
        {
            if (top < 1)
            {
                printf("Invalid input");
                return 0;
            }

            char op1[MAX], op2[MAX], expr[MAX];
            strcpy(op1, pop());
            strcpy(op2, pop());

            sprintf(expr, "%s%s%c", op1, op2, ch);
            push(expr);
        }
        // Parentheses are ignored during conversion
        else if (ch == '(' || ch == ')')
        {
            continue;
        }
        else
        {
            printf("Invalid input");
            return 0;
        }
    }

    // Final result
    if (top != 0)
    {
        printf("Invalid input");
        return 0;
    }

    printf("%s", pop());
    return 0;
}