import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan List<Integer> list = new ArrayList(); list new ArrayList() for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			list.add(scan.nextInt());
		} {
			list.add(scan.nextInt());
		} list.add(scan.nextInt()) list.add list scan.nextInt() scan.nextInt scan List<Integer> sorted = new ArrayList(list); sorted new ArrayList(list) Collections.sort(sorted) Collections.sort Collections sorted if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} list.equals(sorted) || isChangeable(list, sorted) list.equals(sorted) list.equals list sorted isChangeable(list, sorted) isChangeable list sorted {
			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 static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	} isChangeable {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	} boolean isChangeable = false; isChangeable false int notEqualCount = 0; notEqualCount 0 List<Integer> indexList = new ArrayList(); indexList new ArrayList() for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		} int i=0; int i=0; i 0 i<list.size() i list.size() list.size list i++ i++ i {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		} {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		} if (list.get(i) == sorted.get(i)) continue; list.get(i) == sorted.get(i) list.get(i) list.get list i sorted.get(i) sorted.get sorted i continue; if (notEqualCount > 3) break; notEqualCount > 3 notEqualCount 3 break; indexList.add(i) indexList.add indexList i notEqualCount++ notEqualCount if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		} indexList.size() == 2 indexList.size() indexList.size indexList 2 {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		} int tmp = (Integer) list.get(indexList.get(0)); tmp (Integer) list.get(indexList.get(0)) list.get list indexList.get(0) indexList.get indexList 0 list.set(indexList.get(0), list.get(indexList.get(1))) list.set list indexList.get(0) indexList.get indexList 0 list.get(indexList.get(1)) list.get list indexList.get(1) indexList.get indexList 1 list.set(indexList.get(1), tmp) list.set list indexList.get(1) indexList.get indexList 1 tmp if (list.equals(sorted)) {
				isChangeable = true;
			} list.equals(sorted) list.equals list sorted {
				isChangeable = true;
			} isChangeable = true isChangeable true return isChangeable; isChangeable List list list List sorted sorted public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
} Main
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
}