Time limit
2s
Memory limit
512 MB
You are given a string S and four substrings a, b, c, and d that appear in S.
For each substring, choose one occurrence in S and cover every character in that occurrence. Different substrings may cover the same character.
Find the minimum and maximum possible number of distinct characters of S that can be covered by the four chosen occurrences.
The first line contains the string S. The length of S is at most 2500.
The next four lines contain the substrings a, b, c, and d, in that order. Each substring has length at most 50.
All strings consist only of lowercase English letters.
Print the minimum and maximum possible number of distinct covered characters, separated by a space.
If the same position is covered more than once, it is counted only once. The minimum is obtained by choosing occurrences that overlap as much as possible, and the maximum is obtained by choosing occurrences that overlap as little as possible.