Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
D = list(map(int, input().split()))
D.sort()
M = int(input())
T = list(map(int, input().split()))
for i in range(M):
    t = T[i]
    idx = min(bisect.bisect_left(D, t), len(D) - 1)
    d = D[idx]
    if t == d:
        D.pop(idx)
    else:
        print('NO')
        exit()
print('YES')



Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
D_dict = defaultdict(int)
for d in D:
    D_dict[d] += 1
M = int(input())
T = list(map(int, input().split()))
T_dict = defaultdict(int)
for t in T:
    T_dict[t] += 1

for target, t_cnt in T_dict.items():
    d_cnt = D_dict[target]
    if t_cnt > d_cnt:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
D = list(map(int, input().split()))
D.sort()
M = int(input())
T = list(map(int, input().split()))
for i in range(M):
    t = T[i]
    idx = min(bisect.bisect_left(D, t), len(D) - 1)
    d = D[idx]
    if t == d:
        D.pop(idx)
    else:
        print('NO')
        exit()
print('YES')



Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
D_dict = defaultdict(int)
for d in D:
    D_dict[d] += 1
M = int(input())
T = list(map(int, input().split()))
T_dict = defaultdict(int)
for t in T:
    T_dict[t] += 1

for target, t_cnt in T_dict.items():
    d_cnt = D_dict[target]
    if t_cnt > d_cnt:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
D = list(map(int, input().split()))
D.sort()
M = int(input())
T = list(map(int, input().split()))
for i in range(M):
    t = T[i]
    for j in range(N):
        idx = min(bisect.bisect_left(D, t), len(D) - 1)
        d = D[idx]
        if t == d:
            D.pop(idx)
            break
    else:
        print('NO')
        exit()
print('YES')


Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
D_dict = defaultdict(int)
for d in D:
    D_dict[d] += 1
M = int(input())
T = list(map(int, input().split()))
T_dict = defaultdict(int)
for t in T:
    T_dict[t] += 1

for target, t_cnt in T_dict.items():
    d_cnt = D_dict[target]
    if t_cnt > d_cnt:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
D_flags = [True] * N
for i in range(M):
    t = T[i]
    for j in range(N):
        d = D[j]
        if t == d and D_flags[j]:
            D_flags[j] = False
            break
    else:
        print('NO')
        exit()
print('YES')

Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
D_dict = defaultdict(int)
for d in D:
    D_dict[d] += 1
M = int(input())
T = list(map(int, input().split()))
T_dict = defaultdict(int)
for t in T:
    T_dict[t] += 1

for target, t_cnt in T_dict.items():
    d_cnt = D_dict[target]
    if t_cnt > d_cnt:
        print('NO')
        exit()
print('YES')