{"raw_statement":[{"iden":"statement","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_."},{"iden":"input","content":"The 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."},{"iden":"output","content":"Print 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."},{"iden":"examples","content":"Input\n\n4\n4 3 2 1\n0 1 1 1\n\nOutput\n\n2\n\nInput\n\n3\n2 3 1\n0 0 0\n\nOutput\n\n1"},{"iden":"note","content":"In 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."}],"translated_statement":[{"iden":"statement","content":"Pavel 在烤肉。有 #cf_span[n] 根肉串，它们排成一行，每根位于 #cf_span[n] 个位置之一。Pavel 希望每根肉串在两个方向上都经过每个位置：即最初的方向和反转后的方向。\n\nPavel 有一个计划：一个排列 #cf_span[p] 和一个由 0 和 1 组成的序列 #cf_span[b1, b2, ..., bn]。每一秒，Pavel 将位置 #cf_span[i] 上的肉串移动到位置 #cf_span[pi]，如果 #cf_span[bi] 等于 #cf_span[1]，则将其反转。他希望每根肉串都能访问每个位置的两个方向。\n\n不幸的是，并非每一对排列 #cf_span[p] 和序列 #cf_span[b] 都符合 Pavel 的要求。他需要最少改变多少个元素（在给定的排列 #cf_span[p] 和序列 #cf_span[b] 中），才能使每根肉串访问全部 #cf_span[2n] 个位置？注意，修改后排列仍必须保持为一个排列。\n\n如果某根肉串在烹饪结束前多次访问某些位置，这对 Pavel 来说没有问题。换句话说，如果存在一个整数 #cf_span[k]（#cf_span[k ≥ 2n]），使得在 #cf_span[k] 秒后，每根肉串都访问过全部 #cf_span[2n] 个位置，则排列 #cf_span[p] 和序列 #cf_span[b] 就是合适的。\n\n可以证明，对于任意 #cf_span[n]，都存在一组合适的排列 #cf_span[p] 和序列 #cf_span[b]。\n\n第一行包含整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 2·105]）——肉串的数量。\n\n第二行包含整数序列 #cf_span[p1, p2, ..., pn]（#cf_span[1 ≤ pi ≤ n]）——Pavel 想用来移动肉串的排列。\n\n第三行包含由 0 和 1 组成的序列 #cf_span[b1, b2, ..., bn]，表示 Pavel 想用来反转肉串的规则。\n\n请输出一个整数——Pavel 需要最少改变的排列 #cf_span[p] 和序列 #cf_span[b] 中的元素总数，使得每根肉串都能访问全部 #cf_span[2n] 个位置。\n\n在第一个例子中，Pavel 可以将排列改为 #cf_span[4, 3, 1, 2]。\n\n在第二个例子中，Pavel 可以将 #cf_span[b] 中的任意一个元素改为 #cf_span[1]。"},{"iden":"input","content":"第一行包含整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 2·105]）——肉串的数量。\n\n第二行包含整数序列 #cf_span[p1, p2, ..., pn]（#cf_span[1 ≤ pi ≤ n]）——Pavel 想用来移动肉串的排列。\n\n第三行包含由 0 和 1 组成的序列 #cf_span[b1, b2, ..., bn]，表示 Pavel 想用来反转肉串的规则。"},{"iden":"output","content":"请输出一个整数——Pavel 需要最少改变的排列 #cf_span[p] 和序列 #cf_span[b] 中的元素总数，使得每根肉串都能访问全部 #cf_span[2n] 个位置。"},{"iden":"examples","content":"输入\n4\n4 3 2 1\n0 1 1 1\n输出\n2\n\n输入\n3\n2 3 1\n0 0 0\n输出\n1"},{"iden":"note","content":"在第一个例子中，Pavel 可以将排列改为 #cf_span[4, 3, 1, 2]。\n\n在第二个例子中，Pavel 可以将 #cf_span[b] 中的任意一个元素改为 #cf_span[1]。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of skewers.  \nLet $ p \\in S_n $ be a permutation of $ \\{1, 2, \\dots, n\\} $.  \nLet $ b \\in \\{0,1\\}^n $ be a binary sequence.  \n\nEach skewer $ i \\in \\{1, \\dots, n\\} $ is associated with a state $ (i, d) \\in \\{1, \\dots, n\\} \\times \\{0,1\\} $, representing its position and direction ($ d = 0 $: original, $ d = 1 $: reversed). There are $ 2n $ total placements.\n\nThe dynamics are:  \nAt each second, skewer at position $ i $ with direction $ d $ moves to position $ p[i] $ and direction $ d \\oplus b[i] $.\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 2 \\cdot 10^5 $  \n2. $ p $ is a permutation: $ p_i \\in \\{1, \\dots, n\\} $, all distinct.  \n3. $ b_i \\in \\{0,1\\} $ for all $ i $.  \n\n**Objective**  \nFind the minimum total number of changes to elements of $ p $ and $ b $ such that, under the updated $ p $ and $ b $, the state transition graph on the $ 2n $ placements consists of a single cycle of length $ 2n $ (i.e., the system is a single cyclic orbit covering all placements).\n\nEquivalently:  \nMinimize $ |\\{ i \\mid p_i \\neq p_i' \\}| + |\\{ i \\mid b_i \\neq b_i' \\}| $,  \nover all $ p' \\in S_n $, $ b' \\in \\{0,1\\}^n $, such that the permutation $ \\sigma: (i,d) \\mapsto (p'[i], d \\oplus b'[i]) $ is a single $ 2n $-cycle.","simple_statement":null,"has_page_source":false}