#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<int> &v) {
  for (int i : v) {
    cout << i << " ";
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int j = 0;
  while (n--) {
    cin >> j;
    v.push_back(j - 1);
  }
  for (int i = 0; i < v.size(); i++) {
    if (i == v[v[v[i]]]) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
