import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

} import java.util.ArrayList; ArrayList java.util import java.util.Comparator; Comparator java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

} Main public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    } run {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            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 List<Integer> p = new ArrayList<>(); p new ArrayList<>() for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            p.add(i, scanner.nextInt());
        } {
            p.add(i, scanner.nextInt());
        } p.add(i, scanner.nextInt()) p.add p i scanner.nextInt() scanner.nextInt scanner List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList()); q p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList()) p.stream().sorted(Comparator.naturalOrder()).collect p.stream().sorted(Comparator.naturalOrder()) p.stream().sorted p.stream() p.stream p Comparator.naturalOrder() Comparator.naturalOrder Comparator Collectors.toList() Collectors.toList Collectors int count = 0; count 0 for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(p.get(i) != q.get(i)){
                count++;
            }
        } {
            if(p.get(i) != q.get(i)){
                count++;
            }
        } if(p.get(i) != q.get(i)){
                count++;
            } p.get(i) != q.get(i) p.get(i) p.get p i q.get(i) q.get q i {
                count++;
            } count++ count if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        } count == 2 || count == 0 count == 2 count 2 count == 0 count 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" public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

} public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

} Main
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(i, scanner.nextInt());
        }
        List<Integer> q = p.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        int count = 0;
        for (int i = 0; i < N; i++) {
            if(p.get(i) != q.get(i)){
                count++;
            }
        }
        if(count == 2 || count == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

}