import array


def find_compensation(payload, secret):
    """Finds the u16bit word to append in the secret in order to obtain the same checksum as in the payload."""
    if len(payload) % 2 == 1:
        payload += b"\0"
    if len(secret) % 2 == 1:
        secret += b"\0"
    sp = sum(array.array("H", payload))  # sum payload 16bit words
    ss = sum(array.array("H", secret))  # sum secret 16bit words
    val = sp - ss  # subtract sums
    val = (val >> 16) + (val & 0xffff)  # shift and mask 16bit for carry
    val += val >> 16  # make it unsigned

    return val