import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int arr[] = new int[n]; arr new int[n] n int max = Integer.MIN_VALUE max Integer.MIN_VALUE Integer Integer.MIN_VALUE maxId = 0 maxId 0 min = Integer.MAX_VALUE min Integer.MAX_VALUE Integer Integer.MAX_VALUE minId = 0; minId 0 for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		} {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		} arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in if (arr[i] < min) {
				min = arr[i];
				minId = i;
			} arr[i] < min arr[i] arr i min {
				min = arr[i];
				minId = i;
			} min = arr[i] min arr[i] arr i minId = i minId i if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			} arr[i] > max arr[i] arr i max {
				max = arr[i];
				maxId = i;
			} max = arr[i] max arr[i] arr i maxId = i maxId i boolean f = false f false m = false; m false if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		} minId == 0 && maxId == n - 1 minId == 0 minId 0 maxId == n - 1 maxId n - 1 n 1 {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			} {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			} for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				} int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				} {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				} m = false m false if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					} arr[i] > arr[j] arr[i] arr i arr[j] arr j {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					} int t = arr[i]; t arr[i] arr i arr[i] = arr[j] arr[i] arr i arr[j] arr j arr[j] = t arr[j] arr j t m = true m true f = check(arr) f check(arr) check arr if (f)
						break; f break; if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					} m {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					} int t = arr[i]; t arr[i] arr i arr[i] = arr[j] arr[i] arr i arr[j] arr j arr[j] = t arr[j] arr j t if (f)
					break; f break; if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		} min != 0 && maxId == n - 1 min != 0 min 0 maxId == n - 1 maxId n - 1 n 1 {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} int t = arr[minId]; t arr[minId] arr minId arr[minId] = arr[0] arr[minId] arr minId arr[0] arr 0 arr[0] = t arr[0] arr 0 t f = check(arr) f check(arr) check arr if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		} minId == 0 && maxId != n - 1 minId == 0 minId 0 maxId != n - 1 maxId n - 1 n 1 {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} int t = arr[maxId]; t arr[maxId] arr maxId arr[maxId] = arr[n - 1] arr[maxId] arr maxId arr[n - 1] arr n - 1 n 1 arr[n - 1] = t arr[n - 1] arr n - 1 n 1 t f = check(arr) f check(arr) check arr {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		} int t = arr[maxId]; t arr[maxId] arr maxId arr[maxId] = arr[minId] arr[maxId] arr maxId arr[minId] arr minId arr[minId] = t arr[minId] arr minId t f = check(arr) f check(arr) check arr if (f)
			System.out.println("YES");
		else
			System.out.println("NO"); f System.out.println("YES") System.out.println System.out System System.out "YES" System.out.println("NO") System.out.println System.out System System.out "NO" in.close() in.close in String[] args args public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	} check {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	} int n = arr.length; n arr.length arr arr.length int order[] = new int[n]; order new int[n] n for (int i = 0; i < n; i++)
			order[i] = arr[i]; int i = 0; int i = 0; i 0 i < n i n i++ i++ i order[i] = arr[i]; order[i] = arr[i] order[i] order i arr[i] arr i Arrays.sort(order) Arrays.sort Arrays order for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (arr[i] != order[i])
				return false;
		} {
			if (arr[i] != order[i])
				return false;
		} if (arr[i] != order[i])
				return false; arr[i] != order[i] arr[i] arr i order[i] order i return false; false return true; true int arr[] arr public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
}
