# https://stackoverflow.com/a/75408780/1468366

def next_combination(n: int, c: list[int]):
    """Compute next combination, in lexicographical order.

    Args:
      n: the number of items to choose
         from.
      c: a list of integers between 0
         (inclusive) and n (exclusive) in
         strictly ascending order. It
         will get modified by the call.
    Returns: the list c after modification,
         or None if this was the last
         combination.
    """
    i = len(c)
    while i > 0:
        i -= 1
        n -= 1
        if c[i] == n: continue
        c[i] += 1
        for j in range(i + 1, len(c)):
            c[j] = c[j - 1] + 1
        return c
    return None

lst = [0, 1, 2]
while lst is not None:
    print(lst)
    lst = next_combination(5, lst)