#P2875. Deciphering the Cowmunication

    ID: 16133 Type: Default 1000ms 256MiB

Deciphering the Cowmunication

Deciphering the Cowmunication

The cows have their own dictionary of words and a garbled message received through their imperfect mooing communication system. You are given a dictionary containing \(W\) words (where \(1 \le W \le 600\); each word has no more than 25 characters from 'a' to 'z') and a garbled message of length \(L\) (where \(2 \le L \le 300\)) consisting only of lower-case letters. The message has extra letters inserted by noise. Your task is to remove the minimum number of letters so that the remaining message becomes a sequence of words from the dictionary.

For example, if the dictionary includes the words "brown", "cow", and "moocow", and the received message is "browndcow", then by removing the extra letter 'd', the intended message "browncow" is obtained.

inputFormat

The input begins with an integer \(W\), the number of words in the dictionary.

Then follow \(W\) lines, each containing one dictionary word (composed only of lowercase letters).

The last line of the input contains the garbled message (a string of lowercase letters).

outputFormat

Output a single integer denoting the minimum number of letters that must be removed so that the message becomes a valid sequence of words from the dictionary.

sample

3
brown
cow
moocow
browndcow
1