#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int n, f[maxn];
bool ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++) {
    if (f[f[f[i]]] != i) continue;
    ans = true;
    break;
  }
  if (ans)
    puts("YES");
  else
    puts("NO");
  return 0;
}
