#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, tk;
  vector<int> vc;
  vc.push_back(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> tk, vc.push_back(tk);
  for (int i = 1; i <= n; i++) {
    int x = vc[vc[i]];
    if (vc[x] == i) return puts("YES"), 0;
  }
  puts("NO");
}
