#C13554. Common Strings Intersection

    ID: 43105 Type: Default 1000ms 256MiB

Common Strings Intersection

Common Strings Intersection

You are given three lists of strings. Your task is to find all strings that are present in all three lists. The returned list should satisfy two conditions:

  1. It should include each common string only once (i.e. no duplicates).
  2. It must maintain the order of the first appearance of each string in the first list.

Mathematically, if A, B, and C denote the three lists, you need to output

$$result = \{x \in A \mid x \in B \; \text{and} \; x \in C\} $$

Ensure that your solution reads input from stdin and writes output to stdout.

inputFormat

The input is given via standard input and has the following format:

  • The first line contains an integer n, representing the number of elements in the first list (A).
  • The second line contains n space-separated strings (elements of list A).
  • The third line contains an integer m, representing the number of elements in the second list (B).
  • The fourth line contains m space-separated strings (elements of list B).
  • The fifth line contains an integer k, representing the number of elements in the third list (C).
  • The sixth line contains k space-separated strings (elements of list C).

outputFormat

Print a single line containing the common strings found in all three lists in the order of their first occurrence in A, separated by a space. If there are no common strings, output an empty line.## sample

3
a b c
3
b a c
3
c a b
a b c

</p>