
import java.util.ArrayList;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
} import java.util.ArrayList; ArrayList java.util 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();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==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();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==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 ArrayList<Integer> ary = new ArrayList<>(); ary new ArrayList<>() for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            ary.add(scanner.nextInt());
        } {
            ary.add(scanner.nextInt());
        } ary.add(scanner.nextInt()) ary.add ary scanner.nextInt() scanner.nextInt scanner int cnt = 0; cnt 0 for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        } int idx=0; int idx=0; idx 0 idx<N idx N idx++ idx++ idx {
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        } {
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        } if(idx+1!=ary.get(idx)){
                cnt++;
            } idx+1!=ary.get(idx) idx+1 idx 1 ary.get(idx) ary.get ary idx {
                cnt++;
            } cnt++ cnt if(cnt==0|cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        } cnt==0|cnt==2 cnt==0 cnt 0 cnt==2 cnt 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();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==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();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
} Main

import java.util.ArrayList;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for (int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        int cnt = 0;
        for(int idx=0; idx<N; idx++){
            if(idx+1!=ary.get(idx)){
                cnt++;
            }
        }
        if(cnt==0|cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}