CHEAT - Chơi bi-a 1 lỗ
Tác giả: RR
Ngôn ngữ: Pascal
var
a,s:array[1..1000111] of longint;
u,i,top,n:longint;
begin
read(n);
for i:=1 to n do read(a[i]);
top:=0; u:=1;
for i:=1 to n do
begin
inc(top); s[top]:=i;
while (a[u]=s[top]) do
begin
inc(u);
dec(top);
end;
end;
while (top>0) and (a[u]=s[top]) do
begin
dec(top);
inc(u);
end;
if top>0 then writeln('YES')
else writeln('NO');
end.