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: 640 ms):
import sys

import string

import math

import array

import bisect

from heapq import heappop,heappush

from functools import lru_cache,cache

from collections import deque,defaultdict,Counter

from itertools import permutations,combinations

#sys.setrecursionlimit(10**5)

input = sys.stdin.readline

printf = lambda x:sys.stdout.write(x)



INF = 10**15



RI = lambda: int(sys.stdin.readline())

RF = lambda: float(sys.stdin.readline())

RS = lambda: sys.stdin.readline().strip()

RFF = lambda: map(float, sys.stdin.readline().split())

RII = lambda: map(int, sys.stdin.readline().split())

RSS = lambda: map(str, sys.stdin.readline().strip().split())

RIL = lambda: list(RII())

RFL = lambda: list(RFF())

RSL = lambda: list(RSS())



from types import GeneratorType

def bootstrap(f, stack=[]):

    def wrappedfunc(*args, **kwargs):

        if stack:

            return f(*args, **kwargs)

        else:

            to = f(*args, **kwargs)

            while True:

                if type(to) is GeneratorType:

                    stack.append(to)

                    to = next(to)

                else:

                    stack.pop()

                    if not stack:

                        break

                    to = stack[-1].send(to)

            return to



    return wrappedfunc



def main():

    test = RI()

    

    for i in range(test):

        n,m = RII()

        a = RIL()

        b = RIL()

        #db = Counter(b)

        #a.sort()

        da = Counter([str(i) for i in a])

        

        # @bootstrap

        # def dp(i):

        #     if i==1:

        #         da[i] -= 1

        #         yield None

        #     if da[i]>=1:

        #         da[i] -= 1

        #         yield None

        #     x = i//2

        #     y = x+i%2

        #     yield dp(x)

        #     yield dp(y)

        #     yield None

        cnt = 0

        @bootstrap

        def dp(i):

            nonlocal cnt

            if cnt>=n:

                da[str(0)] -= 1

                yield None

            if i==1:

                da[str(i)] -= 1

                cnt += 1

                yield None

            if da[str(i)]>=1:

                da[str(i)] -= 1

                cnt += 1

                yield None

            x = i//2

            y = x+i%2

            yield dp(x)

            yield dp(y)

            yield None

        

        for i in b:

            dp(i)

        #print(da)

        flag = True

        for x in da.values():

            if x!=0:

                flag = False

                break

        

        if flag==True:

            print('Yes')

        else:

            print('No')    





if __name__ == '__main__':

    main()