#P4595. [COCI 2011/2012 #5] POPLOČAVANJE

[COCI 2011/2012 #5] POPLOČAVANJE

Description

There is a street consisting of NN lowercase English letters. The city government occasionally replaces the tiles on the street. However, letter tiles are in high demand, so the government only has MM kinds of letter tiles to choose from.

The pattern of the ii-th tile consists of LiL_{i} letters. Tiles cannot be rotated or broken, and they can only be placed where the tile’s letters exactly match a contiguous substring of letters on the street.

Tiles may overlap, and multiple tiles with the same pattern may be used. If a street cannot be covered by any tiles, then it is bad.

Find how many bad streets there are.

Input Format

The first line contains an integer NN, the number of letters on the street.

The second line contains NN lowercase letters, the sequence on the street.

The third line contains an integer MM, the number of tiles.

The next MM lines each contain LiL_{i} lowercase letters, describing the pattern of that tile.

Output Format

Print one line with an integer, the number of bad streets.

6
abcbab
2
cb
cbab
2
4
abab
2
bac
baba
4
6
abcabc
2
abca
cab
1

Hint

Constraints: 1N3×1051\le N\le 3\times 10^{5}, 1M5×1031\le M\le 5\times 10^{3}, 1Li5×1031\le L_{i}\le 5\times 10^{3}.

Translated from COCI 2011/2012 #5 T6.

Translated by ChatGPT 5