#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100009;
int n, f[MAXN], vis[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &f[i]);
  for (int i = 1; i <= n; ++i) {
    int a = i, b = f[a], c = f[b];
    if (f[c] == a) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
