Generalized array merging with duplicate removal

TypeScript Easy generics

Task «Generalized array merging with duplicate removal»

Write a generic function `mergeUnique` that takes two arrays of the same type and returns a new array containing all unique elements from both arrays in the order of their first appearance. The type of elements can be any (numbers, strings, etc.). The function must work correctly with primitive types. Ensure that the order of elements is preserved and duplicates are removed.

Input Format

First line: the number of elements in the first array N. Second line: N elements separated by spaces. Third line: the number of elements in the second array M. Fourth line: M elements separated by spaces.

Output Format

Elements of the resulting array separated by spaces.

Examples

Example 1

INPUT
4 9 99 999 9999
OUTPUT
9 99 999 9999

Example 2

INPUT
11 20
OUTPUT
11 20

Example 3

INPUT
2 2
OUTPUT
2
main.ts