#include <iostream>
#include <vector>
#include <functional>
#include <sys/signal.h>
#include <sys/time.h>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
void handler(int) {
    cout << "No" << endl;
    exit(EXIT_SUCCESS);
}
int main() {
    // timer
    signal(SIGALRM, handler);
    itimerval tv;
    tv.it_value.tv_sec = 4;
    tv.it_value.tv_usec = 800 * 1000;
    tv.it_interval = {};
    setitimer(ITIMER_REAL, &tv, NULL);
    // solve
    int n; cin >> n;
    vector<int> f(n); repeat (i,n) { cin >> f[i]; -- f[i]; }
    vector<int> g(n, -1);
    vector<bool> used(n);
    function<bool (int)> go = [&](int i) {
        if (i == n) return true;
        if (g[i] == -1) {
            repeat (j,n) if (not used[j]) {
                used[j] = true;
                g[i] = j;
                if (go(i)) return true;
                g[i] = -1;
                used[j] = false;
            }
        } else {
            if (g[g[i]] == -1) {
                if (not used[f[i]]) {
                    used[f[i]] = true;
                    g[g[i]] = f[i];
                    if (go(i+1)) return true;
                    g[g[i]] = -1;
                    used[f[i]] = false;
                }
            } else {
                if (g[g[i]] == f[i]) {
                    if (go(i+1)) return true;
                }
            }
        }
        return false;
    };
    cout << (go(0) ? "Yes" : "No") << endl;
    return 0;
}