#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const double DELTA = 1e-12;
const int INF = 1e6;
const long long LINF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const int MAXN = 1e5 + 10;
int n;
int a[MAXN];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int j = 1; j < n + 1; ++j) {
    cin >> a[j];
  }
  for (int j = 1; j < n + 1; ++j) {
    if (a[a[a[j]]] == j) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
