#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int temp1, temp2, flag = 0;
  for (int i = 0; i < n; ++i) {
    temp1 = a[i] - 1;
    temp2 = a[temp1] - 1;
    if (a[temp2] - 1 == i) {
      flag = 1;
      printf("YES\n");
      break;
    }
  }
  if (flag == 0) {
    printf("NO\n");
  }
  return 0;
}
