#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, i, j, k, sum, tmp, x, y, ara[100005], n, m;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
  }
  m = 0;
  for (i = 1; i <= n; i++) {
    x = ara[i];
    y = ara[x];
    if (y != i) {
      if (ara[y] == i) {
        m = 1;
        break;
      }
    }
  }
  if (m == 0) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
}
