Problem:
Set Union Find the union of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. Input The input is given in the following format. $n$
$a_0 \; a_1 \; ... \; a_{n-1}$
$m$
$b_0 \; b_1 \; ... \; b_{m-1}$ Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. Output Print elements in the union in ascending order. Print an element in a line. Constraints  $1 \leq n, m \leq 200,000$  $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$  $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$  Sample Input 1 3
1 5 8
2
5 9 Sample Output 1 1
5
8
9

Solution (Python):









import os
import sys




def main():
    n=int(input())
    a=list(map(int,input().split()))
    m=int(input())
    b=list(map(int,input().split()))
    c=a+b
    c=list(set(c))
    c.sort()
    for ab in c:
        print(ab)


if __name__ == "__main__":
    main()

Solution (Python):
input()
a = set(list(map(int,input().split())))
input()
b = set(list(map(int,input().split())))

for i in sorted(a|b):
    print(i)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
c = sorted(set(a)|set(b))
for d in c:print (d)

Solution (Python):
n = int(input())
a = set(map(int, input().split()))
m = int(input())
b = set(map(int, input().split()))
for i in sorted(a | b):
    print(i)

Solution (Python):
n = int(input())
a = set(map(int,input().split()))
m = int(input())
b = set(map(int,input().split()))
c = a | b
c = list(c)
c.sort()


for i in c:
    print(i,sep="\n")

Solution (Python):
n = int(input())
a = set(map(int, input().split()))
m = int(input())
b = set(map(int, input().split()))
s_union = a.union(b)
print(*sorted(s_union), sep="\n")

Solution (Python):
n = int(input())
A = set(list(map(int, input().split())))
m = int(input())
B = set(list(map(int, input().split())))

answer = A.union(B)
[print(i) for i in sorted(answer)]

Solution (Python):
setA = set()
while True:
    try:
        a = input()
        s = set(map(int, input().split()))
        setA = setA.union(s)
    except EOFError:
        break

for elem in sorted(setA):
    print(elem)

Solution (Python):
input()
a = set(map(int, input().split()))
input()
b = set(map(int, input().split()))
print("\n".join(map(str, sorted(list(a.union(b))))))

Solution (Python):
def main():
    n = int(input())
    a = set([int(a) for a in input().split()])
    m = int(input())
    b = set([int(a) for a in input().split()])

    c = a.union(b)
    sorted_c = sorted(c)
    for i in sorted_c:
        print(i)
main()

Solution (Python):
a=int(input())
a_li=list(map(int, input().split()))
b=int(input())
b_li=list(map(int, input().split()))
answer=sorted(set(a_li+b_li))
ans=[print(i) for i in answer]

Solution (Python):
n=int(input())
a=set(int(i) for i in input().split())
m=int(input())
b=set(int(i) for i in input().split())
for i in sorted(a|b):
    print(i)

Solution (Python):
input()
L = [int(x) for x in input().split()]
input()
Q = [int(x) for x in input().split()]


for i in sorted(set(L)|set(Q)):
    print(i)

Solution (Python):
n = int(input())
nums = set(map(int, input().split()))
m = int(input())
nums.update(set(map(int, input().split())))

for n in sorted(nums): print(n)

Solution (Python):

n = int(input())
a = set(map(int, input().split( )))
m = int(input())
b = set(map(int, input().split( )))
sm = a|b

ans = list(sm)
ans.sort()

for i in ans:
    print(i)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = set(map(lambda x: int(x), input().split()))
    m = int(input())
    b = set(map(lambda x: int(x), input().split()))

    for elem in sorted(a.union(b)):
        print(elem)

Solution (Python):
n = int(input())
alist = list(map(int, input().split()))
m = int(input())
blist = list(map(int, input().split()))

anslist = alist + blist
anslist = list(set(anslist))
anslist.sort()

for ans in anslist:
    print(ans)

Solution (Python):

"""
Set Operation - Set Union
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_9_A&lang=jp

"""
_ = input()
A = set([int(a) for a in input().split()])
_ = input()
B = set([int(b) for b in input().split()])
print(*sorted(A | B), sep='\n')

Solution (Python):
N = int(input())
A = set(map(int, input().split()))
M = int(input())
B = set(map(int, input().split()))
print(*sorted(A | B), sep = '\n')

Solution (Python):
if __name__ == '__main__':

	input()
	A = set(map(int,input().split()))
	input()
	B = set(map(int,input().split()))

	C = sorted(A|B)

	for i in C:
		print(i)

Solution (Python):
n=int(input())
a=set(map(int,input().split()))
m=int(input())
b=set(map(int,input().split()))
if a|b:
  print(*sorted(a|b),sep='\n')

Solution (Python):
n = int(input())

A = set(map(int, input().split()))

m = int(input())

B = set(map(int, input().split()))



for c in sorted(list(A | B)):
    print(c)

Solution (Python):
input()
a = set(list(map(int,input().split())))
input()
b = set(list(map(int,input().split())))
ans = a|b
ans = sorted(list(ans))
for i in ans:
    print(i)

Solution (Python):
n = int(input())
A = set(map(int, input().split()))
m = int(input())
B = set(map(int, input().split()))
print(*sorted(A | B), sep='\n')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))

m=int(input())
B=list(map(int,input().split()))

C=list(set(A)|set(B))
C.sort()
print('\n'.join(map(str,C)))

Solution (Python):
input()
A = set(int(x) for x in input().split())
input()
B = set(int(x) for x in input().split())

for i in sorted(A | B):
    print(i)

Solution (Python):
input()
s1 = list(map(int, input().split()))
input()
s2 = list(map(int, input().split()))

s = sorted(list(set(s1+s2)))

print('\n'.join(map(str, s)))

Solution (Python):
n = int(input())
alist = list(map(int, input().split()))
m = int(input())
blist = list(map(int, input().split()))

anslist = alist + blist
anslist = list(set(anslist))
anslist.sort()

for ans in anslist:
    print(ans)

Solution (Python):
N = int(input())
A = set(map(int, input().split()))
M = int(input())
B = set(map(int, input().split()))
print(*sorted(A | B), sep='\n')

Solution (Python):




def union(n, m, a, b):
    i, j = 0, 0
    while i < n and j < m:
        if a[i] < b[j]:
            yield a[i]
            i += 1
        elif a[i] > b[j]:
            yield b[j]
            j += 1
        else:
            yield a[i]
            i += 1
            j += 1

    while i < n:
        yield a[i]
        i += 1
    while j < m:
        yield b[j]
        j += 1


def run():
    n = int(input())
    a = [int(i) for i in input().split()]
    m = int(input())
    b = [int(j) for j in input().split()]

    for v in union(n, m, a, b):
        print(v)


if __name__ == '__main__':
    run()

Solution (Python):
n = int(input())
a = set(list(map(int, input().split())))
m = int(input())
b = set(list(map(int, input().split())))
for i in sorted(a|b):
    print(i)