atcoder#ABC257G. [ABC257G] Prefix Concatenation
[ABC257G] Prefix Concatenation
Score : points
Problem Statement
You are given two strings and consisting of lowercase English letters.
Find the minimum positive integer such that you can choose (not necessarily distinct) prefixes of so that their concatenation coincides with .
In other words, find the minimum positive integer such that there exists a -tuple of integers between and such that , where denotes the substring of from the -st through the -th characters and denotes the concatenation of strings.
If it is impossible to make it coincide with , print instead.
Constraints
- and are strings consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum positive integer such that you can choose prefixes of so that their concatenation coincides with . It is impossible to make it coincide with , print instead.
aba
ababaab
3
ababaab
can be written as ab
+ aba
+ ab
, of which ab
and aba
are prefixes of aba
.
Since it is unable to express ababaab
with two or less prefixes of aba
, print .
atcoder
ac
-1
Since it is impossible to express as a concatenation of prefixes of , print .