/* rpn: output Reverse Polish Form */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char next;
void E(void);
void T(void);
void S(void);
void F(void);
void gen(char);
void error(void);
void scan(void);

void main(void)
{
   scan();
   E();
   if (next != '#') error();
   else printf("\n");
}
void E(void)
{
   char save;
   T();
   while (next == '+' || next == '-') {
      save = next;
      scan();
      T();
      gen(save);
   }
}
void T(void)
{
   char save;
   S();
   while (next == '*' || next == '/') {
      save = next;
      scan();
      S();
      gen(save);
   }
}
void S(void)
{
   F();
   if (next == '^') {
      scan();
      S();
      gen('^');
   }
}
void F(void)
{
   if (isalpha(next)) {
      gen(next);
      scan();
   }
   else if (next == '(') {
      scan();
      E();
      if (next == ')') scan();
      else error();
   }
   else {
      error();
   }
}
void scan(void)
{
   while (isspace(next = getchar()))
      ;
}
void error(void)
{
   printf("\n*** ERROR ***\n");
   exit(1);
}
void gen(char ch)
{
   putchar(ch);
}