#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    long long aa, bb, cc, laa, lbb, lcc;
    aa = i;
    laa = a[i - 1];
    bb = laa - 1;
    lbb = a[bb];
    cc = lbb - 1;
    lcc = a[cc];
    if (aa == lcc) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
