import java.util.*;

public class InfixToPostfix {
    private static final String LEFT_PAREN = "(";
    private static final String RIGHT_PAREN = ")";

    /** Stack for holding operators and parens. */
    private Deque<String> stack = new LinkedList<>();

    /** Map operators to precedence */
    private Map<String, Integer> opPrecedence = new HashMap<>();

    public void addOperator(String operator, int precedence) {
        opPrecedence.put(operator, precedence);
    }

    public boolean isOperator(String s) {
        return opPrecedence.containsKey(s);
    }

    public String convertExpr(String infixExpr) {
        String[] tokens = infixExpr.split(" ");
        return convertExpr(Arrays.asList(tokens));
    }

    public String convertExpr(List<String> tokens) {
        StringBuilder sb = new StringBuilder();
        for(String token : tokens) {
            if(isOperator(token)) {
                int precedence = opPrecedence.get(token);
                while(!stack.isEmpty() &&
                      isOperator(stack.peek()) &&
                      precedence <= opPrecedence.get(stack.peek())) {
                    sb.append(stack.pop() + " ");
                }
                stack.push(token);
            } else if(token.equals(LEFT_PAREN)) {
                stack.push(token);
            } else if(token.equals(RIGHT_PAREN)) {
                boolean foundLeftParen = false;
                while(!stack.isEmpty() && !foundLeftParen) {
                    String s = stack.pop();
                    if(s.equals(LEFT_PAREN)) {
                        foundLeftParen = true;
                    } else {
                        sb.append(s + " ");
                    }
                }
                if(!foundLeftParen) {
                    System.err.println("Mismatched parens (missing left)");
                }
            } else {
                // not operator or paren, must be operand
                sb.append(token + " ");
            }
        }
        // out of tokens, pop remaining operators
        while(!stack.isEmpty()) {
            if(stack.peek().equals(LEFT_PAREN)) {
                System.err.println("Mismatched parens (missing right)");
            }
            sb.append(stack.pop() + " ");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        InfixToPostfix converter = new InfixToPostfix();
        converter.addOperator("+", 1);
        converter.addOperator("-", 1);
        converter.addOperator("*", 2);
        converter.addOperator("/", 2);

        Scanner sc = new Scanner(System.in).useDelimiter("\n");        
        while(sc.hasNext()) {
            System.out.println(converter.convertExpr(sc.next()));
        }
    }
}
