import java.awt.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

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

}
 import java.awt.*; awt.* java import java.util.Arrays; Arrays java.util import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

        if(invCount<=2) 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=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

        if(invCount<=2) System.out.println("YES");
        else System.out.println("NO");
    } main {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

        if(invCount<=2) 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 int[] a=new int[n]; a new int[n] n for(int i=0;i<n;i++)a[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int[] b=a.clone(); b a.clone() a.clone a Arrays.sort(b) Arrays.sort Arrays b for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            a[i]=a[i]-b[i];
        } {
            a[i]=a[i]-b[i];
        } a[i]=a[i]-b[i] a[i] a i a[i]-b[i] a[i] a i b[i] b i int invCount=0; invCount 0 for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(a[i]!=0)invCount++;
        } {
            if(a[i]!=0)invCount++;
        } if(a[i]!=0)invCount++; a[i]!=0 a[i] a i 0 invCount++ invCount if(invCount<=2) System.out.println("YES");
        else System.out.println("NO"); invCount<=2 invCount 2 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=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

        if(invCount<=2) 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=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

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

} Main
import java.awt.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

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

}

