import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	}	

}
 import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	}	

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> initialList = new ArrayList(); initialList new ArrayList() for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			initialList.add(sc.nextInt());
		} {
			initialList.add(sc.nextInt());
		} initialList.add(sc.nextInt()) initialList.add initialList sc.nextInt() sc.nextInt sc List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList()); sortedList initialList.stream().sorted().collect(Collectors.toList()) initialList.stream().sorted().collect initialList.stream().sorted() initialList.stream().sorted initialList.stream() initialList.stream initialList Collectors.toList() Collectors.toList Collectors int count = 0; count 0 String message = "YES"; message "YES" for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		} {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		} if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			} initialList.get(i) != sortedList.get(i) initialList.get(i) initialList.get initialList i sortedList.get(i) sortedList.get sortedList i {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			} count++ count if(count > 2) {
					message = "NO";
					break;
				} count > 2 count 2 {
					message = "NO";
					break;
				} message = "NO" message "NO" break; System.out.println(message) System.out.println System.out System System.out message String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	}	

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	}	

} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> initialList = new ArrayList();
		for(int i = 0; i < n; i++) {
			initialList.add(sc.nextInt());
		}
		
		List<Integer> sortedList = initialList.stream().sorted().collect(Collectors.toList());
		
		int count = 0;
		String message = "YES";
		for(int i = 0; i < n; i++) {
			if(initialList.get(i) != sortedList.get(i)) {
				count++;
				if(count > 2) {
					message = "NO";
					break;
				}
			}
		}
		System.out.println(message);
		

		
		

		
		
	}	

}

