program main
  implicit none
  integer :: n, i, p(50), sp(50), c
  read (*, *) n
  read (*, *) p(1:n)
  sp(1:n) = p(1:n)
  call insertion_sort(sp(1:n))
  c = 0
  do i = 1, n
    if (p(i) /= sp(i)) c = c + 1
  end do
  if (c <= 2) then
    write (*, "(a)") "YES"
  else
    write (*, "(a)") "NO"
  end if

  contains
  subroutine insertion_sort(s)
    implicit none
    integer, intent(inout) :: s(:)
    integer :: i, j, tmp
    do i = 2, size(s)  ! ループ終了時に [1, i] が昇順
      do j = i, 2, -1  ! i の位置にあった新要素が適切な位置に来るまで隣同士 swap
        if (s(j) >= s(j - 1)) exit
        tmp = s(j)
        s(j) = s(j - 1)
        s(j - 1) = tmp
      end do
    end do
  end subroutine insertion_sort
end program main
