#K43157. Minimum Adjacent Swaps

    ID: 27247 Type: Default 1000ms 256MiB

Minimum Adjacent Swaps

Minimum Adjacent Swaps

This problem requires you to determine the minimum number of adjacent swaps needed to transform one string into another. More formally, given two strings initial and target, you can only swap two consecutive characters in the initial string. Your goal is to transform initial into target using the minimum number of such swaps. If the transformation is impossible (either because the strings have different characters or different lengths), you should output \(-1\).

For example, if initial is "abcdef" and target is "abcfde", the minimum number of adjacent swaps is \(2\). On the other hand, if initial is "abc" and target is "def", no sequence of swaps can transform one into the other, so the answer is \(-1\).

Note: All input will be read from standard input and any output should be written to standard output.

inputFormat

The input consists of two lines:

  1. The first line contains the initial string.
  2. The second line contains the target string.

Both strings will consist of lowercase English letters.

outputFormat

Output a single integer, which is the minimum number of adjacent swaps required to transform the initial string into the target string. If the transformation is impossible, output -1.

## sample
abc
abc
0

</p>