#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int INF = 1e18;
const int N = 1e5 + 5;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos(-1.0);
int n, a[N], f[N];
int main(int argc, char const *argv[]) {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], f[i] = a[i];
  for (int i = 1; i <= n; i++) {
    if (f[f[f[i]]] == i) return cout << "YES" << endl, 0;
  }
  cout << "NO" << endl;
  return 0;
}
