#include <bits/stdc++.h>
using namespace std;
const long long int LL_MAX = 1e18 + 5;
const int MX = INT_MAX;
const long long int mod = 1000000007;
const int maxx = 2e5;
const int d4i[4] = {-1, 0, 1, 0};
const int d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
string y = "YES", no = "NO";
void solve() {
  int n;
  cin >> n;
  ;
  vector<int> a;
  for (long long int i = (0); i < (n); i++) {
    int k;
    cin >> k;
    ;
    a.push_back(k);
  }
  for (long long int i = (0); i < (n); i++) {
    int x = i + 1;
    int l = a[i];
    int z = a[l - 1];
    int p = a[z - 1];
    if (x == p) {
      cout << y << "\n";
      return;
    }
  }
  cout << no << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
