#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long int;
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
void solve() {
  ll n;
  cin >> n;
  ll ar[n + 1];
  for (ll i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  bool temp = false;
  for (ll i = 1; i <= n; i++) {
    if (ar[ar[ar[i]]] == i) {
      temp = true;
    }
  }
  if (!temp) {
    cout << "NO"
         << "\n";
  } else {
    cout << "YES"
         << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ll t = 1;
  for (ll i = 1; i <= t; i++) {
    solve();
  }
}
