Legend has it that the Old Gods' voices are dread whispers that no mere mortal can hope to resist. And now, the time of their awakening draws near. Will you head their whispers at your ear?
We may represent a whisper by a sequence of digits. And surprisingly, the whispers of the Old Gods can be characterized by a regular expression (<regex>). The syntax of a regular expression is shown below (in Backus-Naur form):
<regex> ::= <regex> <regex>
| <regex> "|" <regex>
| <regex> "+"
| <atomic-regex>
<atomic-regex> ::= <digit>
| "[" <digit-sequence> "]"
| "(" <regex> ")"
where <digit> is any single digit (0, 1, ..., 9) and <digit-sequence> is any nonempty sequence of digits. In case of any ambiguity, the positive closure (<regex> "+") has the highest precedence, which is followed by the concatenation (<regex> <regex>), and the alternation (<regex> "|" <regex>) has the lowest precedence. For example, the regular expression 1|23+ should be parsed as (1|(2(3+))).
Every regular expression $$$R$$$ recognizes a set of digit strings, denoted $$$L(R)$$$, which is defined as follows:
Given a regular expression describing the whispers of the Old Gods and a whisper you heard last night, you wonder how close is the whisper you heard to the Old Gods'. Specifically, you want to know the minimum number of changes to make it recognized by the regular expression. There are three kinds of changes to the whisper:
For example, let the regular expression be (5|6+)[12]3+, and the sequence of digits you've heard be 4334. One possible way to make minimum number of changes to make the digit sequence recognized by the regular expression is 4334 -> 54334 -> 52334 -> 5233.
The input contains two lines.
The first line of the input is the regular expression $$$R$$$ characterizing the whispers of the Old Gods, which contains at most $$$5\,000$$$ characters. The regular expression is syntactically correct and contains no character other than digits, |, [, ], (, ), and +.
The second line is a nonempty digital sequence with at most $$$10^4$$$ digits, denoting the whisper you've heard.
Print a single integer, denoting the minimum number of changes you could make to the whisper, such that it can be recognized by the regular expression.
(5|6+)[12]3+ 4334
3
[12](3+|4+)+ 2345
1
(234|25)+ 2442342523535
3
| Название |
|---|


