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