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.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 2) {
	        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.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 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 = Integer.parseInt(sc.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 2) {
	        System.out.println("YES");
	    } else {
	        System.out.println("NO");
	    }
    } main {
        Scanner sc = new Scanner(System.in);
	    int n = Integer.parseInt(sc.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 2) {
	        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.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	        array[i] = Integer.parseInt(sc.next());
	    } {
	        array[i] = Integer.parseInt(sc.next());
	    } array[i] = Integer.parseInt(sc.next()) array[i] array i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt = 0; cnt 0 for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    } {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    } if (array[i] != i + 1) {
	            cnt++;
	        } array[i] != i + 1 array[i] array i i + 1 i 1 {
	            cnt++;
	        } cnt++ cnt if (cnt == 0 || cnt == 2) {
	        System.out.println("YES");
	    } else {
	        System.out.println("NO");
	    } cnt == 0 || cnt == 2 cnt == 0 cnt 0 cnt == 2 cnt 2 {
	        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) throws Exception {
        Scanner sc = new Scanner(System.in);
	    int n = Integer.parseInt(sc.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 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 = Integer.parseInt(sc.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 2) {
	        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.next());
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	        array[i] = Integer.parseInt(sc.next());
	    }
	    int cnt = 0;
	    for (int i = 0; i < n; i++) {
	        if (array[i] != i + 1) {
	            cnt++;
	        }
	    }
	    if (cnt == 0 || cnt == 2) {
	        System.out.println("YES");
	    } else {
	        System.out.println("NO");
	    }
    }
}
