Cutting the shortest piece from a necklace
There is a necklace of n beads strung in a circle. Each bead has one lowercase English letter on it, and the i-th character of the necklace string S is the i-th bead. Because the necklace is round, the 1st bead comes again after the n-th bead. You want to cut out some consecutive beads so that you have every letter of string T, at least as many times as it appears in T. The beads you cut out start at some bead and continue in the direction of increasing numbers (after the n-th comes the 1st), and the same bead cannot be used twice. Cut out as few beads as possible. If there are several ways, choose the one whose starting bead has the smallest number. Print the number of the starting bead and the number of beads cut out on one line, separated by a space. If no cut works, print -1.
- Input
- The first line has S and the second line has T.
Both consist of lowercase English letters only.
1 ≤ length n of S ≤ 100,000, 1 ≤ length of T ≤ 100,000 - Output
- The number of the starting bead and the number of beads on one line, separated by a space, or -1
cabbad dc
6 2
ab aa
-1