#include <bits/stdc++.h>
using namespace std;
void io() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
const int N = 2e5 + 9;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
int dx[5] = {0, -1, 1, 0, 0};
int dy[5] = {0, 0, 0, -1, 1};
char dc[5] = {'0', 'U', 'D', 'L', 'R'};
int f[N];
int main() {
  int test;
  test = 1;
  while (test--) {
    int n;
    cin >> n;
    for (int i = (0), _n = ((n)-1); i <= _n; ++i) {
      cin >> f[i];
      f[i]--;
    }
    for (int i = (0), _n = ((n)-1); i <= _n; ++i) {
      int x = f[i];
      int y = f[x];
      if (f[y] == i) {
        cout << "YES";
        return 0;
      }
    }
    cout << "NO";
  }
  return 0;
}
