import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
} import java.io.BufferedReader; BufferedReader java.io import java.io.*; io.* java import java.util.*; util.* java import java.util.ArrayList; ArrayList java.util import java.util.Iterator; Iterator java.util import java.util.List; List java.util import java.util.Collections; Collections java.util import java.util.Arrays; Arrays java.util public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
} Main public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





} main {
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





} final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final List<Integer> list = new ArrayList<>(); list new ArrayList<>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        list.add(sc.nextInt());
    } {
        list.add(sc.nextInt());
    } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc List<Integer> list2= new ArrayList<Integer>(list); list2 new ArrayList<Integer>(list) Collections.sort(list) Collections.sort Collections list for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        if(list.get(i) != list2.get(i)){
            count++;
        }
    } {
        if(list.get(i) != list2.get(i)){
            count++;
        }
    } if(list.get(i) != list2.get(i)){
            count++;
        } list.get(i) != list2.get(i) list.get(i) list.get list i list2.get(i) list2.get list2 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" final String[] args args public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
} public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
} Main
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
}