program kadai
implicit none
integer  ::  n
integer,allocatable  ::  p(:)
integer  ::  i,check


read(*,*) n
allocate(p(n))
read(*,*) p

check=0
do i=1,n
    if (i==p(i)) then
        check=check+1
    end if
end do
if (check==n-2 .or. check==n) then
    write(*,*) "YES"
else
    write(*,*) "NO"
end if


stop

end program kadai
