import java.util.Scanner;

public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
} Main public static int N = 0; N 0 public static int[] p; p public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    } main {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    } String[] pStrArray; pStrArray Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc pStrArray = sc.nextLine().split(" ") pStrArray sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " p = new int[N] p new int[N] N for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            p[i] = Integer.parseInt(pStrArray[i]);
        } {
            p[i] = Integer.parseInt(pStrArray[i]);
        } p[i] = Integer.parseInt(pStrArray[i]) p[i] p i Integer.parseInt(pStrArray[i]) Integer.parseInt Integer pStrArray[i] pStrArray i int compareCount = 0; compareCount 0 for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (p[i] != i+1) {
                compareCount++;
            }
        } {
            if (p[i] != i+1) {
                compareCount++;
            }
        } if (p[i] != i+1) {
                compareCount++;
            } p[i] != i+1 p[i] p i i+1 i 1 {
                compareCount++;
            } compareCount++ compareCount String output = ""; output "" for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        } {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        } if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            } compareCount == 0 || compareCount == 2 compareCount == 0 compareCount 0 compareCount == 2 compareCount 2 {
                output = "YES";
            } output = "YES" output "YES" {
                output = "NO";
            } output = "NO" output "NO" System.out.println(output) System.out.println System.out System System.out output String[] args args public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
} public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
} Main
import java.util.Scanner;

public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
}
