#C13340. Merge Two Lists Alternately

    ID: 42868 Type: Default 1000ms 256MiB

Merge Two Lists Alternately

Merge Two Lists Alternately

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

The merging process can be summarized by the following formula in LaTeX:

$$merged = \begin{cases} \text{list1}[i] & \text{if } i \text{ is even}\\ \text{list2}[i] & \text{if } i \text{ is odd} \end{cases} $$

Note that the above pseudo-formula illustrates the alternating merge. More precisely, if the two lists are \(L_1 = [a_1,a_2,\dots,a_m]\) and \(L_2 = [b_1,b_2,\dots,b_n]\), then the merged list is:

$$merged = [a_1, b_1, a_2, b_2, \dots, a_{\min(m,n)}, b_{\min(m,n)}] \cup \text{remaining elements} $$

Your program should read its input from stdin and print the result to stdout.

inputFormat

The input consists of two lines:

  1. The first line contains a list of elements separated by spaces representing the first list. An empty line indicates an empty list.
  2. The second line contains a list of elements separated by spaces representing the second list. An empty line indicates an empty list.

Elements can be numbers or strings.

outputFormat

Output a single line containing the merged list with its elements separated by a single space. The elements should be merged alternately; if one list has extra elements, they appear at the end.

## sample
1 2 3 4
a b c d
1 a 2 b 3 c 4 d