#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200000];
int main() {
  int c1, c2, first = 0, g, h, z = 0, b[5004], d, e, k, t, n, m, y, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    a[i].first = i + 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i].second == a[j].first &&
          a[a[j].second - 1].second == a[i].first) {
        cout << "YES";
        exit(0);
      }
    }
  }
  cout << "NO";
}
