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

public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

} Main static int nums[] nums copys[] ; copys public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	} main {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	} Scanner in = new Scanner (System.in) ; in new Scanner (System.in) int N = in.nextInt() ; N in.nextInt() in.nextInt in nums = new int [N] nums new int [N] N copys = new int [N] copys new int [N] N for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		} {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		} nums[i] = in.nextInt() nums[i] nums i in.nextInt() in.nextInt in copys[i] = nums[i] copys[i] copys i nums[i] nums i Arrays.sort(copys) Arrays.sort Arrays copys int cnt = 0 ; cnt 0 for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(copys[i]!=nums[i])
				cnt++ ;
		} {
			if(copys[i]!=nums[i])
				cnt++ ;
		} if(copys[i]!=nums[i])
				cnt++ ; copys[i]!=nums[i] copys[i] copys i nums[i] nums i cnt++ cnt if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		} cnt>2 cnt 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" in.close() in.close in String[] args args public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

} public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

}
