#include <bits/stdc++.h>
using namespace std;
int visited[100000], arr[100000], flag = 0;
int main() {
  long long n;
  cin >> n;
  long long x;
  for (x = 1; x <= n; x++) {
    cin >> arr[x];
  }
  for (x = 1; x <= n; x++) {
    if (arr[arr[arr[x]]] == x) {
      cout << "YES\n";
      break;
    }
    if (x == n) cout << "NO\n";
  }
}
