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 sortPs As Integer() = ps
    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
          Array.Sort(sortPs)
          If sortPs IsNot ps Then output = "NO"
        Else
          output = "NO"
        End If
        Exit For
      End If
    Next
    Console.WriteLine(output)
  End Sub
End Class