Question: Peter has two strings of the same length. The first string is fixed and the second string is rotatable. In the left rotation, the first

Peter has two strings of the same length. The first string is fixed and the second string is rotatable. In the left rotation, the first character is removed and added to the end of the string. In the right rotation, the last character is removed and added to the start of the string. Peter is Interested in knowing the longest common prefix of both the strings.

Write an algorithm to help Peter find the minimum number of rotations required to find the longest common prefix. If no prefix is common then output -1.

Input

The first line of the input consists of a string firstString, representing the first string.

The second line consists of a string secondString, representing the second string.

Output

Print an integer representing the minimum number of rotations required to find the longest common prefox. If no prefix is common then print -1.

Constraint

0
Note

The input strings are alphanumeric.

The input strings consists of lowercase and uppercase alphabets (l.e. a-z and A-Z) and digits (l.e. 0-9).

The string comparisons are case sensitive Le abcd and ABCD are not considered same.

Example

Input:

azabccc

bdddaza

4 83°F

Mostly cloudy

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question provided is incomplete there seems to be some formatting or con... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!