import java.util.*;

public class Main{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
} 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[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
} Main public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		} main {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] X = new int[N]; X new int[N] N int[] Y = new int[N]; Y new int[N] N for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		} {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		} int input = sc.nextInt(); input sc.nextInt() sc.nextInt sc X[i] = input X[i] X i input Y[i] = input Y[i] Y i input Arrays.sort(X) Arrays.sort Arrays X int count = 0; count 0 for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(X[i] != Y[i])count++;
		} {
			if(X[i] != Y[i])count++;
		} if(X[i] != Y[i])count++; X[i] != Y[i] X[i] X i Y[i] Y i count++ count System.out.println((count <= 2)?"YES":"NO") System.out.println System.out System System.out (count <= 2)?"YES":"NO" (count <= 2) count 2 "YES" "NO" String args[] args public class Main{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
} public class Main{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
} Main
import java.util.*;

public class Main{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
}