#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, f = 0, A, B, C;
  cin >> n;
  vector<long long> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    A = a[i];
    B = a[A - 1];
    C = a[B - 1];
    if (C == i + 1) {
      f = 1;
      break;
    } else
      f = 0;
  }
  if (f == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
