#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, c = 0;
  cin >> n;
  vector<long long int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 1; i <= n; i++) {
    if (v[v[v[i]]] == i) {
      c++;
    }
  }
  if (c % 3 == 0 && c != 0)
    cout << "YES\n";
  else
    cout << "NO\n";
}
