UHCC1 P2 - String

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Given a long string S of length K and N words. Find the number of characters in the string that are overlapped by at least two words that appears in the string. Note that each word might appear more than once in the long string.

S and the N words will only contain lowercase characters.

Constraints

1\leq K\leq 10^4

The sum of the lengths of the N words will not exceed 10^3.

Input Specification

The first line of input contains a single integer K.

The second line of input contains the string S.

The third line of input contains a single integer N.

The next N lines of input each contains a word.

Output Specification

Output the number of characters contained in at least two words.

Sample Input 1

8
aabcdefg
4
aa
abc
def
ef

Sample Output 1

3

Sample Explanation 1

The overlapping characters are shown in blue below.

Sample Input 2

16
fafelmasfelimsdf
5
fa
felim
m
ef
kenneth

Sample Output 2

1

Sample Explanation 2

The only overlapping letter is "m", the overlap from "felim" and "m".

Sample Input 3

3
aaa
1
aa

Sample Output 3

1

Sample Explanation 3

The middle "a" is overlapped by the two "aa".


Comments

There are no comments at the moment.