临近期末,请勿抄袭代码,维护公平!

5159: Yuchang ans Zixiang’s Magic 分享至QQ空间

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
Total Submit: 37            Accepted:8

Description

As we know Zixiang and Yuchang are Good And Young, they always play some Professional Young game. However this time, they want to Make Magic, when people around them hear this, they are so surprise that their watermelon have all fallen out of their hands.

One day, Zixiang get a magic diamond, this diamond is made of M small cube diamonds, all the M small diamonds have the same length and width, and the length and width is 1. But they have different height. The ith small diamond’s height is ai, here are some example if you look it from the front:

             

Height:  1  2   3   1                5  2  4  5  1

 

And Yuchang also get a magic diamond, it is also made of N small cube diamonds, all the N small diamonds have the same length and width, and the length and width is 1. But they have different height. The ith small diamond’s height is bi, here are some example if you look it from the front:

             

Height:  1   3   2   1             1  5   4  2  5

However ,the M is always bigger than N , so the Yuchang’s diamond can fit into Zixiang’s diamond some times, the way to make magic is that , Yuchang put his diamond on Zixiang’s, if it look like this :

    

But these will not make magic:

 

To make it more clearly, Zixiang’s diamond is made of M small cube which’s length is 1, and Yuchang’s diamond is the same, so, we can say that the length of Zixiang’s diamond is M, Yuchang’s diamond is N, we know that M is always bigger than N, so we can find a sub length in M which’s length is N

Then we put Yuchang’s diamond on the sub, if they can make a rectangle without any empty area in the rectangle, they will make magic. Now, please tell the people who’s watermelon have fallen out of hands that how many different ways can Zixiang and Yuchang make magic?

Input

Multiple cases, for each case:

The first line contains two numbers N,M(0<N<10000 , 0<M<1000000) means the length of the magic diamondthey have .

Then the second line contains N numbers ,means the height of every small magic diamond which Yuchang has .

The third line contains M numbers , means the height of every small  magic diamond which Zixiang has .

All the numbers is less than 1e9.


Output

Each case output one number per line, the number of ways they can make magic.


Sample Input

Sample Output

Source

华中农业大学2016新生赛

Uploader

crq


[Submit] [Status]

|Back |   | Top|
Copyright @ 2008-2022(浙ICP备2022001332号), TZOJ. All Rights Reserved.