#include <bits/stdc++.h>
using namespace std;
const int maxn = 10007;
int a[maxn];
int n;
bool dfs(int i) {
  int B = a[i];
  int C = a[B];
  int D = a[C];
  if (D == i) return true;
  return false;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  bool ok = false;
  for (int i = 1; i <= n; i++)
    if (dfs(i)) ok = true;
  if (ok)
    cout << "YES";
  else
    cout << "NO";
}
