#P10069. Flip it and Stick it

    ID: 12050 Type: Default 1000ms 256MiB

Flip it and Stick it

Flip it and Stick it

Finn is playing a game called Flip it and Stick it (FiSi). In the game, you are given two binary strings \(S\) and \(T\). You can perform the following operation on \(S\): select any substring of \(S\) (a contiguous block of characters), reverse it, and then reassemble the string by concatenating the parts in their original order.

If, after some operations, \(S\) no longer contains \(T\) as a substring, Finn wins the game. Your task is to determine the minimum number of operations required for Finn to win, or output -1 if it is impossible.

Note: The positions in \(S\) are 1-indexed, and any reversal operation may be applied on any substring of length at least 2.

inputFormat

The input consists of two lines:

  • The first line contains the binary string \(S\).
  • The second line contains the binary string \(T\).

outputFormat

Output a single integer representing the minimum number of reversal operations required so that \(S\) does not contain \(T\) as a substring. If it is impossible, output -1.

sample

110
11
1