import 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
    }
    public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } 
} import java.util.*; util.* java 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
    }
    public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } 
} 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            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 sc.close() sc.close sc if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        } Swap0or1(N, p, 1, 0) Swap0or1 N p 1 0 {
            System.out.println("NO");
        } System.out.println("NO") System.out.println System.out System System.out "NO" {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } Swap0or1 {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } if (index > N) {
            return false;
        } index > N index N {
            return false;
        } return false; false if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        } p[index-1] != index p[index-1] p index-1 index 1 index {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        } if (p[p[index-1]-1] != index || times == 1) {
                return true;
            } p[p[index-1]-1] != index || times == 1 p[p[index-1]-1] != index p[p[index-1]-1] p p[index-1]-1 p[index-1] p index-1 index 1 1 index times == 1 times 1 {
                return true;
            } return true; true p[p[index-1]-1] = p[index-1] p[p[index-1]-1] p p[index-1]-1 p[index-1] p index-1 index 1 1 p[index-1] p index-1 index 1 p[index-1] = index p[index-1] p index-1 index 1 index return Swap0or1(N, p, index + 1, times + 1); Swap0or1(N, p, index + 1, times + 1) Swap0or1 N p index + 1 index 1 times + 1 times 1 return Swap0or1(N, p, index + 1, times); Swap0or1(N, p, index + 1, times) Swap0or1 N p index + 1 index 1 times int N N int[] p p int index index int times times 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
    }
    public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } 
} 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
    }
    public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } 
} Main
import 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();
        }
        sc.close();

        if (Swap0or1(N, p, 1, 0)) {
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
    }
    public static boolean Swap0or1(int N, int[] p, int index, int times) {
        if (index > N) {
            return false;
        }
        if (p[index-1] != index) {
            if (p[p[index-1]-1] != index || times == 1) {
                return true;
            }
            p[p[index-1]-1] = p[index-1];
            p[index-1] = index;
            return Swap0or1(N, p, index + 1, times + 1);
        }
        return Swap0or1(N, p, index + 1, times);
    } 
}
