import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		String result = "YES";
		int count = 0;
		int tmp1 = 0;
		int tmp2 = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		}
		if (count > 2) {
			result = "NO";
		}
		if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		}
		System.out.println(result);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		String result = "YES";
		int count = 0;
		int tmp1 = 0;
		int tmp2 = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		}
		if (count > 2) {
			result = "NO";
		}
		if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		}
		System.out.println(result);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		String result = "YES";
		int count = 0;
		int tmp1 = 0;
		int tmp2 = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		}
		if (count > 2) {
			result = "NO";
		}
		if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		}
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		String result = "YES";
		int count = 0;
		int tmp1 = 0;
		int tmp2 = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		}
		if (count > 2) {
			result = "NO";
		}
		if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		}
		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[] p = new int[n]; p new int[n] n String result = "YES"; result "YES" int count = 0; count 0 int tmp1 = 0; tmp1 0 int tmp2 = 0; tmp2 0 for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.nextInt();
		} {
			p[i] = sc.nextInt();
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		} {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		} if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			} p[i] != i + 1 p[i] p i i + 1 i 1 {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			} count++ count if (count == 1) {
					tmp1 = i;
				} count == 1 count 1 {
					tmp1 = i;
				} tmp1 = i tmp1 i if (count == 2) {
					tmp2 = i;
				} count == 2 count 2 {
					tmp2 = i;
				} tmp2 = i tmp2 i if (count > 2) {
			result = "NO";
		} count > 2 count 2 {
			result = "NO";
		} result = "NO" result "NO" if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		} count == 2 count 2 {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		} int tmp = p[tmp1]; tmp p[tmp1] p tmp1 p[tmp1] = p[tmp2] p[tmp1] p tmp1 p[tmp2] p tmp2 p[tmp2] = tmp p[tmp2] p tmp2 tmp for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (p[i] != i + 1) {
				result = "NO";
			}
		} {
			if (p[i] != i + 1) {
				result = "NO";
			}
		} if (p[i] != i + 1) {
				result = "NO";
			} p[i] != i + 1 p[i] p i i + 1 i 1 {
				result = "NO";
			} result = "NO" result "NO" System.out.println(result) System.out.println System.out System System.out result String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		String result = "YES";
		int count = 0;
		int tmp1 = 0;
		int tmp2 = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				count++;
				if (count == 1) {
					tmp1 = i;
				}
				if (count == 2) {
					tmp2 = i;
				}
			}
		}
		if (count > 2) {
			result = "NO";
		}
		if (count == 2) {
			int tmp = p[tmp1];
			p[tmp1] = p[tmp2];
			p[tmp2] = tmp;
		}
		for (int i = 0; i < n; i++) {
			if (p[i] != i + 1) {
				result = "NO";
			}
		}
		System.out.println(result);
	}
}