#include #include using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); int N, x; while(cin >> N) { vector a(N); for(int i = 0; i < N; ++i) { cin >> x; a[i] = x-1; } int n = 0, t = 0; for(int i = 0; i < N; ++i) { // cout << n << " " << t << '\t' << i << " " << a[i] << endl; if (a[i] == i) continue; if (i == a[a[i]]) { if (i < a[i]) {n += 1;continue;} else continue; } t++; // cout << i << " " << a[i] << " " << n << " " << t << endl; } // cout << endl << endl; // cout << n << " "<< t << endl; cout << n + max(0, t-1) << endl; } }