Tara and Sandy are at the beach! Tara is showing Sandy a card trick with each card labeled with a single, not necessarily unique, lowercase English character.
Initially, Tara has a sequence of cards and shows it to Sandy. Tara then performs a cyclic shift on the cards (a cyclic shift is obtained by repeatedly moving cards from the front of the sequence to the back). For example, the cyclic shifts of abcde
are abcde
, bcdea
, cdeab
, deabc
, and eabcd
. Let this new sequence of cards be .
Afterwards, Tara takes a completely random sequence of card(s) from a seperate deck and inserts it in front of the sequence . The then takes another random sequence of card(s) and places it behind the sequence (it is possible for sequence and/or to be empty). The final sequence is . Let's call this sequence .
Sandy saw Tara perform these steps but suspects that Tara performed some sort of sleight of hand. Given the original sequence , and Tara's proposed sequence for , determine the possible ways to achieve this proposed sequence from though the above operations.
Constraints
Note: denotes the length of the sequence .
In all test cases,
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line contains the sequence (the original sequence of cards).
The second line contains Tara's proposed sequence .
Output Specification
If it is possible to convert into Tara's proposed sequence through these operations, list all the -indices that sequence can begin on in increasing order. Otherwise, output -1
.
Sample Input 1
abcde
cazbcdeatueabcde
Output for Sample Case 1
4
11
12
Explanation for Sample Case 1
There are ways for Tara to generate :
- Generate the cyclic shift
bcdea
, prependcaz
, and appendtueabcde
to create the resulting sequence. The sequence (bcdea
) begins on the character of sequence . - Generate the cyclic shift
eabcd
, prependcazbcdeatu
, and appende
to create the resulting sequence. The sequence (eabcd
) begins on the character of sequence . - Generate the cyclic shift
abcde
, prependcazbcdeatue
, and append nothing to create the resulting sequence. The sequence (abcde
) begins on the character of sequence .
Sample Input 2
abcde
wwwvvabcd
Output for Sample Case 2
-1
Comments