import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    }

} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    }

} Main public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    } main {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    } try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        } {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        } BufferedInputStream in = new BufferedInputStream(System.in) BufferedInputStream in = new BufferedInputStream(System.in) new BufferedInputStream(System.in) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) new PrintWriter(new BufferedOutputStream(System.out)) Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int diff = 0; diff 0 for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
                if (sc.nextInt() != i) diff++;
            } {
                if (sc.nextInt() != i) diff++;
            } if (sc.nextInt() != i) diff++; sc.nextInt() != i sc.nextInt() sc.nextInt sc i diff++ diff System.out.println((diff == 2 || diff == 0) ? "YES" : "NO") System.out.println System.out System System.out (diff == 2 || diff == 0) ? "YES" : "NO" (diff == 2 || diff == 0) diff == 2 diff 2 diff == 0 diff 0 "YES" "NO" String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    }

} Main
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:03-

            int n = sc.nextInt();
            int diff = 0;
            for (int i = 1; i <= n; i++) {
                if (sc.nextInt() != i) diff++;
            }

            System.out.println((diff == 2 || diff == 0) ? "YES" : "NO");
        }
    }

}
