Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 

Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton.
Chef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and was able to build a map of relationships between them. He knows that a mafia's organizational structure consists of a single Don, heading a hierarchical criminal organization. Each member reports exactly to one other member of the clan. It's obvious that there are no cycles in the reporting system of the mafia.
There are N people in the clan, for simplicity indexed from 1 to N, and Chef knows who each of them report to. Member i reports to member R_{i}.
Now, Chef needs to identfy all potential killers to continue his investigation. Having considerable knowledge about the mafia's activities, Chef knows that the killer must be a minor criminal, that is, one of the members who nobody reports to. Please find the list of potential killers for Chef. Since Don reports to nobody, his R_{i} will be equal to 0.

------ Input ------ 

The first line of input contains one integer N.
Next line has N space-separated integers, the i^{th} integer denotes R_{i} — the person whom the i^{th} member reports to.

------ Output ------ 

Output a list of space-separated integers in ascending order — the indices of potential killers.

------ Constraints ------ 

$1 ≤ N ≤ 10^{5}$
$1 ≤ R_{i} ≤ N except for Don, whose R_{i} equals to 0.$
$It is guaranteed that there are no cycles in the reporting structure.$

------ Subtasks ------ 

$Subtask #1 [50 points]: N ≤ 10000$
$Subtask #2 [50 points]: No additional constraints$

----- Sample Input 1 ------ 
6

0 1 1 2 2 3
----- Sample Output 1 ------ 
4 5 6
----- explanation 1 ------ 
The reporting structure:

Source: codechef | Difficulty: EASY
Tags: Data structures

Implementation

Complete search


Solutions:
n = int(input())
m = list(map(int, input().split()))
m = set(m)
p = set(range(n + 1))
a = p - m
for i in a:
	print(i, end=' ')


n = int(input())
r = list(map(int, input().split(' ')))
r = set(r)
result = ''
for ele in range(1, n + 1):
	if ele not in r:
		result += f'{ele} '
print(result)


n = int(input())
p = list(map(int, input().split()))
p1 = set(p)
h = []
for j in range(1, n + 1):
	if j not in p1:
		h.append(j)
print(*h)


n = int(input())
l = list(map(int, input().split()))
ans = set(l)
for i in range(1, n + 1):
	if i not in ans:
		print(i, end=' ')


t = int(input())
l = list(map(int, input().split()))
m = set(l)
for i in range(1, t + 1):
	if i not in m:
		print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
l1 = set(l)
r = []
for i in range(n + 1):
	if i not in l1:
		r.append(i)
for i in range(len(r)):
	print(r[i], end=' ')


n = int(input())
l = [int(i) for i in input().split()]
s = set(range(n + 1)) - set(l)
for i in s:
	print(i, end=' ')


kmap = set()
n = int(input())
arr = list(map(int, input().split()))
for ele in arr:
	if ele not in kmap:
		kmap.add(ele)
res = []
for i in range(n + 1):
	if i not in kmap:
		res.append(i)
print(*res)


n = int(input())
arr = set(map(int, input().split(' ')))
out = set((i for i in range(n + 1)))
print(' '.join(map(str, out - arr)))


n = int(input())
arr = set(map(int, input().split()))
criminal = set(range(1, n + 1))
l = criminal - arr
print(' '.join(map(str, l)))


n = int(input())
l = [int(x) for x in input().split()]
c = [0] * (n + 1)
for i in l:
	c[i] += 1
for i in range(n + 1):
	if c[i] == 0:
		print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
s = set(a)
d = []
p = set(range(n + 1))
m = p - s
for j in m:
	d.append(j)
print(*d)


N = int(input())
A = list(map(int, input().split()))
A1 = set(A)
S = []
for i in range(1, N + 1):
	if i not in A1:
		S.append(i)
S.sort()
for j in S:
	print(j, end=' ')


n = int(input())
r = list(map(int, input().split()))
s = set(r)
ans = []
for i in range(0, n + 1):
	if i not in s:
		ans.append(i)
ans.sort()
for i in ans:
	print(i, end=' ')


n = int(input())
r = set(map(int, input().split()))
l = [x for x in range(1, n + 1)]
for j in l:
	if not j in r:
		print(j, end=' ')


n = int(input())
r = list(map(int, input().split()))
r = set(r)
lst = ''
for i in range(1, n + 1):
	if i not in r:
		lst += f'{i} '
print(lst)


n = int(input())
l = list(map(int, input().split()))
vis = [0] * n
ans = []
for i in range(n):
	if l[i]:
		vis[l[i] - 1] += 1
for i in range(n):
	if vis[i] == 0:
		ans.append(i + 1)
for I in ans:
	print(I, end=' ')


n = int(input())
r = list(map(int, input().split()))
r = set(r)
l = set(range(n + 1))
a = l - r
for i in a:
	print(i, end=' ')


n = set([i + 1 for i in range(int(input()))])
a = set([int(x) for x in input().split()])
b = sorted(list(n - a))
print(*b)


n = int(input())
r = set(map(int, input().split()))
for i in range(1, n + 1):
	if i not in r:
		print(i, end=' ')


n = int(input())
m = list(map(int, input().split()))
l = set(m)
for j in range(n + 1):
	if j not in l:
		print(j, end=' ')


n = int(input())
l = list(map(int, input().split()))
arr = [0 for i in range(10 ** 5 + 1)]
ans = []
for i in l:
	arr[i] += 1
for i in range(1, n + 1):
	if arr[i] == 0:
		ans.append(i)
for i in range(len(ans)):
	print(ans[i], end=' ')


x = int(input())
l = list(map(int, input().split()))
l = set(l)
for i in range(1, x + 1):
	if i not in l:
		print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
s = set(l)
a = []
for i in range(1, n + 1):
	if i not in s:
		a.append(i)
print(*a)


n = int(input())
arr = set([int(i) for i in input().split()])
d = []
for i in range(1, n + 1):
	if i not in arr:
		d.append(str(i))
print(' '.join(d))


n = int(input())
l = list(map(int, input().split()))
m = [i + 1 for i in range(n)]
l.remove(0)
print(*set(l).symmetric_difference(set(m)))


a = int(input())
l = list(map(int, input().split()))
n = ''
y = set(l)
for i in range(1, a + 1):
	if i not in y:
		n += str(i) + ' '
print(n[:len(n) - 1])


n = int(input())
arr = list(map(int, input().split()))
graph = {i: 0 for i in range(n + 1)}
for i in range(len(arr)):
	graph[arr[i]] += 1
for (i, j) in graph.items():
	if j == 0 and i != 0:
		print(i, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr = set(arr)
for i in range(1, n + 1):
	if i not in arr:
		print(i, end=' ')


n = int(input())
r = [int(i) for i in input().split()]
r = set(r)
x = []
for i in range(1, n + 1):
	if i not in r:
		x.append(i)
print(*x)


n = int(input())
r = list(map(int, input().split()))
rs = set(r)
b = []
for i in range(n):
	if i + 1 not in rs:
		b.append(i + 1)
for j in b:
	print(j, end=' ')


n = int(input())
r = list(map(int, input().split()))
refs = [0] * (n + 1)
for v in r:
	if v > 0:
		refs[v] += 1
for i in range(1, n + 1):
	if refs[i] == 0:
		print(i, end=' ')
print()


n = int(input())
li = set([int(x) for x in input().split()])
for i in range(n + 1):
	if i not in li:
		print(i, end=' ')


N = int(input())
arr = [int(ele) for ele in input().split()]
a = [ele for ele in range(N + 1)]
ans = list(set(a) - set(arr))
for ele in ans:
	print(ele, end=' ')
print()


n = int(input())
l = list(map(int, input().split()))
p = list(set(range(n + 1)) - set(l))
for i in p:
	print(i, end=' ')


ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
si = lambda : input()
ssi = lambda : list(input())
sepi = lambda : map(int, input().split())
sizeOfClan = ii()
reports = set(li())
clanMembers = range(1, sizeOfClan + 1)
potentialKillers = [suspect for suspect in clanMembers if suspect not in reports]
print(*potentialKillers)