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