import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
} import java.util.*; util.* java public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
} Main public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    } main {

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Integer N = Integer.parseInt(scan.next()); N Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan ArrayList<Integer> p1 = new ArrayList<Integer>(); p1 new ArrayList<Integer>() ArrayList<Integer> p2 = new ArrayList<Integer>(); p2 new ArrayList<Integer>() for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        } {
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        } int s = Integer.parseInt(scan.next()); s Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan p1.add(s) p1.add p1 s p2.add(s) p2.add p2 s Collections.sort(p2) Collections.sort Collections p2 int counter = 0; counter 0 int c = 0; c 0 boolean r = false; r false for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        } {
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        } if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } p1.get(i) != p2.get(i) p1.get(i) p1.get p1 i p2.get(i) p2.get p2 i {
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } counter++ counter if(counter == 1){
                    c = i;
                } counter == 1 counter 1 {
                    c = i;
                } c = i c i if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                } counter == 2 counter 2 {
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                } int tmp = p1.get(c); tmp p1.get(c) p1.get p1 c p1.remove(c) p1.remove p1 c p1.add(c,p1.get(i-1)) p1.add p1 c p1.get(i-1) p1.get p1 i-1 i 1 p1.remove(i) p1.remove p1 i p1.add(i,tmp) p1.add p1 i tmp for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    } int j=0; int j=0; j 0 j<N j N j++ j++ j {
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    } {
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    } if(p1.get(j) != p2.get(j)) break; p1.get(j) != p2.get(j) p1.get(j) p1.get p1 j p2.get(j) p2.get p2 j break; if(j==N-1){
                            r = true;
                        } j==N-1 j N-1 N 1 {
                            r = true;
                        } r = true r true if(counter==3) break; counter==3 counter 3 break; if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        } counter == 3 counter 3 System.out.println("NO") System.out.println System.out System System.out "NO" {
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        } if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            } r || counter == 0 r counter == 0 counter 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" String args[] args public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
} public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
} Main
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        
        ArrayList<Integer> p1 = new ArrayList<Integer>();
        ArrayList<Integer> p2 = new ArrayList<Integer>();

        for(int i=0;i<N;i++){
            int s = Integer.parseInt(scan.next());
            p1.add(s);
            p2.add(s);
        }

        Collections.sort(p2);

        int counter = 0;
        int c = 0;
        boolean r = false;
        for(int i=0;i<N;i++){
            if(p1.get(i) != p2.get(i)){
                counter++;
                if(counter == 1){
                    c = i;
                }
                if(counter == 2){
                    int tmp = p1.get(c);
                    p1.remove(c);
                    p1.add(c,p1.get(i-1));
                    p1.remove(i);
                    p1.add(i,tmp);
                    for(int j=0;j<N;j++){
                        if(p1.get(j) != p2.get(j)) break;
                        if(j==N-1){
                            r = true;
                        }
                    }
                }

                if(counter==3) break;
            } 
        }

        
        if(counter == 3)
            System.out.println("NO");
        else{
            if(r || counter == 0){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }

        }
    }
}