CF213E.Two Permutations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Rubik is very keen on number permutations.
A permutation a with length n is a sequence, consisting of n different numbers from 1 to n . Element number i (1<=i<=n) of this permutation will be denoted as ai .
Furik decided to make a present to Rubik and came up with a new problem on permutations. Furik tells Rubik two number permutations: permutation a with length n and permutation b with length m . Rubik must give an answer to the problem: how many distinct integers d exist, such that sequence c (c1=a1+d,c2=a2+d,...,cn=an+d) of length n is a subsequence of b .
Sequence a is a subsequence of sequence b , if there are such indices i1,i2,...,in (1<=i_{1}<i_{2}<...<i_{n}<=m) , that a1=bi1 , a2=bi2 , ... , an=bin , where n is the length of sequence a , and m is the length of sequence b .
You are given permutations a and b , help Rubik solve the given problem.
输入格式
The first line contains two integers n and m (1<=n<=m<=200000) — the sizes of the given permutations. The second line contains n distinct integers — permutation a , the third line contains m distinct integers — permutation b . Numbers on the lines are separated by spaces.
输出格式
On a single line print the answer to the problem.
输入输出样例
输入#1
1 1 1 1
输出#1
1
输入#2
1 2 1 2 1
输出#2
2
输入#3
3 3 2 3 1 1 2 3
输出#3
0