#include <bits/stdc++.h>
using namespace std;
int i, t, r, val[5100], n, a, b, c;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (i = 1; i <= n; i++) {
    a = val[i];
    b = val[a];
    c = val[b];
    if (c == i) {
      r = 1;
    }
  }
  if (r == 1)
    cout << "YES\n";
  else {
    cout << "NO\n";
  }
  return 0;
}
