Codeforces Round 131 (Div. 1)
E
Two Permutations
Codeforces
2700
原题
← D→
翻译中…

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 $*a*_{*i*}$.

翻译中…

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*$ $(*c*_{1} = *a*_{1} + *d*, *c*_{2} = *a*_{2} + *d*, ..., *c*_{*n*} = *a*_{*n*} + *d*)$ of length $*n*$ is a subsequence of $*b*$.

翻译中…

Sequence $*a*$ is a subsequence of sequence $*b*$, if there are such indices $*i*_{1}, *i*_{2}, ..., *i*_{*n*}$ $(1 ≤ *i*_{1} < *i*_{2} < ... < *i*_{*n*} ≤ *m*)$, that $*a*_{1} = *b*_{*i*_{1}}$, $*a*_{2} = *b*_{*i*_{2}}$, $...$, $*a*_{*n*} = *b*_{*i*_{*n*}}$, 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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

On a single line print the answer to the problem.

翻译中…

样例

Input #1
1 1
1
1
Output #1
1
InputCopy OutputCopy
Input #2
1 2
1
2 1
Output #2
2
InputCopy OutputCopy
Input #3
3 3
2 3 1
1 2 3
Output #3
0
InputCopy OutputCopy
题目信息
题号
213E
时间限制
2 s
内存限制
256 MB
标签
数据结构
哈希
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。