//我就是来水点积分的
tj
不想说~~~
很任性~
贴代码
var
a,b:array[0..100005]of longint;
i,j,k,l,n:longint;
procedure qsort(l,r:longint);
var
i,j,mid:longint;
begin
i:=l;
j:=r;
mid:=a[(i+j) div 2];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin
a[0]:=a[i];
a[i]:=a[j];
a[j]:=a[0];
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if l<j then qsort(l,j);
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
readln;
b:=a;
qsort(1,n);
k:=0;
for i:=1 to n do if a[i]<>b[i] then inc(k);
if k>2 then writeln('NO') else writeln('YES');
end.