#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 50;
int arr[MAXN];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  bool ans = 0;
  for (int i = 1; i <= n; i++) {
    int like = arr[i];
    like = arr[like];
    like = arr[like];
    if (i == like) ans = 1;
  }
  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}
