import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	}
} Main public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	} main {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	} int ans = 0; ans 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc boolean f = true; f true int[] array = new int[n]; array new int[n] n int[] array2 = new int[n]; array2 new int[n] n for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		} {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc if(array[i] != i+1) {
				f=false;
			} array[i] != i+1 array[i] array i i+1 i 1 {
				f=false;
			} f=false f false if(f) {
			System.out.println("YES");
			sc.close();
			return;
		} f {
			System.out.println("YES");
			sc.close();
			return;
		} System.out.println("YES") System.out.println System.out System System.out "YES" sc.close() sc.close sc return; f= true f true for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		} {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		} for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			} int j=0; int j=0; j 0 j<n j n j++ j++ j {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			} {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			} f = true f true System.arraycopy(array,0,array2,0,n) System.arraycopy System array 0 array2 0 n array2[j] = array[i] array2[j] array2 j array[i] array i array2[i] = array[j] array2[i] array2 i array[j] array j for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				} int k= 0; int k= 0; k 0 k<n k n k++ k++ k {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				} {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				} if(array2[k] != k+1) {
						f = false;
						break;
					} array2[k] != k+1 array2[k] array2 k k+1 k 1 {
						f = false;
						break;
					} f = false f false break; if(f) {
				System.out.println("YES");
				sc.close();
				return;
				} f {
				System.out.println("YES");
				sc.close();
				return;
				} System.out.println("YES") System.out.println System.out System System.out "YES" sc.close() sc.close sc return; System.out.println("NO") System.out.println System.out System System.out "NO" sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	}
} public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
//		int d = sc.nextInt();
//
		boolean f = true;
		int[] array = new int[n];
		int[] array2 = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			if(array[i] != i+1) {
				f=false;
			}
		}

		if(f) {
			System.out.println("YES");
			sc.close();
			return;
		}
		f= true;

		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				f = true;
				System.arraycopy(array,0,array2,0,n);
				array2[j] = array[i];
				array2[i] = array[j];
				for(int k= 0;k<n;k++) {
					if(array2[k] != k+1) {
						f = false;
						break;
					}
				}
				if(f) {
				System.out.println("YES");
				sc.close();
				return;
				}

			}
		}
		System.out.println("NO");

		sc.close();
	}
}