import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    } main {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int ary[]=new int[N+1]; ary new int[N+1] N+1 N 1 String ans="YES"; ans "YES" int inc = 0; inc 0 for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		} int i=1; int i=1; i 1 i<=N i N i++ i++ i {
			ary[i]=sc.nextInt();
		} {
			ary[i]=sc.nextInt();
		} ary[i]=sc.nextInt() ary[i] ary i sc.nextInt() sc.nextInt sc for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		} int i=1; int i=1; i 1 i<=N i N i++ i++ i {
			if (i!=ary[i]) {
				inc = inc+1;
			}
		} {
			if (i!=ary[i]) {
				inc = inc+1;
			}
		} if (i!=ary[i]) {
				inc = inc+1;
			} i!=ary[i] i ary[i] ary i {
				inc = inc+1;
			} inc = inc+1 inc inc+1 inc 1 if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);} inc==0||inc==2 inc==0 inc 0 inc==2 inc 2 {
			System.out.println(ans);
		} System.out.println(ans) System.out.println System.out System System.out ans {
		ans="NO";
		System.out.println(ans);} ans="NO" ans "NO" System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    }
} public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ary[]=new int[N+1];
		String ans="YES";
		int inc = 0;
		for(int i=1;i<=N;i++){
			ary[i]=sc.nextInt();
		}
		for(int i=1;i<=N;i++){
			if (i!=ary[i]) {
				inc = inc+1;
			}
		}
		if (inc==0||inc==2) {
			System.out.println(ans);
		}
		else{
		ans="NO";
		System.out.println(ans);}
    }
}
