#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5050];
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= n; i++) {
    int a = i;
    int b = arr[i];
    int c = arr[b];
    if (arr[c] == i) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
