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 count As Integer = 0
    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
          count += 1
        Else
          output = "NO"
          Exit For
        End If
      End If
    Next
    If count <> 0 AndAlso count <> 2 Then output = "NO"
    Console.WriteLine(output)
  End Sub
End Class