import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

}
 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];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    } 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 for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = sc.nextInt();
        } {
            p[i] = sc.nextInt();
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int key = 0; key 0 int value = 0; value 0 for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        } {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        } if (p[i] == i + 1) {
                continue;
            } p[i] == i + 1 p[i] p i i + 1 i 1 {
                continue;
            } continue; if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            } key == 0 key 0 {
                key = i + 1;
                value = p[i];
                continue;
            } key = i + 1 key i + 1 i 1 value = p[i] value p[i] p i continue; if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            } key != p[i] || value != i + 1 key != p[i] key p[i] p i value != i + 1 value i + 1 i 1 {
                System.out.println("NO");
                return;
            } System.out.println("NO") System.out.println System.out System System.out "NO" return; System.out.println("YES") System.out.println System.out System System.out "YES" 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];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int key = 0;
        int value = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            if (key == 0) {
                key = i + 1;
                value = p[i];
                continue;
            }
            if (key != p[i] || value != i + 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

}

