Problem list
Log in
#coci00221 · COCI 2011/2012 Contest 5

Popločavanje

Platinum I 4.0 s 512 MB

Mirko‟s ASCII street is made of N lowercase letters of the English alphabet. The city government occasionally replaces the tiles in the street. However, the letter tiles are in high demand, so the government has only M different tile patterns available. The i^{th} tile pattern consists of Li letters. A tile cannot be rotated or broken into pieces, and it can only be placed such that the tile letters coincide with the contiguous letter subsequence in the street. Tiles can overlap and we can use multiple tiles of the same pattern. A street cell is untileable if it cannot be covered by any tile. Compute the number of untileable cells.

Input

The first line of input contains the positive integer N ($1 \le N \le 300,000$), the length of the street. The second line of input contains N lowercase English letters, the letter sequence in the street. The third line of input contains the positive integer M ($1 \le M \le 5000$), the number of tile patterns. Each of the next M lines contains a description of a tile pattern with length Li ($1 \le Li \le 5000$). The tile pattern descriptions consist of lowercase English letters.

Output

The first and only line of output must contain the required number of untileable cells.

Example 1

Input
6
abcbab
2
cb
cbab
Output
2

Example 2

Input
4
abab
2
bac
baba
Output
4

Example 3

Input
6
abcabc
2
abca
cab
Output
1
Source
COCI 2011/2012 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code