const
  znak = ['/','*','-','+'];

type PTree = ^Tree;
     Tree  = record
       left,rigth : PTree;
       key        : char;
     end;

var
  Tr : PTree;
  p  : pointer;

Procedure BuildTree(T : PTree; s : string; var n : integer);
begin
  t^.key:=s[n];
  if (s[n] in znak) then
  begin
    if not(t^.key in znak) then Write('Error');
    new(t^.rigth);
    dec(n);
    BuildTree(t^.rigth,s,n);
    if t^.key <> '-' then
    begin
      dec(n);
      if not(t^.key in znak) then Write('Error');
      new(t^.left);
      BuildTree(t^.left,s,n);
    end
    else t^.left:=nil;
  end
  else
  begin
    t^.left:=nil; t^.rigth:=nil;
  end;
end;


Procedure post2pref(var s1 : string; var n : integer; T : PTree);
begin
  if T <> nil then
  begin
    inc(n);
    post2pref(s1,n,t^.rigth);
    inc(n);
    post2pref(s1,n,t^.left);
    s1:=s1+t^.key;
  end;
end;


Procedure OutPut(out,s : string);
var
  f : text;
  i : integer;
begin
  assign(f,out); append(f);
  WriteLn(f);
  Write(f,'Preorder: ');
  for i:=length(s) downto 1 do Write(f,s[i]);
  close(f);
end;

Procedure ReadFile(inp,out : string);
var
  f,f1 : text;
  s,s1    : string;
  x : integer;
begin
  assign(f,inp); reset(f);
  assign(f1,out); rewrite(f1);
  ReadLn(f,s);
  WriteLn(f1,'Postorder: ',s);
  x:=length(s);
  BuildTree(Tr,s,x);
  x:=1;
  s1:='';
  WriteLn;
  Post2pref(s1,x,Tr);
{  if length(s1) <> length(s) then s1:='*******';}
  close(f1);
  Output('output.txt',s1);
  close(f);
end;

begin
  mark(p);
  new(Tr); 
  tr^.left:=nil; tr^.rigth:=nil;
  ReadFile('input.txt','output.txt');
  release(p);
end.