program acm1326;
type
node=^rec;
rec=record
data:longint;
link:node;
end;
var
slow,p,q:node; n,i,key:longint; st:string;
procedure insert(st:string);
var
t,x,t2,i:longint; u,head,ko:node; st2:string;
begin
u:=q; head:=q; t:=pos(' ',st);
delete(st,1,t); t:=pos(' ',st); st2:=copy(st,t+1,length(st)-t);
delete(st,t,length(st)-t+1);
val(st,t); val(st2,t2);
if (u=nil)and(t>1) then begin write('insert fail'); exit;end;
for i:=1 to t-1 do
begin
u:=u^.link;
if u=nil then begin write('insert fail'); exit; end;
end;
for i:=1 to t-2 do
head:=head^.link;
if t=1 then begin new(ko); ko^.data:=t2; ko^.link:=u; q:=ko; end else begin
new(ko); ko^.data:=t2; ko^.link:=u; head^.link:=ko;end; write('insert OK');
end;
procedure show;
var
u:node;
begin
u:=q; if u=nil then begin write('Link list is empty'); exit; end;
write(u^.data); u:=u^.link;
while u<>nil do
begin
write(' ',u^.data);
u:=u^.link;
end;
end;
procedure delete2(st:string);
var
t,i:longint; u,head:node;
begin
t:=pos(' ',st); delete(st,1,t); val(st,t);
u:=q; head:=q;
if u=nil then begin write('delete fail'); exit; end;
for i:=1 to t-1 do
begin
u:=u^.link;
if u=nil then begin write('delete fail'); exit; end;
end;
for i:=1 to t-2 do
head:=head^.link;
if t=1 then q:=q^.link else begin
head^.link:=u^.link; end; write('delete OK');
end;
procedure get(st:string);
var
t,i:longint; u:node; f:boolean;
begin
u:=q; f:=false;
t:=pos(' ',st); delete(st,1,t); val(st,t);
i:=0;
while u<>nil do
begin
inc(i);
if i=t then begin write(u^.data); f:=true; exit; end;
u:=u^.link;
end;
if not f then write('get fail');
end;
begin
read(n); p:=nil;
for i:=1 to n do
begin
read(key); new(q);
q^.data:=key; q^.link:=p;
p:=q;
end;
readln(n);
for i:=1 to n do
begin
readln(st);
if st[1]='g' then begin get(st); end;
if st[1]='s' then begin show; end;
if st[1]='i' then begin insert(st);end;
if st[1]='d' then begin delete2(st);end;
writeln;
end;
end.
/**************************************************************
Problem: 2138
User: admin
Language: Pascal
Result: Wrong Answer
****************************************************************/