Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim ps As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim swapPs(0 To n - 1) As Integer
    Array.Copy(ps, 0, swapPs, 0, n)
    Dim output As String = "YES"
    For i As Integer = 0 To n - 1
      If ps(i) <> i + 1 Then
        If ps(ps(i) - 1) = i + 1 Then
          swapPs(i) = i + 1
          swapPs(ps(i) - 1) = ps(i)
          Dim sortPs(0 To n - 1) As Integer
          Array.Copy(ps, 0, sortPs, 0, n)
          Array.Sort(sortPs)
          For k As Integer = 0 To n - 1
            If Not swapPs(i).Equals(sortPs(i)) Then
              output = "NO"
              Exit For
            End If
          Next
        Else
          output = "NO"
        End If
        Exit For
      End If
    Next
    Console.WriteLine(output)
  End Sub
End Class