import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

} Main public static void main(String[] args) {
        exec();
    } main {
        exec();
    } exec() exec String[] args args static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    } exec {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    } PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = Integer.parseInt(sc.next());

        } {
            a[i] = Integer.parseInt(sc.next());

        } a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int k = 0; k 0 for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (a[i] != i+1) {
                k++;
            }
        } {
            if (a[i] != i+1) {
                k++;
            }
        } if (a[i] != i+1) {
                k++;
            } a[i] != i+1 a[i] a i i+1 i 1 {
                k++;
            } k++ k if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        } k == 0 || k == 2 k == 0 k 0 k == 2 k 2 {
            out.println("YES");
        } out.println("YES") out.println out "YES" {
            out.println("NO");
        } out.println("NO") out.println out "NO" out.flush() out.flush out public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

} public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

}
