Store the species numbers of butterflies in a set . Then, to determine whether a butterfly of species is in Andrey Sergeevich's collection, simply check whether belongs to the set .
Algorithm implementation
Store all butterfly species numbers from the collection in the set .
set<int> s;Read the input data.
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &x);
s.insert(x);
}Process queries.
scanf("%d", &m);
for (i = 0; i < m; i++)
{Check whether a butterfly of species is in the collection. The answer is "YES" if the number is present in the set .
scanf("%d", &x);
if (s.find(x) != s.end()) puts("YES");
else puts("NO");
}Python implementation
Read the input data.
n = int(input())
lst = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))Store all butterfly species numbers from the collection in the set .
s = set(lst)Process queries.
for x in q:Check whether a butterfly of species is in the collection. The answer is "YES" if the number is present in the set .
if x in s:
print("YES")
else:
print("NO")