#include <bits/stdc++.h>
using namespace std;
void Start_Crushing() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
vector<int> love;
int nextLove(int plane) { return love[plane]; }
void solve() {
  int n;
  cin >> n;
  love.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> love[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == nextLove(nextLove(nextLove(i)))) {
      cout << "yes";
      return;
    }
  }
  cout << "no";
}
int main() {
  Start_Crushing();
  int t = 1;
  while (t--) {
    solve();
    if (!t) break;
    cout << "\n";
  }
  return 0;
}
