#B4086. Identifying Disqualified Teams from Pig Competition

    ID: 11743 Type: Default 1000ms 256MiB

Identifying Disqualified Teams from Pig Competition

Identifying Disqualified Teams from Pig Competition

In the XCPC competition, there are n teams of pig enthusiasts. Each team has a unique name given as \(s_i\) for the \(i^{th}\) team.

The teams must have their names approved by the organizers. The judges maintain a dictionary of m strings, where the \(j^{th}\) string is \(t_j\). A team name is considered violating if there exists a contiguous substring \(k\) in \(s_i\) such that \(k = t_j\) for some \(j\) (i.e. \(t_j\) is a substring of \(s_i\)).

Your task is to determine which teams will be contacted for disqualification (i.e. withdrawal). The output should list the team names (in the same order as input) that contain at least one forbidden substring.

Note: When a team name matches any string from the dictionary as a contiguous substring, it is considered as violative.

inputFormat

The input is given in the following format:

n m
s_1
s_2
... 
s_n
t_1
t_2
... 
t_m

Where:

  • n is the number of teams.
  • m is the number of forbidden substrings in the dictionary.
  • Each s_i is the name of the \(i^{th}\) team.
  • Each t_j is one forbidden substring.

outputFormat

Output all team names that are in violation, each on a new line in the order they appear in the input. If no team violates the rules, the output should be empty.

sample

3 1
apple
banana
apricot
app
apple

</p>