#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 6;
long long int t, i, j, k, n, m, q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  long long int a[n + 1];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool visited[n + 1];
  memset(visited, 0, sizeof(visited));
  bool f = 0;
  for (i = 0; i < n; i++) {
    if (a[a[a[i] - 1] - 1] - 1 == i) {
      f = 1;
      break;
    }
  }
  cout << (f ? "YES" : "NO");
  return 0;
}
