Codeforces Round 402 (Div. 2)
D
String Game
Codeforces
未评级
原题
← CE →
翻译中…

Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.

翻译中…

Sergey gives Nastya the word $*t*$ and wants to get the word $*p*$ out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word $*t*$: $*a*_{1}... *a*_{|*t*|}$. We denote the length of word $*x*$ as $|*x*|$. Note that after removing one letter, the indices of other letters don't change. For example, if $*t* =$"nastya" and $*a* = [4, 1, 5, 3, 2, 6]$ then removals make the following sequence of words "nastya" image "nastya" image "nastya" image "nastya" image "nastya" image "nastya" image "nastya".

翻译中…

Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word $*p*$. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.

翻译中…

It is guaranteed that the word $*p*$ can be obtained by removing the letters from word $*t*$.

翻译中…

Input

翻译中…

The first and second lines of the input contain the words $*t*$ and $*p*$, respectively. Words are composed of lowercase letters of the Latin alphabet ($1 ≤ |*p*| < |*t*| ≤ 200 000$). It is guaranteed that the word $*p*$ can be obtained by removing the letters from word $*t*$.

翻译中…

Next line contains a permutation $*a*_{1}, *a*_{2}, ..., *a*_{|*t*|}$ of letter indices that specifies the order in which Nastya removes letters of $*t*$ ($1 ≤ *a*_{*i*} ≤ |*t*|$, all $*a*_{*i*}$ are distinct).

翻译中…

Output

翻译中…

Print a single integer number, the maximum number of letters that Nastya can remove.

翻译中…

Note

翻译中…

In the first sample test sequence of removing made by Nastya looks like this:

翻译中…

"ababcba" image "ababcba" image "ababcba" image "ababcba"

翻译中…

Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".

翻译中…

So, Nastya will remove only three letters.

翻译中…

样例

Input #1
ababcba
abb
5 3 4 1 7 6 2
Output #1
3
InputCopy OutputCopy
Input #2
bbbabb
bb
1 6 3 4 2 5
Output #2
4
InputCopy OutputCopy
题目信息
题号
779D
时间限制
2 s
内存限制
512 MB

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