#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif void solve() { int N; cin >> N; vector A(N); for(int i = 0; i < N; i++) cin >> A[i], A[i]--; vector seen(N); int ans = 0; for(int i = 0; i < N; i++) { int size = 0; int cur = i; do { size += 1; seen[cur] = true; cur = A[cur]; }while(!seen[cur]); ans += size - 1; } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while(tt--) { solve(); } }