#include <bits/stdc++.h>
using namespace std;
int main() {
  static int f[10000];
  int n, ok = false;
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", f + i);
  for (int i = 1; i <= n; ++i)
    if (f[f[f[i]]] == i) ok = true;
  puts(ok ? "YES" : "NO");
}
