CF778A.String Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 tt and wants to get the word pp 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 tt : a1... ata_{1}...\ a_{|t|} . We denote the length of word xx as x|x| . Note that after removing one letter, the indices of other letters don't change. For example, if t=t= "nastya" and a=[4,1,5,3,2,6]a=[4,1,5,3,2,6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".

Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word pp . 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 pp can be obtained by removing the letters from word tt .

输入格式

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

Next line contains a permutation a1,a2,...,ata_{1},a_{2},...,a_{|t|} of letter indices that specifies the order in which Nastya removes letters of tt ( 1<=ai<=t1<=a_{i}<=|t| , all aia_{i} are distinct).

输出格式

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

输入输出样例

  • 输入#1

    ababcba
    abb
    5 3 4 1 7 6 2
    

    输出#1

    3
  • 输入#2

    bbbabb
    bb
    1 6 3 4 2 5
    

    输出#2

    4

说明/提示

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

"ababcba" "ababcba" "ababcba" "ababcba"

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

So, Nastya will remove only three letters.

首页