#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[n];
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    f[i] = temp - 1;
  }
  bool found = false;
  for (int i = 0; i < n; i++) {
    if (f[f[f[i]]] == i) {
      cout << "YES" << endl;
      found = true;
      break;
    }
  }
  if (!found) {
    cout << "NO" << endl;
  }
}
