#K68992. Alternate Merging of Two Lists

    ID: 32987 Type: Default 1000ms 256MiB

Alternate Merging of Two Lists

Alternate Merging of Two Lists

You are given two lists of integers. Your task is to merge these two lists by taking elements alternately from each list. If one list is longer than the other, append the remaining elements from the longer list at the end.

Formally, given two lists \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\), the merged list \(C\) is defined as:

[ C = [a_1, b_1, a_2, b_2, \dots, a_{\min(n,m)}, b_{\min(n,m)}] \cup \begin{cases} [a_{\min(n,m)+1}, \dots, a_n] & \text{if } n > m \ [b_{\min(n,m)+1}, \dots, b_m] & \text{if } m > n \end{cases} ]

It is guaranteed that each list contains zero or more integers. Read the lists from standard input and print the merged list to standard output in one line with integers separated by a single space.

inputFormat

The input consists of two lines:

  • The first line contains zero or more integers separated by spaces representing the first list.
  • The second line contains zero or more integers separated by spaces representing the second list.

outputFormat

Output the merged list in one line. The numbers should be separated by a single space.

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