cswork / OAOpen practice workspace

AmazonOA #280

Maximum Times Word Removed

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Each time, choose any characters from s that, after rearranging, form exactly the target t, then delete those characters; all other characters remain. Find the maximum number of target words that can be taken. The characters need not form a contiguous substring, and they need not spell t in their original order.

Input

The two lines contain s and t. The original statement only specifies lowercase letters; on this site 1≤|s|,|t|≤200000 and the target is non-empty.

Output

Output a single integer, the answer.

Example 1

Input:

abacbc
bca

Output:

2

Example 2

Input:

abdadccacd
edac

Output:

0

Example 3

Input:

aaaaab
aa

Output:

2

Example notes

The answers are 2, 0 and 2 respectively. In the third example each target uses two a's, so it can be taken only twice.

Editorial

Loading solution…