#C14136. Common Elements in Two Sets

    ID: 43752 Type: Default 1000ms 256MiB

Common Elements in Two Sets

Common Elements in Two Sets

You are given two sets of integers. Your task is to compute the common elements in these two sets and output them in ascending order. If there are no common elements, output an empty line.

The input is given in four lines:

  • The first line contains an integer \( n \) indicating the number of elements in the first set.
  • The second line contains \( n \) space‐separated integers representing the first set.
  • The third line contains an integer \( m \) indicating the number of elements in the second set.
  • The fourth line contains \( m \) space‐separated integers representing the second set.

Output the common elements in ascending order separated by a single space. If there are no common elements, output an empty line.

inputFormat

The input is read from standard input (stdin). It consists of four lines:

  1. An integer ( n ) (where ( 0 \leq n \leq 10^5 )) representing the number of elements in the first set.
  2. ( n ) space-separated integers forming the first set.
  3. An integer ( m ) (where ( 0 \leq m \leq 10^5 )) representing the number of elements in the second set.
  4. ( m ) space-separated integers forming the second set.

outputFormat

Output the common elements from the two sets in ascending order separated by a single space. If there are no common elements, output an empty line. The output should be printed to standard output (stdout).## sample

3
1 2 3
3
4 5 6