

my @stack;

while (<>) {
  next unless /\S/;
  input_postfix(split);
}
output_infix(pop @stack);
print "\n";


sub input_postfix {
  for (@_) {
    if (/^\d+$/) {
      push @stack, $_;
    } elsif (/^[-+*\/]$/) {
      my $s2 = pop @stack;
      push @stack, [$_, pop(@stack), $s2];
    }
  }
}

sub output_infix {
  my $tree = shift;
  if (ref $tree) {
    print "(";
    output_infix($tree->[1]);
    print "$tree->[0]";
    output_infix($tree->[2]);
    print ")";
  } else {
    print $tree;
  }
}

