#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long ar[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (long long i = 1; i <= n; i++) {
    long long f = ar[i];
    long long t = ar[f];
    if (ar[t] == i) {
      return cout << "YES", 0;
    }
  }
  cout << "NO";
  return 0;
}
