#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int H[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> H[i];
  }
  int flag = 0;
  for (int j = 1; j <= n; ++j) {
    if (H[H[H[j]]] == j) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
