Flip it and Stick it

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Finn is playing a game of "Flip it and Stick it" which is abbreviated as FiSi. FiSi is a one-player game played on two strings, SS and TT, of 0s and 1s. Finn is allowed to make moves of the following form:

  • Select a substring of SS and reverse it, gluing the pieces of the string back together in their original order to form the new string SS.

For example, Finn may take the string S=S = 101100, take the substring 011 starting at index 22 (assuming 11-based string indexing), and create the string S=S = 111000 in one move. Finn wins the game if SS does not contain TT as a substring. Your task is to help Finn determine the length of the shortest winning sequence of moves or tell him that the game cannot be won.

입력

The first line of input contains the string SS (1S200,000)(1 \le |S| \le 200\\,000).

The second line of input contains the string TT (1T3)(1 \le |T| \le 3).

In the table below, T_1T\_1 is the first bit in TT, T_2T\_2 is the second bit in TT, and T_3T\_3 is the third bit in TT, when reading from left-to-right.

출력

Output the minimum number of moves needed or -1 if it is impossible to win the game.