import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    }
} import java.io.*; io.* java import java.util.*; util.* java import java.util.stream.*; stream.* java.util public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    }
} Main public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) public static final PrintStream out = System.out; out System.out System System.out public static final PrintStream err = System.err; err System.err System System.err public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    } main {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    } int N = in.nextInt(); N in.nextInt() in.nextInt in int[] P = new int[N]; P new int[N] N for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            P[i] = in.nextInt();
        } {
            P[i] = in.nextInt();
        } P[i] = in.nextInt() P[i] P i in.nextInt() in.nextInt in int err = 0; err 0 for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (P[i] != i + 1) {
                err++;
            }
        } {
            if (P[i] != i + 1) {
                err++;
            }
        } if (P[i] != i + 1) {
                err++;
            } P[i] != i + 1 P[i] P i i + 1 i 1 {
                err++;
            } err++ err out.println(err == 0 || err == 2 ? "YES" : "NO") out.println out err == 0 || err == 2 ? "YES" : "NO" err == 0 || err == 2 err == 0 err 0 err == 2 err 2 "YES" "NO" String[] args args public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    }
} public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    }
} Main
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = in.nextInt();
        }
        
        int err = 0;
        for (int i = 0; i < N; i++) {
            if (P[i] != i + 1) {
                err++;
            }
        }

        out.println(err == 0 || err == 2 ? "YES" : "NO");
    }
}
