Generalized iterator for merging sorted collections

TypeScript Hard generics

Task «Generalized iterator for merging sorted collections»

Implement a generic function `mergeSorted` that takes an array of iterators (each returning sorted values of the same type) and returns a new iterator that yields all values in ascending order. The value type must be parameterized and support comparison using the `<` operator. Use TypeScript generics. Constraints: values are unique, the number of iterators is from 1 to 1000, and the length of each iterator is up to 10^5.

Input Format

First line: number N (number of iterators). Next N lines: each contains numbers separated by spaces — elements of one iterator (already sorted in ascending order).

Output Format

A string with numbers separated by spaces — all elements from all iterators in ascending order.

Examples

Example 1

INPUT
3 -2 10 -5
OUTPUT
-2 10 -5
main.ts