405678: GYM102035 B Mahmoud the Thief

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Mahmoud the Thieftime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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^{th}$$$ problem has size $$$a_i$$$.

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.

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$$$.

Ayoub knows the permutation $$$b$$$, which represents the order of the problems Mahmoud will attempt to cut from the hard disk.

Since Ayoub is a bad programmer, he asks for your help to tell him how many problems Mahmoud will steal until the transfer stops.

Input

The first line contains two integer $$$n$$$ and $$$m$$$ $$$(1 \leq n \leq 10^{5})$$$ $$$(1 \leq m \leq 10^{9})$$$

The second line contains integers $$$a_1$$$,$$$a_2$$$,...,$$$a_n$$$ $$$(1 \leq a_i \leq 10^{9})$$$

The third line contains a permutation $$$b$$$ , $$$b_1$$$,$$$b_2$$$,...,$$$b_n$$$ $$$(1 \leq b_i \leq 10^{5})$$$

Output

print exactly one integer $$$-$$$ the number of codes Mahmoud can steal

ExamplesInput
3 2
2 1 4
2 1 3
Output
1
Input
3 2
2 1 4
3 2 1
Output
2
Input
5 2
7 9 5 33 77
5 3 4 2 1
Output
0
Note

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.

Source/Category

加入题单

算法标签: