import java.util.Arrays;
import java.util.Scanner;

/**
 * B - 0 or 1 Swap
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    } main {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    } Scanner sc = new Scanner( System.in ); sc new Scanner( System.in ) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n int[] q = new int[n]; q new int[n] n int replaceCnt = 0; replaceCnt 0 String result = "YES"; result "YES" for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = sc.nextInt();
            q[i] = p[i];
        } {
            p[i] = sc.nextInt();
            q[i] = p[i];
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc q[i] = p[i] q[i] q i p[i] p i Arrays.sort( q ) Arrays.sort Arrays q for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        } {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        } if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            } p[i] != q[i] p[i] p i q[i] q i {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            } replaceCnt++ replaceCnt if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                } replaceCnt > 2 replaceCnt 2 {
                    result = "NO";
                    break;
                } result = "NO" result "NO" break; System.out.println( result ) System.out.println System.out System System.out result sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

/**
 * B - 0 or 1 Swap
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
}