import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

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

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    }
    
} Main public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    } main {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc ArrayList<Integer> list_l = new ArrayList<Integer>(); list_l new ArrayList<Integer>() for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		} int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
			list_l.add(sc.nextInt());
			
		} {
			list_l.add(sc.nextInt());
			
		} list_l.add(sc.nextInt()) list_l.add list_l sc.nextInt() sc.nextInt sc ArrayList<Integer> list_b = new ArrayList<Integer>(); list_b new ArrayList<Integer>() list_b = (ArrayList<Integer>) list_l.clone() list_b (ArrayList<Integer>) list_l.clone() list_l.clone list_l Collections.sort(list_l) Collections.sort Collections list_l int cnt = 0; cnt 0 for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		} int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		} {
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		} if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			} list_l.get(i)!=list_b.get(i) list_l.get(i) list_l.get list_l i list_b.get(i) list_b.get list_b i {
				cnt ++;
			} cnt ++ cnt if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		} cnt == 2 | cnt == 0 cnt == 2 cnt 2 cnt == 0 cnt 0 {
			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" sc.close() sc.close sc return ; String[] args args public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    }
    
} public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    }
    
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_l = new ArrayList<Integer>();


		for(int i = 0 ;i < N;i++){
			list_l.add(sc.nextInt());
			
		}

		ArrayList<Integer> list_b = new ArrayList<Integer>();
		list_b = (ArrayList<Integer>) list_l.clone();
		//ソート
		Collections.sort(list_l);

		int cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_l.get(i)!=list_b.get(i)) {
				cnt ++;
			}
		}

		if(cnt == 2 | cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

   		sc.close();
        return ;

    }
    
}

