#include int max(int a1, int a2) { return a1 > a2 ? a1 : a2; } int main() { int n = 0; int arr[300000]; bool swapped[300000]; while (scanf("%d", &n) > 0) { for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); swapped[i] = false; } int goodPosCount = 0; for (int i = 0; i < n; i++) { if (arr[i] == i + 1) goodPosCount++; } int pairPosCount = 0; for (int i = 0; i < n; i++) { if (arr[i] != i + 1 && arr[arr[i] - 1] == i + 1 && swapped[i] == false) { pairPosCount++; swapped[i] = true; swapped[arr[i] - 1] = true; } } int res = pairPosCount + max(0, n - goodPosCount - 2 * pairPosCount - 1); //int res = n - goodPosCount - pairPosCount + (goodPosCount + 2 * pairPosCount != n ? -1 : 0); printf("%d\n", res); } return 0; }