I have WA#9. Who knows where is my fault?
If who knows please tell me where is my mistake?
{PASCAL CODE HERE}
var
t,st:string;
i:integer;
procedure init;
begin
readln(st);
i:=0; t:=st;
end;
procedure solve1;
begin
repeat
inc(i);
if st[i]='(' then
begin
if ((pos(')',st)<>0) and (pos(')',st)>=i)) then
begin
st[i]:=' '; st[pos(')',st)]:=' ';
end;
end else
if st[i]=')' then
begin
if ((pos('(',st)<>0) and (pos('(',st)<=i)) then
begin
st[i]:=' '; st[pos('(',st)]:=' ';
end;
end else
if st[i]='[' then
begin
if ((pos(']',st)<>0) and (pos(']',st)>=i)) then
begin
st[i]:=' '; st[pos(']',st)]:=' ';
end;
end else
if st[i]=']' then
begin
if ((pos('[',st)<>0) and (pos('[',st)<=i)) then
begin
st[i]:=' '; st[pos('[',st)]:=' ';
end;
end;
until i=length(st);
end;
procedure solve2;
begin
i:=0;
repeat
inc(i);
if st[i]='(' then
begin
insert(')',t,i+1); insert(' ',st,i+1); inc(i);
end;
if st[i]=')' then
begin
insert('(',t,i); insert(' ',st,i+1); inc(i);
end;
if st[i]='[' then
begin
insert(']',t,i+1); insert(' ',st,i+1); inc(i);
end;
if st[i]=']' then
begin
insert('[',t,i); insert(' ',st,i+1); inc(i);
end;
until i=length(st);
end;
procedure print;
begin
writeln(t);
end;
begin
init;
solve1;
solve2;
print;
end.