import java.math.BigDecimal;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }


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


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }


} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc String pStr = sc.nextLine(); pStr sc.nextLine() sc.nextLine sc int[] p = new int[n]; p new int[n] n int[] temp = new int[n]; temp new int[n] n for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        } {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        } p[i] = Integer.parseInt(pStr.split(" ")[i]) p[i] p i Integer.parseInt(pStr.split(" ")[i]) Integer.parseInt Integer pStr.split(" ")[i] pStr.split(" ") pStr.split pStr " " i temp[i]  = Integer.parseInt(pStr.split(" ")[i]) temp[i] temp i Integer.parseInt(pStr.split(" ")[i]) Integer.parseInt Integer pStr.split(" ")[i] pStr.split(" ") pStr.split pStr " " i Arrays.sort(temp) Arrays.sort Arrays temp boolean sorted = true; sorted true int before before after; after before = after  = 0 before after  = 0 after 0 for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        } {
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        } if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            } p[i] != temp[i] p[i] p i temp[i] temp i {
                sorted  = false;
                before = i;
                break;
            } sorted  = false sorted false before = i before i break; if(sorted){
            System.out.println("YES");
            return;
        } sorted {
            System.out.println("YES");
            return;
        } System.out.println("YES") System.out.println System.out System System.out "YES" return; for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        } int i = n - 1; int i = n - 1; i n - 1 n 1 i >= 0 i 0 i-- i-- i {
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        } {
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        } if(p[i] != temp[i]){
                after = i;
                break;
            } p[i] != temp[i] p[i] p i temp[i] temp i {
                after = i;
                break;
            } after = i after i break; if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        } p[before] == temp[after] && p[after] == temp[before] p[before] == temp[after] p[before] p before temp[after] temp after p[after] == temp[before] p[after] p after temp[before] temp before {
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        } int t; t t = p[after] t p[after] p after p[after] = p[before] p[after] p after p[before] p before p[before] = t p[before] p before t sorted = true sorted true for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        } {
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        } if(p[i] != temp[i]){
                sorted  = false;
                break;
            } p[i] != temp[i] p[i] p i temp[i] temp i {
                sorted  = false;
                break;
            } sorted  = false sorted false break; if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        } 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 class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }


} public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }


} Main
import java.math.BigDecimal;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String pStr = sc.nextLine();

        int[] p = new int[n];
        int[] temp = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(pStr.split(" ")[i]);
            temp[i]  = Integer.parseInt(pStr.split(" ")[i]);
        }

        Arrays.sort(temp);

        boolean sorted = true;
        int before, after;
        before = after  = 0;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                before = i;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
            return;
        }



        for(int i = n - 1; i >= 0; i--){
            if(p[i] != temp[i]){
                after = i;
                break;
            }
        }

        if(p[before] == temp[after] && p[after] == temp[before]){
            int t;
            t = p[after];
            p[after] = p[before];
            p[before] = t;
        }

        sorted = true;
        for(int i = 0;i < n; i++){
            if(p[i] != temp[i]){
                sorted  = false;
                break;
            }
        }
        if(sorted){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }


}
