import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} main {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); reader new InputStreamReader(System.in, StandardCharsets.UTF_8) BufferedReader in = new BufferedReader(reader); in new BufferedReader(reader) int N = Integer.parseInt(in.readLine()); N Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in String[] tokens = in.readLine().split(" "); tokens in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int[] p = new int[N]; p new int[N] N int[] q = new int[N]; q new int[N] N for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		} int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		} {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		} p[i] = Integer.parseInt(tokens[i]) p[i] p i Integer.parseInt(tokens[i]) Integer.parseInt Integer tokens[i] tokens i q[i] = p[i] q[i] q i p[i] p i Arrays.sort(q) Arrays.sort Arrays q int count = 0; count 0 for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		} int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
			if(p[i] != q[i]) {
				++count;
			}
		} {
			if(p[i] != q[i]) {
				++count;
			}
		} if(p[i] != q[i]) {
				++count;
			} p[i] != q[i] p[i] p i q[i] q i {
				++count;
			} ++count count if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} count <= 2 count 2 {
			System.out.println("YES");
		} System.out.println("YES") System.out.println System.out System System.out "YES" {
			System.out.println("NO");
		} System.out.println("NO") System.out.println System.out System System.out "NO" String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] p = new int[N];
		int[] q = new int[N];
		for (int i = 0; i < N; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
			q[i] = p[i];
		}
		Arrays.sort(q);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if(p[i] != q[i]) {
				++count;
			}
		}
		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}