#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, AA, BB;
  cin >> n;
  int ar[n + 5];
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i <= n; i++) {
    int p1 = ar[i];
    int p2 = ar[p1];
    int p3 = ar[p2];
    if (p3 == i) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
