program test
  implicit none
  integer :: n, i, flag, tmp
  integer, dimension ( : ), allocatable :: p
  
  read ( unit = *, fmt = * ) n

  allocate ( p ( 1:n ) )

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

  do i = 1, n

     if ( p ( i ) == i ) then

        continue
     
     else if ( p ( i ) /= i .and. p ( p ( i ) ) == i ) then

        tmp = p ( i )

        p ( i ) = p ( p ( i ) )

        p ( tmp ) = tmp

        flag = flag + 1

     else

        write ( unit = *, fmt = '(a2)' ) 'NO'
        
        stop
        
     end if

     if ( flag > 1 ) then

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

        stop

     else

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

        stop

     end if

  end do
  
end program test
