#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
bool used[N];
bool f;
vector<vector<int> > g((N), vector<int>());
void dfs(int v, int pr = -1) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++)
    if (!used[g[v][i]]) {
      int p = g[v][i];
      for (int j = 0; j < g[p].size(); j++)
        if (g[p][j] == pr) {
          f = true;
          cout << "YES";
          exit(0);
        }
      dfs(g[v][i], v);
    }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    g[i].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) dfs(i);
    if (f == true) return 0;
  }
  cout << "NO";
  return 0;
}
