import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

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

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

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

} Main public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

            if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    } main {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

            if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    } try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

            if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

            if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader String[] array = reader.readLine().split(" "); array reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int diff = 0; diff 0 for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            } {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            } int p = Integer.parseInt(array[i]); p Integer.parseInt(array[i]) Integer.parseInt Integer array[i] array i if (p != (i + 1)) {
                    diff++;
                } p != (i + 1) p (i + 1) i 1 {
                    diff++;
                } diff++ diff if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            } diff <= 2 diff 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) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

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

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

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

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

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

}
