{"problem":{"name":"Two Permutations","description":{"content":"Snuke has permutations $(P_0,P_1,\\cdots,P_{N-1})$ and $(Q_0,Q_1,\\cdots,Q_{N-1})$ of $(0,1,\\cdots,N-1)$. Now, he will make new permutations $A$ and $B$ of $(0,1,\\cdots,N-1)$, under the following condit","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":8000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc038_f"},"statements":[{"statement_type":"Markdown","content":"Snuke has permutations $(P_0,P_1,\\cdots,P_{N-1})$ and $(Q_0,Q_1,\\cdots,Q_{N-1})$ of $(0,1,\\cdots,N-1)$.\nNow, he will make new permutations $A$ and $B$ of $(0,1,\\cdots,N-1)$, under the following conditions:\n\n*   For each $i$ ($0 \\leq i \\leq N-1$), $A_i$ should be $i$ or $P_i$.\n*   For each $i$ ($0 \\leq i \\leq N-1$), $B_i$ should be $i$ or $Q_i$.\n\nLet us define the distance of permutations $A$ and $B$ as the number of indices $i$ such that $A_i \\neq B_i$. Find the maximum possible distance of $A$ and $B$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 100000$\n*   $0 \\leq P_i \\leq N-1$\n*   $P_0,P_1,\\cdots,P_{N-1}$ are all different.\n*   $0 \\leq Q_i \\leq N-1$\n*   $Q_0,Q_1,\\cdots,Q_{N-1}$ are all different.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$P_0$ $P_1$ $\\cdots$ $P_{N-1}$\n$Q_0$ $Q_1$ $\\cdots$ $Q_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc038_f","tags":[],"sample_group":[["4\n2 1 3 0\n0 2 3 1","3\n\nFor example, if we make $A=(0,1,2,3)$ and $B=(0,2,3,1)$, the distance will be $3$, which is the maximum result possible."],["10\n0 4 5 3 7 8 2 1 9 6\n3 8 5 6 4 0 2 1 7 9","8"],["32\n22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31","28"]],"created_at":"2026-03-03 11:01:14"}}