#C12660. List Intersection

    ID: 42112 Type: Default 1000ms 256MiB

List Intersection

List Intersection

You are given two lists of integers. Your task is to compute their intersection, i.e. the set of numbers that appear in both lists. Each number should appear in the resulting output only once, even if it occurs multiple times in the input lists. The result must be sorted in ascending order.

Mathematically, if we denote the two lists as \(A\) and \(B\), the intersection is defined as:

[ A \cap B = {x \mid x \in A \text{ and } x \in B} ]

Note: You must not use built-in set operations for this task. The input should be read from standard input and output should be written to standard output.

inputFormat

The input is provided via standard input in the following format:

  • The first line contains an integer \(n\), denoting the number of elements in the first list.
  • The second line contains \(n\) space-separated integers.
  • The third line contains an integer \(m\), denoting the number of elements in the second list.
  • The fourth line contains \(m\) space-separated integers.

outputFormat

Output a single line containing the intersection of the two lists as space-separated integers in ascending order. If there is no common element, output an empty line.

## sample
3
4 9 5
5
9 4 9 8 4
4 9