영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
메모리 제한 1024 MB
Problem
Latbo is well known to be the laziest city in Sweden. Björn has had the goal of being the laziest in town since he was little. Yesterday, he made it all the way to the final in this year's laziness competition. He was fully prepared to win but was completely crushed when his opponent was too lazy to even show up.
This was the last straw for Björn, and he has now decided to use his medical knowledge to develop a cure for laziness. To do this, he needs to synthesize the magical protein T.
Since he is too lazy to determine how to do this himself, he is now asking for your help in finding the best way to construct protein T. All proteins, including protein T, can be represented as a string of letters from a-z. Björn knows how to produce M types of proteins. It takes one day to create one of these M proteins, regardless of how long or short they are. He also has tools to combine two proteins. For example, he can take the proteins abc and ba and combine them into either abcba or baabc.
Since Björn wants to produce protein T as quickly as possible, he wants your help in figuring out how many days it will take to produce it if he spends his time optimally. The time it takes to combine proteins is negligible, so you only need to consider the time it takes to produce the proteins.
Input
The first line of the input contains the integer N (1 ≤ N ≤ 10^5), the length of protein T.
The next line contains a string of length N, representing protein T.
The next line contains M (1 ≤ M ≤ 10^6), the number of proteins Björn can manufacture.
Afterwards, M lines follow, each containing a string. This string represents a protein he can produce. It is guaranteed that the total length of the M strings does not exceed 10^6.
All strings in the input consist of letters a-z. It is guaranteed that Björn can synthesize T by only using the M proteins Björn can manufacture.
Output
Print an integer: the number of days it takes for Björn to create protein T if he spends his time optimally.
Scoring
Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.
| Group | Points | Constraints |
|---|---|---|
| 1 | 10 | N ≤ 20, M ≤ 5 |
| 2 | 20 | N, M ≤ 100 |
| 3 | 30 | M ≤ 100 |
| 4 | 40 | No additional constraints. |
Explanation of sample 1
By creating the protein abc twice, he can combine them to create the protein abcabc.
예제
예제 1
6 abcabc 5 a b c abc abca
2
예제 2
5 aaaaa 4 aaaa aa aa aaa
2