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