#include <bits/stdc++.h>
using namespace std;
int main() {
  int size;
  cin >> size;
  vector<int> arr(size + 1);
  for (int i = 1; i <= size; i++) cin >> arr[i];
  for (int i = 1; i <= size; i++)
    if (arr[arr[arr[i]]] == i) {
      cout << "YES" << endl;
      return 0;
    }
  cout << "NO" << endl;
  return 0;
}
