505. Prefixes and suffixes
Time limit per test: 0.75
Memory limit: 262144
Andrew has just made a breakthrough in biology: he realized that
most of genome's characteristics are determined by the absence
or presence of certain prefixes and suffixes. So he needs to quickly
test large arrays of genomes for that.
More formally, we represent the genome as a string of lowercase English
letters. We are given several genomes, and need to answer the following
type of question: how many genomes from the given set have the given
the given string s
The first line of the input file contains an integer n
the number of genomes.
The next n
lines contain a non-empty
string of lowercase
English letters each, representing the given genomes. The total length
of all given genomes doesn't exceed
The next line contains an integer m
— the number of questions to answer.
The next m
lines contain two non-empty strings of lowercase English letters
first denoting the prefix and the second denoting the suffix. The prefix and
suffix are separated with a single space. The total length of all given
prefixes plus the total length of all given suffixes doesn't exceed
integers one per line. i
-th output line should contain the
number of genomes that have i
-th given prefix and i
-th given suffix.