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