#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x;
  cin >> n;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    mp[i] = x - 1;
  }
  for (int i = 0; i < n; ++i) {
    int a = mp[i];
    int b = mp[a];
    int c = mp[b];
    if (i == c) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
}
