#P9940. Cowphabet Song
Cowphabet Song
Cowphabet Song
Bessie the cow has her own language called Cowphabet, which is composed of (26) lowercase letters from a
to z
. However, when Bessie sings, she uses a specific permutation of these letters instead of the usual alphabetical order. Farmer John has recorded a sequence of letters that he heard while Bessie was repeatedly singing her cowphabet song. Note that Farmer John might have missed some letters, so the recorded sequence is only a subsequence of the full repeated song.
Given the cowphabet ordering and the sequence that Farmer John heard, determine the minimum number of times Bessie must have sung her complete cowphabet song so that the recorded sequence can be obtained as a subsequence of the sung letters.
Formally, let the cowphabet ordering be a permutation of the 26 letters. Bessie sings this ordering repeatedly. You are given a string s (of lowercase letters) that is a subsequence of this repeated string. Find the minimum number of complete repetitions needed such that s appears as a subsequence.
inputFormat
The input consists of two lines:
- The first line is a string of length 26 representing the cowphabet ordering (a permutation of
a
toz
). - The second line is a non-empty string s representing the sequence of letters that Farmer John heard.
outputFormat
Output a single integer, the minimum number of complete cowphabet songs Bessie must have sung for the recorded sequence to appear as a subsequence.
sample
abcdefghijklmnopqrstuvwxyz
mood
3