Problem: 2061D - Kevin and Numbers
Language: python

Code 1:
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([i for i in b])

        a.sort()

        q = []

        for i in a:

            #q.append(i)

            heappush(q,i)

        cnt = 0

        while q and cnt<n-m:

            #print(q)

            x = heappop(q)

            if db[x]>=1 or (not q) or abs(x-q[0])>1:

                db[x] -= 1

                continue

            y = 0

            if q:

                y = heappop(q)

            else:

                break

            if db[x+y]>=1:

                db[x+y] -= 1

                cnt += 1

                continue

            else:

                heappush(q,x+y)

                cnt += 1

        while q:

            x = heappop(q)

            db[x] -= 1

        #print(db)

        flag = False

        for i,x in db.items():

            if x!=0:

                flag = True

                break

        if flag==False:

            print('Yes')

        else:

            print('No')

    





if __name__ == '__main__':

    main()

Code 2:
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()

Answer: 2