def add(lhs: list[int], rhs: list[int], base: int) -> list[int]:
    """
    Adds two arbitrary-precision values in some base together.

    Given two arrays lhs and rhs of digits in some base 'base,' returns an
    array of the number lhs + rhs encoded in base 'base.'
    """

    # Pad the two inputs to be the same length.
    length = max(len(lhs), len(rhs))
    lhs = [0] * (length - len(lhs)) + lhs
    rhs = [0] * (length - len(rhs)) + rhs

    # Track the carry from the previous column; initially this is zero.
    carry = 0

    # Track the result.  We'll build the array up in reverse to avoid costly
    # prepend operations that aren't relevant.
    result = []

    # Iterate across the digits in reverse, computing the sum.
    for i in range(1, len(lhs) + 1):
        # Sum the carry and the two values in this column
        column = lhs[-i] + rhs[-i] + carry

        # Output the column value (after modding by the base)
        result.append(column % base)

        # Update the carry
        carry = column // base

    # Prepend the carry to the result if it's nonzero.
    if carry != 0:
        result.append(carry)

    # Reverse the order of the resulting digits; that's the more proper way
    # to hand them back.
    result.reverse()

    return result