{"problem":{"name":"B. Mahmoud the Thief","description":{"content":" As Ayoub was going home from Mahmoud's house, he remembered that he forgot his hard disk, which contains the solutions to $n$ problems from the JU Flash contest. The $i^(t h)$ problem has size $a_i$.","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10203B"},"statements":[{"statement_type":"Markdown","content":"As Ayoub was going home from Mahmoud's house, he remembered that he forgot his hard disk, which contains the solutions to $n$ problems from the JU Flash contest. The $i^(t h)$ problem has size $a_i$.\n\n While panicking, he remembered that he installed a software that prevented the user from copying any files and only allowed the files to be cut from the hard disk in any order the user wants.\n\n As a security measure, the software will stop the transfer if the number of remaining files is 1, or the absolute difference between the sizes of every pair of problems left on the hard disk is divisible by $m$.\n\n Ayoub knows the permutation $b$, which represents the order of the problems Mahmoud will attempt to cut from the hard disk. \n\n Since Ayoub is a bad programmer, he asks for your help to tell him how many problems Mahmoud will steal until the transfer stops.\n\nThe first line contains two integer $n$ and $m$ $(1 <= n <= 10^5)$ $(1 <= m <= 10^9)$\n\nThe second line contains integers $a_1$,$a_2$,...,$a_n$ $(1 <= a_i <= 10^9)$\n\nThe third line contains a permutation $b$ , $b_1$,$b_2$,...,$b_n$ $(1 <= b_i <= 10^5)$ \n\nprint exactly one integer $-$ the number of codes Mahmoud can steal\n\nIn The first sample :\n\nAt first Mahmoud will try to cut the file with index $2$, and he can do it since there exists two files, the absolute difference between their sizes is not divisible by $m$(for example file $2$ and file $1$ ($a_1 -a_2 = 1$) and $1$ is not divisible by $2$).\n\nAfter cutting The first file, the remaining files will be the files with indices $1$ and $3$, Mahmoud can't cut The next file, because the absolute difference between any pair is divisible by $m$.\n\nSo Mahmoud will steal only one file.\n\n## Input\n\nThe first line contains two integer $n$ and $m$ $(1 <= n <= 10^5)$ $(1 <= m <= 10^9)$The second line contains integers $a_1$,$a_2$,...,$a_n$ $(1 <= a_i <= 10^9)$The third line contains a permutation $b$ , $b_1$,$b_2$,...,$b_n$ $(1 <= b_i <= 10^5)$ \n\n## Output\n\nprint exactly one integer $-$ the number of codes Mahmoud can steal\n\n[samples]\n\n## Note\n\nIn The first sample :At first Mahmoud will try to cut the file with index $2$, and he can do it since there exists two files, the absolute difference between their sizes is not divisible by $m$(for example file $2$ and file $1$ ($a_1 -a_2 = 1$) and $1$ is not divisible by $2$).After cutting The first file, the remaining files will be the files with indices $1$ and $3$, Mahmoud can't cut The next file, because the absolute difference between any pair is divisible by $m$.So Mahmoud will steal only one file.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers representing file sizes.  \nLet $ b = (b_1, b_2, \\dots, b_n) $ be a permutation of $ \\{1, 2, \\dots, n\\} $, representing the order of attempted file removals.\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 10^5 $  \n2. $ 1 \\leq m \\leq 10^9 $  \n3. $ 1 \\leq a_i \\leq 10^9 $ for all $ i \\in \\{1, \\dots, n\\} $  \n4. $ b $ is a permutation of $ \\{1, \\dots, n\\} $\n\n**Objective**  \nSimulate the process:  \n- Start with the full set of files $ S = \\{1, 2, \\dots, n\\} $.  \n- For $ k = 1 $ to $ n $:  \n  - Let $ i = b_k $ be the next file to attempt removal.  \n  - If $ |S| = 1 $, stop.  \n  - Else if for all distinct $ j, \\ell \\in S \\setminus \\{i\\} $, $ m \\mid |a_j - a_\\ell| $, stop.  \n  - Else, remove $ i $ from $ S $ and continue.  \n- Output the number of files successfully removed before stopping.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10203B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}