Message
Limits: 2 sec., 256 MiB
One evening Zenyk decided to send some nice message to Marichka to congratulate her on the start of spring. Initially, he entered message \(s\) on his phone, but after a moment he realized, that it would be much better to enter message \(t\).
Unfortunately, it’s not so easy to change the message now – the only thing Zenyk is able to do is to remove the first or the last occurrence of any letter. Please note that he is able to perform this operation any number of times. Moreover, the letters are not removed instantly. It takes \(w_i\) seconds to remove character that was initially placed on \(i\)-th position in string \(s\).
Help Zenyk to calculate the minumum number of seconds it takes to transform message \(s\) into \(t\) using the described operations. If it’s impossible to do that, print a single line \(\texttt{``You better start from}\) \(\texttt{scratch man...''}\) (without quotes).
Input
The first line of the input contains string \(s\), the second – string \(t\). The third line contains \(|s|\) space-separated integers, each of which denotes the number of seconds it takes to remove the corresponding character.
Output
If Zenyk is able to transform \(s\) into \(t\), print the minimum number of seconds required to do that. Otherwise, print \(\texttt{``You better start from scratch man...''}\) (without quotes).
Constraints
\(1 \le |s|, |t| \le 200000\),
\(1 \le w_i \le 10^9\),
Strings \(s\) and \(t\) consist only of the lower case latin letters \(\texttt{a-z}\).
Samples
Input (stdin) | Output (stdout) |
---|---|
ababccb abc 7 2 2 4 3 2 1 | 7 |
Input (stdin) | Output (stdout) |
---|---|
babab baab 2 1 3 2 4 | You better start from scratch man... |
Submit a solution
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|