#include <bits/stdc++.h>
using namespace std;
int c, a, b, inpt = 0, cntr = 0, flag = 0, mx = INT_MAX;
long long p, q, r, num = 0;
array<char, 101> arr;
vector<int> v;
string str;
bool helper(int j) { return v[j] == v[v[v[v[j] - 1] - 1] - 1]; }
int main() {
  int i = 0;
  int t;
  cin >> t;
  for (int x = 0; x < t; ++x) {
    cin >> inpt;
    v.push_back(inpt);
  }
  for (int x = 0; x < t; x++) {
    if (helper(x)) {
      cout << "YES";
      flag = 1;
      break;
    }
  }
  if (flag == 0) cout << "NO";
}
