#include <bits/stdc++.h>
using namespace std;
long long FastExp(long long a, long long b, long long c) {
  if (b == 1) return a;
  long long ans = FastExp(a, b / 2, c);
  if (b % 2 == 0) return ans % c * ans % c;
  if (b % 2 != 0) return ans % c * ans % c * a % c;
}
int main() {
  int n;
  cin >> n;
  int a[n + 5];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == a[a[a[i]]]) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
