program test
  implicit none
  integer :: n, flag, i, k, j
  integer, dimension ( : ), allocatable :: p, q

  read ( unit = *, fmt = * ) n

  allocate ( q ( 1:n ) )  
  allocate ( p ( 1:n ) )
  allocate ( a ( 1:n ) )  

  read ( unit = *, fmt = * ) p ( 1:n )

  k = 1

  do j = 1,n

     do i = 1, n

        if ( p ( i ) == minval ( p ) ) then

           q ( i ) = k

           k = k + 1

           p ( i ) = 100

           exit

        end if

     end do

  end do

  flag = 0

  do i = 1, n

     if ( q ( i ) /= i ) then

        flag = flag + 1

     end if

  end do

  if ( flag > 2 ) then

     write ( unit = *, fmt = '(a2)' ) 'NO'

     stop

  end if

  write ( unit = *, fmt = '(a3)' ) 'YES'

  stop



end program test
