Problem: 2061D - Kevin and Numbers
Language: python

Solution 1 (runtime: 1577 ms):
def diff_elements(l1, l2):
    l1.sort()
    l2.sort()
    j = 0
    k = 0
    L1 = []
    L2 = []
    
    while j < len(l1) and k < len(l2):
        if l1[j] == l2[k]:
            j += 1
            k += 1
        elif l1[j] > l2[k]:
            L2.append(l2[k])
            k += 1
        else:
            L1.append(l1[j])
            j += 1
    
    # Add remaining elements in l1 or l2
    if j < len(l1):
        L1.extend(l1[j:])
    if k < len(l2):
        L2.extend(l2[k:])
    
    return L1, L2

for i in range(int(input())):  # Iterate over multiple test cases
    # Reading the input lists
    l = list(map(int, input().split()))  # This is not being used in the logic.
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
 
    # Sort both lists
    l1.sort()
    l2.sort()
    
    L1, L2 = diff_elements(l1, l2)
    
    # Print the differences between lists
    #print(L1)
    #print(L2)
    
    if sum(L1) != sum(L2):
        print("no")
    else:
        a = L1[0] if len(L1) > 0 else 1  # Default to 1 if L1 is empty
        b = L2[0] if len(L2) > 0 else 0  # Default to 0 if L2 is empty
        
        # While loop to adjust elements if needed
        while b >= a or len(L2) < len(L1):
            h = []
            for s in L2:
                if s % 2 == 0:
                    h.append(s // 2)
                    h.append(s // 2)
                else:
                    h.append(s // 2)
                    h.append((s // 2) + 1)
            
            L1, L2 = diff_elements(L1, h)
            
            a = L1[0] if len(L1) > 0 else 1
            b = L2[0] if len(L2) > 0 else 0
        
        # Final check for equality of differences
        L1, L2 = diff_elements(L1, L2)
        
        if len(L1) == 0 and len(L2) == 0:
            print("yes")
        else:
            print("no")


Solution 2 (runtime: 921 ms):
import sys
from collections import Counter
from heapq import heapify, heappop, heappush

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def cud(n, d):
    if d.get(str(n),0):
        d[str(n)] -= 1
        return True
    if n == 1:
        return False
    return cud(n // 2, d) and cud((n // 2) + (n&1),d)
    

def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    b = sorted(B, reverse=True)
    
    d = {}
    for i in A:
        i = str(i)
        d[i] = d.get(i,0) + 1
        
    for i in b:
        if not cud(i, d):
            P1('No')
            return
        
        
        
    #print(d)
    if any(d.values()):
        P1('No')
    else:
        P1('Yes')
        
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))