{"raw_statement":[{"iden":"statement","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"},{"iden":"input","content":"The 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)$ "},{"iden":"output","content":"print exactly one integer $-$ the number of codes Mahmoud can steal"},{"iden":"examples","content":"Input3 2\n2 1 4\n2 1 3\nOutput1\nInput3 2\n2 1 4\n3 2 1\nOutput2\nInput5 2\n7 9 5 33 77\n5 3 4 2 1\nOutput0\n"},{"iden":"note","content":"In 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."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**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.","simple_statement":"Mahmoud wants to cut files from a hard disk one by one in a given order. He can cut a file only if, after cutting it, the remaining files do NOT all have sizes where every pair’s difference is divisible by m. The process stops when either only one file is left, or all remaining files have pairwise differences divisible by m. Given the sizes of the files and the order in which Mahmoud tries to cut them, count how many files he successfully steals before stopping.","has_page_source":false}