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