
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            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) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] p = new int[N + 1]; p new int[N + 1] N + 1 N 1 for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        } int i = 1 ; int i = 1 ; i 1 i <= N i N i++ i++ i {
            p[i] = scanner.nextInt();
        } {
            p[i] = scanner.nextInt();
        } p[i] = scanner.nextInt() p[i] p i scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 for (int i = 1 ; i <= N ; i++) {
            if (i != p[i]) count++;
        } int i = 1 ; int i = 1 ; i 1 i <= N i N i++ i++ i {
            if (i != p[i]) count++;
        } {
            if (i != p[i]) count++;
        } if (i != p[i]) count++; i != p[i] i p[i] p i count++ count if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        } count <= 2 count 2 {
            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) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
} Main

import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

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

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}
