Submit: 1922 Solved: 417

[Submit][Status][Web Board]

Given a string of which the first half is generated by applying a substitution cipher on the second half and the second half may lost some characters from the tail. You are now required to calculate the minimal possible length of the second half of the string.

The first line is the code table for the substitution cipher, which contains 26 letters representing the encrypted letter for each letter in lexicographical order.

The second line is \(S \ \ (1\leq |s| \leq 5*10^5)\).

One integer, indicating the minimal possible length of the second half.

```
b c d e f g h i j k l m n o p q r s t u v w x y z a
bcdeabc
```

`4`