#C14883. Merge Sorted Lists with Invalid Data

    ID: 44581 Type: Default 1000ms 256MiB

Merge Sorted Lists with Invalid Data

Merge Sorted Lists with Invalid Data

Given two sorted lists of numbers, merge them into one sorted list. Each list is provided along with its size, followed by the list tokens separated by spaces. Some tokens may not be valid integers and should be ignored. The final merged list must be in non-decreasing order. In this problem, a sorted list satisfies the condition \(a_i \le a_{i+1}\) for every adjacent pair of elements. Use an efficient merging algorithm to combine the two valid sequences.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains a positive integer n, the number of tokens in the first list.
  2. The second line contains n space-separated tokens, which may be valid integers or invalid data.
  3. The third line contains a positive integer m, the number of tokens in the second list.
  4. The fourth line contains m space-separated tokens, similarly containing valid integers or invalid data.

outputFormat

Output the merged sorted list of all valid integers. Each integer should be printed on a new line to standard output (stdout).

## sample
4
1 3 5 7
4
2 4 6 8
1

2 3 4 5 6 7 8

</p>