{"problem":{"name":"A. Pavel and barbecue","description":{"content":"Pavel cooks barbecue. There are _n_ skewers, they lay on a brazier in a row, each on one of _n_ positions. Pavel wants each skewer to be cooked some time in every of _n_ positions in two directions: i","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF756A"},"statements":[{"statement_type":"Markdown","content":"Pavel cooks barbecue. There are _n_ skewers, they lay on a brazier in a row, each on one of _n_ positions. Pavel wants each skewer to be cooked some time in every of _n_ positions in two directions: in the one it was directed originally and in the reversed direction.\n\nPavel has a plan: a permutation _p_ and a sequence _b_1, _b_2, ..., _b__n_, consisting of zeros and ones. Each second Pavel move skewer on position _i_ to position _p__i_, and if _b__i_ equals 1 then he reverses it. So he hope that every skewer will visit every position in both directions.\n\nUnfortunately, not every pair of permutation _p_ and sequence _b_ suits Pavel. What is the minimum total number of elements in the given permutation _p_ and the given sequence _b_ he needs to change so that every skewer will visit each of 2_n_ placements? Note that after changing the permutation should remain a permutation as well.\n\nThere is no problem for Pavel, if some skewer visits some of the placements several times before he ends to cook. In other words, a permutation _p_ and a sequence _b_ suit him if there is an integer _k_ (_k_ ≥ 2_n_), so that after _k_ seconds each skewer visits each of the 2_n_ placements.\n\nIt can be shown that some suitable pair of permutation _p_ and sequence _b_ exists for any _n_.\n\n## Input\n\nThe first line contain the integer _n_ (1 ≤ _n_ ≤ 2·105) — the number of skewers.\n\nThe second line contains a sequence of integers _p_1, _p_2, ..., _p__n_ (1 ≤ _p__i_ ≤ _n_) — the permutation, according to which Pavel wants to move the skewers.\n\nThe third line contains a sequence _b_1, _b_2, ..., _b__n_ consisting of zeros and ones, according to which Pavel wants to reverse the skewers.\n\n## Output\n\nPrint single integer — the minimum total number of elements in the given permutation _p_ and the given sequence _b_ he needs to change so that every skewer will visit each of 2_n_ placements.\n\n[samples]\n\n## Note\n\nIn the first example Pavel can change the permutation to 4, 3, 1, 2.\n\nIn the second example Pavel can change any element of _b_ to 1.","is_translate":false,"language":"English"}],"meta":{"iden":"CF756A","tags":["constructive algorithms","dfs and similar"],"sample_group":[["4\n4 3 2 1\n0 1 1 1","2"],["3\n2 3 1\n0 0 0","1"]],"created_at":"2026-03-03 11:00:39"}}