import java.util.Scanner;

public class Main {

    public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} Main public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    } main { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

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

    public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} public class Main {

    public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) { // 33m30s AC

        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        String[] pn = sc.nextLine().split(" ");

        int badPlaceCount = 0;
        for (int i = 0; i < N; i++) {
            if (Integer.parseInt(pn[i]) != i + 1) {
                badPlaceCount++;
            }
        }

        if (badPlaceCount == 2 || badPlaceCount == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}
