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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] array = new int[N];
		int[] array_ = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		}
		sc.close();
		Arrays.sort(array_);
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		}
		if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] array = new int[N];
		int[] array_ = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		}
		sc.close();
		Arrays.sort(array_);
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		}
		if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] array = new int[N];
		int[] array_ = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		}
		sc.close();
		Arrays.sort(array_);
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		}
		if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] array = new int[N];
		int[] array_ = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		}
		sc.close();
		Arrays.sort(array_);
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		}
		if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] array = new int[N]; array new int[N] N int[] array_ = new int[N]; array_ new int[N] N for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		} {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		} int current = Integer.parseInt(sc.next()); current Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc array[i] = current array[i] array i current array_[i] = current array_[i] array_ i current sc.close() sc.close sc Arrays.sort(array_) Arrays.sort Arrays array_ int count = 0; count 0 for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (array[i] != array_[i]) {
				count++;
			}
		} {
			if (array[i] != array_[i]) {
				count++;
			}
		} if (array[i] != array_[i]) {
				count++;
			} array[i] != array_[i] array[i] array i array_[i] array_ i {
				count++;
			} count++ count if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		} count > 2 count 2 {
			System.out.println("NO");
		} System.out.println("NO") System.out.println System.out System System.out "NO" {
			System.out.println("YES");
		} System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] array = new int[N];
		int[] array_ = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			array[i] = current;
			array_[i] = current;
		}
		sc.close();
		Arrays.sort(array_);
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (array[i] != array_[i]) {
				count++;
			}
		}
		if (count > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
}