Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_integer>
  MAKE_FUNCTION 0
  STORE_NAME check_integer
  RETURN_CONST None
END
CODE check_integer(text)
  MAKE_CELL text
  RESUME 0
  LOAD_DEREF text
  LOAD_ATTR NULL|self + strip
  CALL 0
  STORE_DEREF text
  LOAD_GLOBAL NULL + len
  LOAD_DEREF text
  CALL 1
  LOAD_CONST 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE text
  BUILD_TUPLE 1
  LOAD_CONST <code check_integer.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_DEREF text
  CALL 1
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
  POP_JUMP_IF_FALSE L2
  RETURN_CONST True
L2:
  LOAD_DEREF text
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST '+-'
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE text
  BUILD_TUPLE 1
  LOAD_CONST <code check_integer.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_GLOBAL NULL + len
  LOAD_DEREF text
  CALL 1
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  RETURN_CONST False
END
CODE check_integer.<locals>.<genexpr>(.0)
  DOC '0123456789'
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_DEREF text
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0123456789'
  CONTAINS_OP 0
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END
CODE check_integer.<locals>.<genexpr>(.0)
  DOC '0123456789'
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_DEREF text
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0123456789'
  CONTAINS_OP 0
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def check_integer(text):
    text = text.strip()
    if len(text) < 1:
        return None
    elif all((text[i] in '0123456789' for i in range(len(text)))):
        return True
    elif text[0] in '+-' and all((text[i] in '0123456789' for i in range(1, len(text)))):
        return True
    else:
        return False

Prompt: Write a function to check if a string represents an integer or not.

assert check_integer("python")==False
assert check_integer("1")==True
assert check_integer("12345")==True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('Counter',)
  IMPORT_NAME collections
  IMPORT_FROM Counter
  STORE_NAME Counter
  POP_TOP
  LOAD_CONST <code assign_freq>
  MAKE_FUNCTION 0
  STORE_NAME assign_freq
  RETURN_CONST None
END
CODE assign_freq(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST test_list
  CALL 1
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  LOAD_FAST_AND_CLEAR val
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST val
  BUILD_LIST 0
  LOAD_FAST key
  LIST_EXTEND 1
  LOAD_FAST val
  LIST_APPEND 1
  CALL_INTRINSIC_1 INTRINSIC_LIST_TO_TUPLE
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res
  STORE_FAST key
  STORE_FAST val
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST val
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

from collections import Counter

def assign_freq(test_list):
    res = [(*key, val) for key, val in Counter(test_list).items()]
    return str(res)

Prompt: Write a function to assign frequency to each tuple in the given tuple list.

Creative Commons Attribution 4.0 International

MBPP (Mostly Basic Python Problems), Austin et al. 2021, Google Research


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code empty_dit>
  MAKE_FUNCTION 0
  STORE_NAME empty_dit
  RETURN_CONST None
END
CODE empty_dit(list1)
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_CONST <code empty_dit.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST list1
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST empty_dit
  LOAD_FAST empty_dit
  RETURN_VALUE
END
CODE empty_dit.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST d
  LOAD_FAST d
  UNARY_NOT
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def empty_dit(list1):
    empty_dit = all((not d for d in list1))
    return empty_dit

Prompt: Write a function to check whether all dictionaries in a list are empty or not.

assert empty_dit([{},{},{}])==True
assert empty_dit([{1,2},{},{}])==False
assert empty_dit({})==True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code tuple_to_int>
  MAKE_FUNCTION 0
  STORE_NAME tuple_to_int
  RETURN_CONST None
END
CODE tuple_to_int(nums)
  RESUME 0
  LOAD_GLOBAL NULL + int
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL str
  LOAD_FAST nums
  CALL 2
  CALL 1
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

def tuple_to_int(nums):
    result = int(''.join(map(str, nums)))
    return result

Prompt: Write a function to convert a given tuple of positive integers into an integer.

assert tuple_to_int((1,2,3))==123
assert tuple_to_int((4,5,6))==456
assert tuple_to_int((5,6,7))==567


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code list_to_float>
  MAKE_FUNCTION 0
  STORE_NAME list_to_float
  RETURN_CONST None
END
CODE list_to_float(test_list)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST res
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST tup
  BUILD_LIST 0
  STORE_FAST temp
  LOAD_FAST tup
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L3
  LOAD_FAST temp
  LOAD_ATTR NULL|self + append
  LOAD_FAST ele
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  LOAD_FAST temp
  LOAD_ATTR NULL|self + append
  LOAD_GLOBAL NULL + float
  LOAD_FAST ele
  CALL 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L4:
  END_FOR
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST temp
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST temp
  LOAD_CONST 1
  BINARY_SUBSCR
  BUILD_TUPLE 2
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
END

def list_to_float(test_list):
    res = []
    for tup in test_list:
        temp = []
        for ele in tup:
            if ele.isalpha():
                temp.append(ele)
            else:
                temp.append(float(ele))
        res.append((temp[0], temp[1]))
    return str(res)

Prompt: Write a function to convert all possible convertible elements in the list to float.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code search>
  MAKE_FUNCTION 0
  STORE_NAME search
  RETURN_CONST None
END
CODE search(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST XOR
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST XOR
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP ^
  STORE_FAST XOR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST XOR
  RETURN_VALUE
END

def search(arr, n):
    XOR = 0
    for i in range(n):
        XOR = XOR ^ arr[i]
    return XOR

Prompt: Write a python function to find the element that appears only once in a sorted array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_triplet>
  MAKE_FUNCTION 0
  STORE_NAME check_triplet
  RETURN_CONST None
END
CODE check_triplet(A, n, sum, count)
  RESUME 0
  LOAD_FAST count
  LOAD_CONST 3
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_FAST sum
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  LOAD_FAST count
  LOAD_CONST 3
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  LOAD_FAST sum
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_FALSE L3
L2:
  RETURN_CONST False
L3:
  LOAD_GLOBAL NULL + check_triplet
  LOAD_FAST A
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST sum
  LOAD_FAST A
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP -
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +
  CALL 4
  COPY 1
  POP_JUMP_IF_TRUE L4
  POP_TOP
  LOAD_GLOBAL NULL + check_triplet
  LOAD_FAST A
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST sum
  LOAD_FAST count
  CALL 4
L4:
  RETURN_VALUE
END

def check_triplet(A, n, sum, count):
    if count == 3 and sum == 0:
        return True
    if count == 3 or n == 0 or sum < 0:
        return False
    return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or check_triplet(A, n - 1, sum, count)

Prompt: Write a function to find the triplet with sum of the given array


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 3000
  STORE_NAME MAX
  LOAD_CONST <code smartNumber>
  MAKE_FUNCTION 0
  STORE_NAME smartNumber
  RETURN_CONST None
END
CODE smartNumber(n)
  RESUME 0
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_GLOBAL MAX
  BINARY_OP *
  STORE_FAST primes
  BUILD_LIST 0
  STORE_FAST result
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_GLOBAL MAX
  CALL 2
  GET_ITER
L1:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST primes
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_CONST 1
  LOAD_FAST primes
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP *
  STORE_FAST j
  LOAD_FAST j
  LOAD_GLOBAL MAX
  COMPARE_OP <
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST primes
  LOAD_FAST j
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP -=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  LOAD_FAST primes
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 3
  BINARY_OP +
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST j
  CALL 1
  POP_TOP
L4:
  LOAD_FAST j
  LOAD_FAST i
  BINARY_OP +
  STORE_FAST j
  LOAD_FAST j
  LOAD_GLOBAL MAX
  COMPARE_OP <
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L3
L5:
  JUMP_BACKWARD L1
L6:
  END_FOR
  LOAD_FAST result
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  LOAD_FAST result
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  RETURN_VALUE
END

MAX = 3000

def smartNumber(n):
    primes = [0] * MAX
    result = []
    for i in range(2, MAX):
        if primes[i] == 0:
            primes[i] = 1
            j = i * 2
            while j < MAX:
                primes[j] -= 1
                if primes[j] + 3 == 0:
                    result.append(j)
                j = j + i
    result.sort()
    return result[n - 1]

Prompt: Write a function to find n’th smart number.

assert smartNumber(1) == 30
assert smartNumber(50) == 273
assert smartNumber(1000) == 2664


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code amicable_numbers_sum>
  MAKE_FUNCTION 0
  STORE_NAME amicable_numbers_sum
  RETURN_CONST None
END
CODE amicable_numbers_sum(limit)
  RESUME 0
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST limit
  LOAD_GLOBAL int
  CALL 2
  POP_JUMP_IF_TRUE L1
  RETURN_CONST 'Input is not an integer!'
L1:
  LOAD_FAST limit
  LOAD_CONST 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  RETURN_CONST 'Input must be bigger than 0!'
L2:
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST amicables
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST limit
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L3:
  FOR_ITER L19
  STORE_FAST num
  LOAD_FAST num
  LOAD_FAST amicables
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L3
L4:
  LOAD_GLOBAL NULL + sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST num
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR fact
  SWAP 2
L5:
  BUILD_LIST 0
  SWAP 2
L6:
  FOR_ITER L9
  STORE_FAST fact
  LOAD_FAST num
  LOAD_FAST fact
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L8
L7:
  JUMP_BACKWARD L6
L8:
  LOAD_FAST fact
  LIST_APPEND 2
  JUMP_BACKWARD L6
L9:
  END_FOR
L10:
  SWAP 2
  STORE_FAST fact
  CALL 1
  STORE_FAST sum_fact
  LOAD_GLOBAL NULL + sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST sum_fact
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR fact
  SWAP 2
L11:
  BUILD_LIST 0
  SWAP 2
L12:
  FOR_ITER L15
  STORE_FAST fact
  LOAD_FAST sum_fact
  LOAD_FAST fact
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L14
L13:
  JUMP_BACKWARD L12
L14:
  LOAD_FAST fact
  LIST_APPEND 2
  JUMP_BACKWARD L12
L15:
  END_FOR
L16:
  SWAP 2
  STORE_FAST fact
  CALL 1
  STORE_FAST sum_fact2
  LOAD_FAST num
  LOAD_FAST sum_fact2
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L17
  JUMP_BACKWARD L3
L17:
  LOAD_FAST num
  LOAD_FAST sum_fact
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L18
  JUMP_BACKWARD L3
L18:
  LOAD_FAST amicables
  LOAD_ATTR NULL|self + add
  LOAD_FAST num
  CALL 1
  POP_TOP
  LOAD_FAST amicables
  LOAD_ATTR NULL|self + add
  LOAD_FAST sum_fact2
  CALL 1
  POP_TOP
  JUMP_BACKWARD L3
L19:
  END_FOR
  LOAD_GLOBAL NULL + sum
  LOAD_FAST amicables
  CALL 1
  RETURN_VALUE
L20:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST fact
  RERAISE 0
L21:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST fact
  RERAISE 0
  EXC try=L5..L7 -> handler=L20 depth=5 lasti=False
  EXC try=L8..L10 -> handler=L20 depth=5 lasti=False
  EXC try=L11..L13 -> handler=L21 depth=5 lasti=False
  EXC try=L14..L16 -> handler=L21 depth=5 lasti=False
END

def amicable_numbers_sum(limit):
    if not isinstance(limit, int):
        return 'Input is not an integer!'
    if limit < 1:
        return 'Input must be bigger than 0!'
    amicables = set()
    for num in range(2, limit + 1):
        if num in amicables:
            continue
        sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
        sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
        if num == sum_fact2 and num != sum_fact:
            amicables.add(num)
            amicables.add(sum_fact2)
    return sum(amicables)

Prompt: Write a function to sum all amicable numbers from 1 to a specified number.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME cmath
  STORE_NAME cmath
  LOAD_CONST <code angle_complex>
  MAKE_FUNCTION 0
  STORE_NAME angle_complex
  RETURN_CONST None
END
CODE angle_complex(a, b)
  RESUME 0
  LOAD_GLOBAL NULL + complex
  LOAD_FAST a
  LOAD_FAST b
  CALL 2
  STORE_FAST cn
  LOAD_GLOBAL NULL + cmath
  LOAD_ATTR phase
  LOAD_FAST a
  LOAD_FAST b
  BINARY_OP +
  CALL 1
  STORE_FAST angle
  LOAD_FAST angle
  RETURN_VALUE
END

import cmath

def angle_complex(a, b):
    cn = complex(a, b)
    angle = cmath.phase(a + b)
    return angle

Prompt: Write a function to get the angle of a complex number.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_length>
  MAKE_FUNCTION 0
  STORE_NAME find_length
  RETURN_CONST None
END
CODE find_length(string, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST current_sum
  LOAD_CONST 0
  STORE_FAST max_sum
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST i
  LOAD_FAST current_sum
  LOAD_FAST string
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_CONST 1
  JUMP_FORWARD L3
L2:
  LOAD_CONST -1
L3:
  BINARY_OP +=
  STORE_FAST current_sum
  LOAD_FAST current_sum
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_FALSE L4
  LOAD_CONST 0
  STORE_FAST current_sum
L4:
  LOAD_GLOBAL NULL + max
  LOAD_FAST current_sum
  LOAD_FAST max_sum
  CALL 2
  STORE_FAST max_sum
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST max_sum
  POP_JUMP_IF_FALSE L6
  LOAD_FAST max_sum
  RETURN_VALUE
L6:
  LOAD_CONST 0
  RETURN_VALUE
END

def find_length(string, n):
    current_sum = 0
    max_sum = 0
    for i in range(n):
        current_sum += 1 if string[i] == '0' else -1
        if current_sum < 0:
            current_sum = 0
        max_sum = max(current_sum, max_sum)
    return max_sum if max_sum else 0

Prompt: Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum>
  MAKE_FUNCTION 0
  STORE_NAME sum
  RETURN_CONST None
END
CODE sum(a, b)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_GLOBAL NULL + min
  LOAD_FAST a
  LOAD_FAST b
  CALL 2
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST a
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST b
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST sum
  LOAD_FAST i
  BINARY_OP +=
  STORE_FAST sum
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST sum
  RETURN_VALUE
END

def sum(a, b):
    sum = 0
    for i in range(1, min(a, b)):
        if a % i == 0 and b % i == 0:
            sum += i
    return sum

Prompt: Write a python function to find the sum of common divisors of two given numbers.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code multiply_int>
  MAKE_FUNCTION 0
  STORE_NAME multiply_int
  RETURN_CONST None
END
CODE multiply_int(x, y)
  RESUME 0
  LOAD_FAST y
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + multiply_int
  LOAD_FAST x
  LOAD_FAST y
  UNARY_NEGATIVE
  CALL 2
  UNARY_NEGATIVE
  RETURN_VALUE
L1:
  LOAD_FAST y
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST 0
L2:
  LOAD_FAST y
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST x
  RETURN_VALUE
L3:
  LOAD_FAST x
  LOAD_GLOBAL NULL + multiply_int
  LOAD_FAST x
  LOAD_FAST y
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  BINARY_OP +
  RETURN_VALUE
END

def multiply_int(x, y):
    if y < 0:
        return -multiply_int(x, -y)
    elif y == 0:
        return 0
    elif y == 1:
        return x
    else:
        return x + multiply_int(x, y - 1)

Prompt: Write a function to multiply two integers without using the * operator in python.

assert multiply_int(10,20)==200
assert multiply_int(5,10)==50
assert multiply_int(4,8)==32


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('defaultdict',)
  IMPORT_NAME collections
  IMPORT_FROM defaultdict
  STORE_NAME defaultdict
  POP_TOP
  LOAD_CONST <code max_occurrences>
  MAKE_FUNCTION 0
  STORE_NAME max_occurrences
  RETURN_CONST None
END
CODE max_occurrences(nums)
  RESUME 0
  LOAD_GLOBAL NULL + defaultdict
  LOAD_GLOBAL int
  CALL 1
  STORE_FAST dict
  LOAD_FAST nums
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST dict
  LOAD_FAST i
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + max
  LOAD_FAST dict
  LOAD_ATTR NULL|self + items
  CALL 0
  LOAD_CONST <code max_occurrences.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE max_occurrences.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 1
  BINARY_SUBSCR
  RETURN_VALUE
END

from collections import defaultdict

def max_occurrences(nums):
    dict = defaultdict(int)
    for i in nums:
        dict[i] += 1
    result = max(dict.items(), key=lambda x: x[1])
    return result

Prompt: Write a function to find the item with maximum frequency in a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code reverse_vowels>
  MAKE_FUNCTION 0
  STORE_NAME reverse_vowels
  RETURN_CONST None
END
CODE reverse_vowels(str1)
  RESUME 0
  LOAD_CONST ''
  STORE_FAST vowels
  LOAD_FAST str1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST char
  LOAD_FAST char
  LOAD_CONST 'aeiouAEIOU'
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST vowels
  LOAD_FAST char
  BINARY_OP +=
  STORE_FAST vowels
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_CONST ''
  STORE_FAST result_string
  LOAD_FAST str1
  GET_ITER
L4:
  FOR_ITER L6
  STORE_FAST char
  LOAD_FAST char
  LOAD_CONST 'aeiouAEIOU'
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L5
  LOAD_FAST result_string
  LOAD_FAST vowels
  LOAD_CONST -1
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST result_string
  LOAD_FAST vowels
  LOAD_CONST None
  LOAD_CONST -1
  BINARY_SLICE
  STORE_FAST vowels
  JUMP_BACKWARD L4
L5:
  LOAD_FAST result_string
  LOAD_FAST char
  BINARY_OP +=
  STORE_FAST result_string
  JUMP_BACKWARD L4
L6:
  END_FOR
  LOAD_FAST result_string
  RETURN_VALUE
END

def reverse_vowels(str1):
    vowels = ''
    for char in str1:
        if char in 'aeiouAEIOU':
            vowels += char
    result_string = ''
    for char in str1:
        if char in 'aeiouAEIOU':
            result_string += vowels[-1]
            vowels = vowels[:-1]
        else:
            result_string += char
    return result_string

Prompt: Write a python function to reverse only the vowels of a given string.

assert reverse_vowels("Python") == "Python"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_negativenum>
  MAKE_FUNCTION 0
  STORE_NAME sum_negativenum
  RETURN_CONST None
END
CODE sum_negativenum(nums)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CONST <code sum_negativenum.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST nums
  CALL 2
  CALL 1
  STORE_FAST sum_negativenum
  LOAD_GLOBAL NULL + sum
  LOAD_FAST sum_negativenum
  CALL 1
  RETURN_VALUE
END
CODE sum_negativenum.<locals>.<lambda>(nums)
  RESUME 0
  LOAD_FAST nums
  LOAD_CONST 0
  COMPARE_OP <
  RETURN_VALUE
END

def sum_negativenum(nums):
    sum_negativenum = list(filter(lambda nums: nums < 0, nums))
    return sum(sum_negativenum)

Prompt: Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_last>
  MAKE_FUNCTION 0
  STORE_NAME check_last
  RETURN_CONST None
END
CODE check_last(arr, n, p)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST _sum
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST _sum
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +
  STORE_FAST _sum
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST p
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
  LOAD_FAST _sum
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST 'ODD'
L3:
  RETURN_CONST 'EVEN'
L4:
  RETURN_CONST 'EVEN'
END

def check_last(arr, n, p):
    _sum = 0
    for i in range(n):
        _sum = _sum + arr[i]
    if p == 1:
        if _sum % 2 == 0:
            return 'ODD'
        else:
            return 'EVEN'
    return 'EVEN'

Prompt: Write a python function to check whether the last element of given array is even or odd after performing an operation p times.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code hexagonal_num>
  MAKE_FUNCTION 0
  STORE_NAME hexagonal_num
  RETURN_CONST None
END
CODE hexagonal_num(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  LOAD_FAST n
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP -
  BINARY_OP *
  RETURN_VALUE
END

def hexagonal_num(n):
    return n * (2 * n - 1)

Prompt: Write a function to find the nth hexagonal number.

assert hexagonal_num(10) == 190
assert hexagonal_num(5) == 45
assert hexagonal_num(7) == 91


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code cal_electbill>
  MAKE_FUNCTION 0
  STORE_NAME cal_electbill
  RETURN_CONST None
END
CODE cal_electbill(units)
  RESUME 0
  LOAD_FAST units
  LOAD_CONST 50
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  LOAD_FAST units
  LOAD_CONST 2.6
  BINARY_OP *
  STORE_FAST amount
  LOAD_CONST 25
  STORE_FAST surcharge
  JUMP_FORWARD L4
L1:
  LOAD_FAST units
  LOAD_CONST 100
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L2
  LOAD_CONST 130
  LOAD_FAST units
  LOAD_CONST 50
  BINARY_OP -
  LOAD_CONST 3.25
  BINARY_OP *
  BINARY_OP +
  STORE_FAST amount
  LOAD_CONST 35
  STORE_FAST surcharge
  JUMP_FORWARD L4
L2:
  LOAD_FAST units
  LOAD_CONST 200
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
  LOAD_CONST 292.5
  LOAD_FAST units
  LOAD_CONST 100
  BINARY_OP -
  LOAD_CONST 5.26
  BINARY_OP *
  BINARY_OP +
  STORE_FAST amount
  LOAD_CONST 45
  STORE_FAST surcharge
  JUMP_FORWARD L4
L3:
  LOAD_CONST 818.5
  LOAD_FAST units
  LOAD_CONST 200
  BINARY_OP -
  LOAD_CONST 8.45
  BINARY_OP *
  BINARY_OP +
  STORE_FAST amount
  LOAD_CONST 75
  STORE_FAST surcharge
L4:
  LOAD_FAST amount
  LOAD_FAST surcharge
  BINARY_OP +
  STORE_FAST total
  LOAD_FAST total
  RETURN_VALUE
END

def cal_electbill(units):
    if units < 50:
        amount = units * 2.6
        surcharge = 25
    elif units <= 100:
        amount = 130 + (units - 50) * 3.25
        surcharge = 35
    elif units <= 200:
        amount = 130 + 162.5 + (units - 100) * 5.26
        surcharge = 45
    else:
        amount = 130 + 162.5 + 526 + (units - 200) * 8.45
        surcharge = 75
    total = amount + surcharge
    return total

Prompt: Write a function to calculate electricity bill.

assert cal_electbill(75)==246.25
assert cal_electbill(265)==1442.75
assert cal_electbill(100)==327.5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('array',)
  IMPORT_NAME array
  IMPORT_FROM array
  STORE_NAME array
  POP_TOP
  LOAD_CONST <code zero_count>
  MAKE_FUNCTION 0
  STORE_NAME zero_count
  RETURN_CONST None
END
CODE zero_count(nums)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  STORE_FAST n
  LOAD_CONST 0
  STORE_FAST n1
  LOAD_FAST nums
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST x
  LOAD_FAST x
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST n1
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST n1
  JUMP_BACKWARD L1
L2:
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_GLOBAL NULL + round
  LOAD_FAST n1
  LOAD_FAST n
  BINARY_OP /
  LOAD_CONST 2
  CALL 2
  RETURN_VALUE
END

from array import array

def zero_count(nums):
    n = len(nums)
    n1 = 0
    for x in nums:
        if x == 0:
            n1 += 1
        else:
            None
    return round(n1 / n, 2)

Prompt: Write a function to find the ration of zeroes in an array of integers.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_Sum_Of_Powers_Of_Two>
  MAKE_FUNCTION 0
  STORE_NAME is_Sum_Of_Powers_Of_Two
  RETURN_CONST None
END
CODE is_Sum_Of_Powers_Of_Two(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  RETURN_CONST True
END

def is_Sum_Of_Powers_Of_Two(n):
    if n % 2 == 1:
        return False
    else:
        return True

Prompt: Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.

assert is_Sum_Of_Powers_Of_Two(10) == True

assert is_Sum_Of_Powers_Of_Two(7) == False

assert is_Sum_Of_Powers_Of_Two(14) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code circle_circumference>
  MAKE_FUNCTION 0
  STORE_NAME circle_circumference
  RETURN_CONST None
END
CODE circle_circumference(r)
  RESUME 0
  LOAD_CONST 6.283
  LOAD_FAST r
  BINARY_OP *
  STORE_FAST perimeter
  LOAD_FAST perimeter
  RETURN_VALUE
END

def circle_circumference(r):
    perimeter = 2 * 3.1415 * r
    return perimeter

Prompt: Write a function to find the circumference of a circle.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code extract_singly>
  MAKE_FUNCTION 0
  STORE_NAME extract_singly
  RETURN_CONST None
END
CODE extract_singly(test_list)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST res
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST temp
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST inner
  LOAD_FAST inner
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_FAST temp
  CONTAINS_OP 1
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST temp
  LOAD_ATTR NULL|self + add
  LOAD_FAST ele
  CALL 1
  POP_TOP
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST ele
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END

def extract_singly(test_list):
    res = []
    temp = set()
    for inner in test_list:
        for ele in inner:
            if not ele in temp:
                temp.add(ele)
                res.append(ele)
    return res

Prompt: Write a function to extract elements that occur singly in the given tuple list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code pancake_sort>
  MAKE_FUNCTION 0
  STORE_NAME pancake_sort
  RETURN_CONST None
END
CODE pancake_sort(nums)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  STORE_FAST arr_len
  LOAD_FAST arr_len
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST nums
  LOAD_ATTR NULL|self + index
  LOAD_GLOBAL NULL + max
  LOAD_FAST nums
  LOAD_CONST 0
  LOAD_FAST arr_len
  BINARY_SLICE
  CALL 1
  CALL 1
  STORE_FAST mi
  LOAD_FAST nums
  LOAD_FAST mi
  LOAD_CONST None
  LOAD_CONST -1
  BUILD_SLICE 3
  BINARY_SUBSCR
  LOAD_FAST nums
  LOAD_FAST mi
  LOAD_CONST 1
  BINARY_OP +
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST nums
  LOAD_FAST nums
  LOAD_FAST arr_len
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST None
  LOAD_CONST -1
  BUILD_SLICE 3
  BINARY_SUBSCR
  LOAD_FAST nums
  LOAD_FAST arr_len
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST nums
  LOAD_FAST arr_len
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST arr_len
  LOAD_FAST arr_len
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST nums
  RETURN_VALUE
END

def pancake_sort(nums):
    arr_len = len(nums)
    while arr_len > 1:
        mi = nums.index(max(nums[0:arr_len]))
        nums = nums[mi::-1] + nums[mi + 1:len(nums)]
        nums = nums[arr_len - 1::-1] + nums[arr_len:len(nums)]
        arr_len -= 1
    return nums

Prompt: Write a function to sort a list of elements using pancake sort.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_samepair>
  MAKE_FUNCTION 0
  STORE_NAME count_samepair
  RETURN_CONST None
END
CODE count_samepair(list1, list2, list3)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_CONST <code count_samepair.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST list1
  LOAD_FAST list2
  LOAD_FAST list3
  CALL 3
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE count_samepair.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  UNPACK_SEQUENCE 3
  STORE_FAST m
  STORE_FAST n
  STORE_FAST o
  LOAD_FAST m
  LOAD_FAST n
  SWAP 2
  COPY 2
  COMPARE_OP ==
  COPY 1
  POP_JUMP_IF_FALSE L3
  POP_TOP
  LOAD_FAST o
  COMPARE_OP ==
  JUMP_FORWARD L4
L3:
  SWAP 2
  POP_TOP
L4:
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L6 -> handler=L6 depth=0 lasti=True
END

def count_samepair(list1, list2, list3):
    result = sum((m == n == o for m, n, o in zip(list1, list2, list3)))
    return result

Prompt: Write a function to count the same pair in three given lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_lists>
  MAKE_FUNCTION 0
  STORE_NAME find_lists
  RETURN_CONST None
END
CODE find_lists(Input)
  RESUME 0
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST Input
  LOAD_GLOBAL list
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 1
L1:
  LOAD_GLOBAL NULL + len
  LOAD_FAST Input
  CALL 1
  RETURN_VALUE
END

def find_lists(Input):
    if isinstance(Input, list):
        return 1
    else:
        return len(Input)

Prompt: Write a function to find number of lists present in the given tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_Pairs>
  MAKE_FUNCTION 0
  STORE_NAME sum_Pairs
  RETURN_CONST None
END
CODE sum_Pairs(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST -1
  LOAD_CONST -1
  CALL 3
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP *
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST i
  BINARY_OP -
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP *
  BINARY_OP -
  BINARY_OP +=
  STORE_FAST sum
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST sum
  RETURN_VALUE
END

def sum_Pairs(arr, n):
    sum = 0
    for i in range(n - 1, -1, -1):
        sum += i * arr[i] - (n - 1 - i) * arr[i]
    return sum

Prompt: Write a python function to find the sum of absolute differences in all pairs of the given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code ascii_value_string>
  MAKE_FUNCTION 0
  STORE_NAME ascii_value_string
  RETURN_CONST None
END
CODE ascii_value_string(str1)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST str1
  CALL 1
  CALL 1
  GET_ITER
  FOR_ITER L1
  STORE_FAST i
  LOAD_GLOBAL NULL + ord
  LOAD_FAST str1
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  SWAP 2
  POP_TOP
  RETURN_VALUE
L1:
  END_FOR
  RETURN_CONST None
END

def ascii_value_string(str1):
    for i in range(len(str1)):
        return ord(str1[i])

Prompt: Write a function to find the ascii value of total characters in a string.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_digits_single>
  MAKE_FUNCTION 0
  STORE_NAME sum_digits_single
  LOAD_CONST <code closest>
  MAKE_FUNCTION 0
  STORE_NAME closest
  LOAD_CONST <code sum_digits_twoparts>
  MAKE_FUNCTION 0
  STORE_NAME sum_digits_twoparts
  RETURN_CONST None
END
CODE sum_digits_single(x)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST ans
  LOAD_FAST x
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST ans
  LOAD_FAST x
  LOAD_CONST 10
  BINARY_OP %
  BINARY_OP +=
  STORE_FAST ans
  LOAD_FAST x
  LOAD_CONST 10
  BINARY_OP //=
  STORE_FAST x
  LOAD_FAST x
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST ans
  RETURN_VALUE
END
CODE closest(x)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST ans
  LOAD_FAST ans
  LOAD_CONST 10
  BINARY_OP *
  LOAD_CONST 9
  BINARY_OP +
  LOAD_FAST x
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST ans
  LOAD_CONST 10
  BINARY_OP *
  LOAD_CONST 9
  BINARY_OP +
  STORE_FAST ans
  LOAD_FAST ans
  LOAD_CONST 10
  BINARY_OP *
  LOAD_CONST 9
  BINARY_OP +
  LOAD_FAST x
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST ans
  RETURN_VALUE
END
CODE sum_digits_twoparts(N)
  RESUME 0
  LOAD_GLOBAL NULL + closest
  LOAD_FAST N
  CALL 1
  STORE_FAST A
  LOAD_GLOBAL NULL + sum_digits_single
  LOAD_FAST A
  CALL 1
  LOAD_GLOBAL NULL + sum_digits_single
  LOAD_FAST N
  LOAD_FAST A
  BINARY_OP -
  CALL 1
  BINARY_OP +
  RETURN_VALUE
END

def sum_digits_single(x):
    ans = 0
    while x:
        ans += x % 10
        x //= 10
    return ans

def closest(x):
    ans = 0
    while ans * 10 + 9 <= x:
        ans = ans * 10 + 9
    return ans

def sum_digits_twoparts(N):
    A = closest(N)
    return sum_digits_single(A) + sum_digits_single(N - A)

Prompt: Write a function to divide a number into two parts such that the sum of digits is maximum.

assert sum_digits_twoparts(35)==17
assert sum_digits_twoparts(7)==7
assert sum_digits_twoparts(100)==19


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code longest_subseq_with_diff_one>
  MAKE_FUNCTION 0
  STORE_NAME longest_subseq_with_diff_one
  RETURN_CONST None
END
CODE longest_subseq_with_diff_one(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_CONST 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST dp
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L5:
  FOR_ITER L9
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  CALL 1
  GET_ITER
L6:
  FOR_ITER L8
  STORE_FAST j
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L7
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP -
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L7
  JUMP_BACKWARD L6
L7:
  LOAD_GLOBAL NULL + max
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST dp
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  LOAD_FAST dp
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L6
L8:
  END_FOR
  JUMP_BACKWARD L5
L9:
  END_FOR
  LOAD_CONST 1
  STORE_FAST result
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L10:
  FOR_ITER L12
  STORE_FAST i
  LOAD_FAST result
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP <
  POP_JUMP_IF_TRUE L11
  JUMP_BACKWARD L10
L11:
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST result
  JUMP_BACKWARD L10
L12:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
L13:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L13 depth=2 lasti=False
END

def longest_subseq_with_diff_one(arr, n):
    dp = [1 for i in range(n)]
    for i in range(n):
        for j in range(i):
            if arr[i] == arr[j] + 1 or arr[i] == arr[j] - 1:
                dp[i] = max(dp[i], dp[j] + 1)
    result = 1
    for i in range(n):
        if result < dp[i]:
            result = dp[i]
    return result

Prompt: Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.

assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6

assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3

assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) == 7


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code gcd>
  MAKE_FUNCTION 0
  STORE_NAME gcd
  LOAD_CONST <code is_coprime>
  MAKE_FUNCTION 0
  STORE_NAME is_coprime
  RETURN_CONST None
END
CODE gcd(p, q)
  RESUME 0
  LOAD_FAST q
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST q
  LOAD_FAST p
  LOAD_FAST q
  BINARY_OP %
  STORE_FAST q
  STORE_FAST p
  LOAD_FAST q
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST p
  RETURN_VALUE
END
CODE is_coprime(x, y)
  RESUME 0
  LOAD_GLOBAL NULL + gcd
  LOAD_FAST x
  LOAD_FAST y
  CALL 2
  LOAD_CONST 1
  COMPARE_OP ==
  RETURN_VALUE
END

def gcd(p, q):
    while q != 0:
        p, q = (q, p % q)
    return p

def is_coprime(x, y):
    return gcd(x, y) == 1

Prompt: Write a python function to check whether the given number is co-prime or not.

assert is_coprime(17,13) == True
assert is_coprime(15,21) == False
assert is_coprime(25,45) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code merge>
  MAKE_FUNCTION 0
  STORE_NAME merge
  LOAD_CONST <code merge_sort>
  MAKE_FUNCTION 0
  STORE_NAME merge_sort
  RETURN_CONST None
END
CODE merge(a, b)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST c
  LOAD_GLOBAL NULL + len
  LOAD_FAST a
  CALL 1
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L4
  LOAD_GLOBAL NULL + len
  LOAD_FAST b
  CALL 1
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L4
L1:
  LOAD_FAST a
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST b
  LOAD_CONST 0
  BINARY_SUBSCR
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  LOAD_FAST c
  LOAD_ATTR NULL|self + append
  LOAD_FAST a
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST a
  LOAD_ATTR NULL|self + remove
  LOAD_FAST a
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  JUMP_FORWARD L3
L2:
  LOAD_FAST c
  LOAD_ATTR NULL|self + append
  LOAD_FAST b
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST b
  LOAD_ATTR NULL|self + remove
  LOAD_FAST b
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_TOP
L3:
  LOAD_GLOBAL NULL + len
  LOAD_FAST a
  CALL 1
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L4
  LOAD_GLOBAL NULL + len
  LOAD_FAST b
  CALL 1
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L1
L4:
  LOAD_GLOBAL NULL + len
  LOAD_FAST a
  CALL 1
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_FAST c
  LOAD_FAST b
  BINARY_OP +=
  STORE_FAST c
  LOAD_FAST c
  RETURN_VALUE
L5:
  LOAD_FAST c
  LOAD_FAST a
  BINARY_OP +=
  STORE_FAST c
  LOAD_FAST c
  RETURN_VALUE
END
CODE merge_sort(x)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST x
  RETURN_VALUE
L2:
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  LOAD_CONST 2
  BINARY_OP //
  STORE_FAST middle
  LOAD_GLOBAL NULL + merge_sort
  LOAD_FAST x
  LOAD_CONST None
  LOAD_FAST middle
  BINARY_SLICE
  CALL 1
  STORE_FAST a
  LOAD_GLOBAL NULL + merge_sort
  LOAD_FAST x
  LOAD_FAST middle
  LOAD_CONST None
  BINARY_SLICE
  CALL 1
  STORE_FAST b
  LOAD_GLOBAL NULL + merge
  LOAD_FAST a
  LOAD_FAST b
  CALL 2
  RETURN_VALUE
END

def merge(a, b):
    c = []
    while len(a) != 0 and len(b) != 0:
        if a[0] < b[0]:
            c.append(a[0])
            a.remove(a[0])
        else:
            c.append(b[0])
            b.remove(b[0])
    if len(a) == 0:
        c += b
    else:
        c += a
    return c

def merge_sort(x):
    if len(x) == 0 or len(x) == 1:
        return x
    else:
        middle = len(x) // 2
        a = merge_sort(x[:middle])
        b = merge_sort(x[middle:])
        return merge(a, b)

Prompt: Write a function to sort the given array by using merge sort.