10255: CF EDU - Binary Search - Step 2 - F. String Game
[Creator : ]
Description
Petya has the word $t$, he wants to make the word $p$ from it. Petya begins to delete the letters in a certain order, which is described as a permutation of indices of the letters of the word $t:\ a_1…a_{|t|}$. Note that after deleting a letter, the numbering does not change.
His brother Vasya is afraid that Petya may delete too many letters, so he will not get the word $p$ in the end. Vasya's task is to stop his brother at some point and finish deleting himself in such a way, that the resulting word will be $p$. Since Petya likes this activity, Vasya wants to stop him as late as possible. Your task is to tell how many letters Petya can delete out before Vasya stops him.
It is guaranteed that the word $p$ can be obtained by deleting letters from $t$.
His brother Vasya is afraid that Petya may delete too many letters, so he will not get the word $p$ in the end. Vasya's task is to stop his brother at some point and finish deleting himself in such a way, that the resulting word will be $p$. Since Petya likes this activity, Vasya wants to stop him as late as possible. Your task is to tell how many letters Petya can delete out before Vasya stops him.
It is guaranteed that the word $p$ can be obtained by deleting letters from $t$.
Input
The first and second lines of the input file contain the words $t$ and $p$, respectively. Words consist of lowercase letters of the Latin alphabet $(1≤|p|<|t|≤200,000)$.
The next line contains the permutation $a_1…a_{|t|}$ of letter indices, which specifies the order in which Petya deletes the letters of the word $t\ (1≤a_i≤|t|$, all $a_i$ are different).
The next line contains the permutation $a_1…a_{|t|}$ of letter indices, which specifies the order in which Petya deletes the letters of the word $t\ (1≤a_i≤|t|$, all $a_i$ are different).
Output
Print one number, the maximum number of letters that Petya can delete.
Sample 1 Input
ababcba
abb
5 3 4 1 7 6 2
Sample 1 Output
3