#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[5001];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    int z, y;
    z = arr[i];
    y = arr[z];
    if (arr[y] == i) {
      cout << "YES";
      flag = false;
      break;
    }
  }
  if (flag) cout << "NO" << endl;
  return 0;
}
