#P10976. 统计重复个数

统计重复个数

Problem Description

Define str=[s,n]str = [s, n] to mean that strstr is formed by concatenating the string ss exactly nn times.

For example, str==[abc,3]==abcabcabcstr == [\texttt{abc}, 3] == \texttt{abcabcabc}. If we can delete some characters from s2s_2 to make it become s1s_1, then we say that the string s1s_1 can be obtained from the string s2s_2.

For example, by definition, s1=abcs1 = \tt{abc} can be obtained from s2=abdbecs2 = \tt{ab\red{dbe}c}, by only deleting the characters marked in red.

Now you are given two strings s1s_1 and s2s_2, and two integers n1n_1 and n2n_2. Based on them, we construct two strings: str1=[s1,n1]str_1 = [s_1, n_1] and str2=[s2,n2]str_2 = [s_2, n_2].

Please find the maximum integer mm such that str=[str2,m]str = [str_2, m] can be obtained from str1str_1.

Input Format

This problem contains multiple test cases. There are at most 100100 test cases.

For each test case, there are two lines:

  • The first line contains the string s2s_2 and the integer n2n_2.
  • The second line contains the string s1s_1 and the integer n1n_1.

Output Format

For each test case, output the integer mm as the answer.

ab 2
acb 4
acb 1
acb 1
2
1

Hint

The testdata guarantees that s1s_1 and s2s_2 consist only of lowercase letters, and 1s1,s21001 \leq |s_1|, |s_2| \leq 100, 0n1,n21060 \leq n_1, n_2 \leq 10^6. For each test point, there are no more than 100100 test cases.

Translated by ChatGPT 5