#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], i;
  for (i = 1; i < n + 1; i++) cin >> a[i];
  for (i = 1; i < n + 1; i++) {
    if (a[i] > n) {
      cout << "no\n";
      break;
    }
    if (a[i] == i) {
      cout << "no\n";
      break;
    }
    if (a[i] == a[a[a[a[i]]]]) {
      cout << "yes"
           << "\n";
      break;
    }
  }
  if (i == n + 1)
    cout << "no"
         << "\n";
  return 0;
}
