/** * author: zjs * created: 01.09.2026 19:51:18 **/ #include #include // does not include cassert since GCC 16. using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; int ans = 0; vector vis(n + 1); int t = 0; for (int i = 1; i <= n; i++) { if (!vis[i]) { ++t; int j = i; while (!vis[j]) { vis[j] = t; j = a[j]; } if (vis[j] == t) ans++; } } cout << ans << '\n'; }