
import java.util.*;







// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

public class Main{
    public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
    
    
    
} import java.util.*; util.* java public class Main{
    public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
    
    
    
} Main public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    } main {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] A = new int[n]; A new int[n] n for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            A[i] = scanner.nextInt();
        } {
            A[i] = scanner.nextInt();
        } A[i] = scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner int[] sorted = new int[n]; sorted new int[n] n for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            sorted[i] = i+1;
        } {
            sorted[i] = i+1;
        } sorted[i] = i+1 sorted[i] sorted i i+1 i 1 for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        } {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        } if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            } A[i]!=i+1 A[i] A i i+1 i 1 {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            } int a = A[A[i]-1]; a A[A[i]-1] A A[i]-1 A[i] A i 1 A[A[i]-1] = A[i] A[A[i]-1] A A[i]-1 A[i] A i 1 A[i] A i A[i] = a A[i] A i a break; int flag=0; flag 0 for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        } {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        } if(A[i]!=sorted[i]) {
                flag=1;
                break;
            } A[i]!=sorted[i] A[i] A i sorted[i] sorted i {
                flag=1;
                break;
            } flag=1 flag 1 break; if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        } flag==0 flag 0 {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" {
            System.out.println("NO");
        } System.out.println("NO") System.out.println System.out System System.out "NO" String args[] args public class Main{
    public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
    
    
    
} public class Main{
    public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
    
    
    
} Main

import java.util.*;







// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

public class Main{
    public static void main(String args[] ) throws Exception {
        
        //Scanner
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++) {
            A[i] = scanner.nextInt();
        }
        int[] sorted = new int[n];
        for(int i=0;i<n;i++) {
            sorted[i] = i+1;
        }
        for(int i=0;i<n;i++) {
            if(A[i]!=i+1) {
                int a = A[A[i]-1];
                A[A[i]-1] = A[i];
                A[i] = a;
                break;
            }
        }
        
        
        
        int flag=0;
        for(int i=0;i<n;i++) {
            
            if(A[i]!=sorted[i]) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
    
    
    
}
