#K33362. Minimum Left Rotations to Equal Strings

    ID: 25071 Type: Default 1000ms 256MiB

Minimum Left Rotations to Equal Strings

Minimum Left Rotations to Equal Strings

Given two strings s and t each of length \( n \), determine the minimum number of left rotations required to transform s into t. A left rotation moves the first character of the string to its end (i.e. \( s = s_1s_2\ldots s_n \) becomes \( s_2\ldots s_ns_1 \)).

If it is not possible to obtain t from s by any sequence of left rotations, print \(-1\).

Note: It is guaranteed that \( s \) and \( t \) consist of only lowercase English letters.

inputFormat

The input is read from standard input and consists of three lines:

  1. An integer n representing the length of the strings.
  2. A string s of length n.
  3. A string t of length n.

It is guaranteed that \( 1 \leq n \leq 10^5 \).

outputFormat

Output a single integer representing the minimum number of left rotations required to transform s into t. If it is impossible, output -1.

The output should be written to standard output.

## sample
4
abcd
bcda
1