#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
      cin >> v[i];
    }
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (v[i] != i && v[v[v[i]]] == i) flag = true;
    }
    if (flag)
      cout << "YES\n";
    else {
      cout << "NO\n";
    }
  }
  return 0;
}
