#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int hgv;
    cin >> hgv;
    v.push_back(hgv);
  }
  for (int i = 0; i < n; i++) {
    if (i == (v[v[v[i] - 1] - 1] - 1)) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}
