import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] p = new int[n] p new int[n] n index = new int[3]; index new int[3] 3 int i = 0 i 0 j = 0 j 0 flag = 0; flag 0 while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        } i<n i n {
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            } flag<=2&&p[i]!=i+1 flag<=2 flag 2 p[i]!=i+1 p[i] p i i+1 i 1 {
                flag++;
                index[j] = i;
                j++;
            } flag++ flag index[j] = i index[j] index j i j++ j i++ i if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        } flag==0 flag 0 System.out.println("YES") System.out.println System.out System System.out "YES" if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        } flag>2 flag 2 System.out.println("NO") System.out.println System.out System System.out "NO" {
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        } if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO"); p[index[0]]==index[1]+1 p[index[0]] p index[0] index 0 index[1]+1 index[1] index 1 1 System.out.println("YES") System.out.println System.out System System.out "YES" 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){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	}
} public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        int[] p = new int[n], index = new int[3];
        int i = 0, j = 0, flag = 0;
        while(i<n){
            p[i] = scan.nextInt();
            if(flag<=2&&p[i]!=i+1){
                flag++;
                index[j] = i;
                j++;
            }
            i++;
        }
        if(flag==0)
            System.out.println("YES");
        else if(flag>2)
            System.out.println("NO");
        else{
            if(p[index[0]]==index[1]+1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
	}
}