import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	}
	
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	}
	
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    a[i] = sc.nextInt();
		} {
		    a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc String result = "NO"; result "NO" int[] b = Arrays.copyOf(a, n); b Arrays.copyOf(a, n) Arrays.copyOf Arrays a n Arrays.sort(b) Arrays.sort Arrays b int cnt = 0; cnt 0 for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    if(a[i] != b[i]) cnt++;
		} {
		    if(a[i] != b[i]) cnt++;
		} if(a[i] != b[i]) cnt++; a[i] != b[i] a[i] a i b[i] b i cnt++ cnt if(cnt == 0 || cnt == 2) result = "YES"; cnt == 0 || cnt == 2 cnt == 0 cnt 0 cnt == 2 cnt 2 result = "YES" result "YES" System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	}
	
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	}
	
} Main
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		String result = "NO";
		int[] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		//System.out.println(Arrays.toString(b));
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] != b[i]) cnt++;
		}
		if(cnt == 0 || cnt == 2) result = "YES";
		// 出力
		System.out.println(result);
	}
	
}
