#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  int adj[10000];
  for (long long i = 1; i <= n; i++) {
    cin >> adj[i];
  }
  bool tr = 0;
  for (long long i = 1; i <= n; i++) {
    if (adj[adj[adj[i]]] == i) {
      tr = 1;
      break;
    }
  }
  cout << (tr == 1 ? "YES" : "NO");
}
