# SPDX-License-Identifier: MIT
for a, b in ((7, 3), (-7, 3), (7, -3), (-7, -3), (0, -3), (42, 7)):
    print(a, b, divmod(a, b))
print(divmod(1267650600228229401496703205379, 8))
print(divmod(-1267650600228229401496703205379, 8))
print(divmod(1267650600228229401496703205379, -8))
print(divmod(False, True), divmod(True, True), divmod(True, 2))

events = []
def mark(label, value):
    events.append(label)
    return value
print(divmod(mark("left", 20), mark("right", 6)), events)

def checked(label, value, fail):
    events.append(label)
    if fail:
        raise ValueError(label)
    return value
events.clear()
try:
    divmod(checked("first", 9, True), checked("skipped", 3, False))
except ValueError as error:
    print(str(error), events)
events.clear()
try:
    divmod(checked("first", 9, False), checked("second", 3, True))
except ValueError as error:
    print(str(error), events)
events.clear()
try:
    divmod(mark("numerator", 9), mark("zero", 0))
except ZeroDivisionError:
    print(events)

value = 20
def right():
    global value
    value = 99
    return 6
print(divmod(value, right()), value)

split = divmod
def make_splitter(operation):
    def apply(a, b):
        return operation(a, b)
    return apply
apply = make_splitter(split)
result = apply(-20, 6)
q, r = result
print(result, q, r, isinstance(q, int) and not isinstance(q, bool), isinstance(r, int) and not isinstance(r, bool))
print(split(*(29, 5)))

try:
    divmod(10, 0)
except ZeroDivisionError as error:
    print(type(error).__name__, str(error))
try:
    divmod(True, False)
except ZeroDivisionError as error:
    print(type(error).__name__, str(error))
