import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] line1 = line.split(" "); line1 line.split(" ") line.split line " " int[] ary = new int[n]; ary new int[n] n for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]); int i = 0; int i = 0; i 0 i < n i n i++ i++ i ary[i] = Integer.parseInt(line1[i]); ary[i] = Integer.parseInt(line1[i]) ary[i] ary i Integer.parseInt(line1[i]) Integer.parseInt Integer line1[i] line1 i int[] ary1 = ary.clone(); ary1 ary.clone() ary.clone ary Arrays.sort(ary1) Arrays.sort Arrays ary1 int count = 0; count 0 for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++; int i = 0; int i = 0; i 0 i < ary.length i ary.length ary ary.length i++ i++ i if(ary[i] != ary1[i])   count++; if(ary[i] != ary1[i])   count++; ary[i] != ary1[i] ary[i] ary i ary1[i] ary1 i count++ count if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO"); count == 2 || count == 0 count == 2 count 2 count == 0 count 0 System.out.println("YES") System.out.println System.out System System.out "YES" 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) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        int[] ary1 = ary.clone();
        Arrays.sort(ary1);
        int count = 0;
        for(int i = 0; i < ary.length; i++) if(ary[i] != ary1[i])   count++;
        if(count == 2 || count == 0)  System.out.println("YES");
        else    System.out.println("NO");
    }
}