import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] p = new int[N]; p new int[N] N for (int i = 0; i < N; i++) p[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i p[i] = sc.nextInt(); p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int[] pSorted = p.clone(); pSorted p.clone() p.clone p Arrays.sort(pSorted) Arrays.sort Arrays pSorted int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            if (p[i] != pSorted[i]) {
                cnt++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (p[i] != pSorted[i]) {
                cnt++;
            }
        } {
            if (p[i] != pSorted[i]) {
                cnt++;
            }
        } if (p[i] != pSorted[i]) {
                cnt++;
            } p[i] != pSorted[i] p[i] p i pSorted[i] pSorted i {
                cnt++;
            } cnt++ cnt System.out.println(cnt > 2 ? "NO" : "YES") System.out.println System.out System System.out cnt > 2 ? "NO" : "YES" cnt > 2 cnt 2 "NO" "YES" String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        int[] pSorted = p.clone();
        Arrays.sort(pSorted);

        int cnt = 0;

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

        System.out.println(cnt > 2 ? "NO" : "YES");
    }
}