#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int temp1, temp2;
    if (a[i] != i) {
      temp1 = a[a[i]];
      temp2 = a[a[a[i]]];
      if (i == temp2) {
        cout << "yes" << endl;
        break;
      }
      if (i == n && (temp2 != i)) {
        cout << "no" << endl;
        break;
      }
    }
  }
}
