#include #include using namespace std; using namespace atcoder; using ll = long long; using Graph = vector >; using mint = modint998244353; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e+18; #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP2(i, s, n) for (int i = (s); i < (int)(n); i++) #define YesNo(T) if(T){cout<<"Yes"< #define VL vector #define VC vector #define VVI vector > #define VVL vector > #define VVC vector > #define VPII vector > #define VPLL vector > template inline void printVec(std::vector v){ REP(i,v.size()){ if(i) std::cout << " "; std::cout << v[i]; } std::cout << std::endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; VI p(n); REP(i,n) cin >> p[i]; int just = 0; int swap = 0; int apart = 0; REP(i,n){ if(p[i] == i + 1) just++; else if(p[p[i] - 1] == i + 1) swap++; else apart++; } // cout << just << " " << swap << " " << apart << endl; cout << swap / 2 + max(0,apart - 1) << endl; }