// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    }
} import java.math.BigDecimal; BigDecimal java.math import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Objects; Objects java.util import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner java.util import java.util.stream.Stream; Stream java.util.stream public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    }
} Main public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    } main {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    } 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 int[] P2 = new int[N]; P2 new int[N] N for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        } {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        } int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc P[i] = tmp P[i] P i tmp P2[i] = tmp P2[i] P2 i tmp Arrays.sort(P2) Arrays.sort Arrays P2 int cnt = 0; cnt 0 for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        } int i = 0; int i = 0; i 0 i < P2.length i P2.length P2 P2.length i++ i++ i {
            if (P[i] != P2[i]) cnt++;
        } {
            if (P[i] != P2[i]) cnt++;
        } if (P[i] != P2[i]) cnt++; P[i] != P2[i] P[i] P i P2[i] P2 i cnt++ cnt System.out.println(cnt <= 2 ? "YES" : "NO") System.out.println System.out System System.out cnt <= 2 ? "YES" : "NO" cnt <= 2 cnt 2 "YES" "NO" final String[] args args public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    }
} public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


        System.out.println(cnt <= 2 ? "YES" : "NO");
    }
} Main
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int N = sc.nextInt();

        int[] P = new int[N];
        int[] P2 = new int[N];

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            P[i] = tmp;
            P2[i] = tmp;
        }

        Arrays.sort(P2);

        int cnt = 0;
        for (int i = 0; i < P2.length; i++) {
            if (P[i] != P2[i]) cnt++;
        }


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