def _py_expand_long(subsequence, sequence, max_l_dist):
    """Partial match expansion, optimized for long sub-sequences."""
    subseq_len = len(subsequence)
    if subseq_len == 0:
        return 0, 0
    scores = list(range(1, subseq_len + 1))
    min_score = subseq_len
    min_score_idx = -1
    max_good_score = max_l_dist
    new_needle_idx_range_start = 0
    new_needle_idx_range_end = subseq_len - 1
    for seq_index, char in enumerate(sequence):
        needle_idx_range_start = new_needle_idx_range_start
        needle_idx_range_end = min(subseq_len, new_needle_idx_range_end + 1)
        a = seq_index
        c = a + 1
        if c <= max_good_score:
            new_needle_idx_range_start = 0
            new_needle_idx_range_end = 0
        else:
            new_needle_idx_range_start = None
            new_needle_idx_range_end = -1
        for subseq_index in range(needle_idx_range_start, needle_idx_range_end
            ):
            b = scores[subseq_index]
            c = scores[subseq_index] = min(a + (char != subsequence[
                subseq_index]), b + 1, c + 1)
            a = b
            if c <= max_good_score:
                if new_needle_idx_range_start is None:
                    new_needle_idx_range_start = subseq_index
                new_needle_idx_range_end = max(new_needle_idx_range_end, 
                    subseq_index + 1 + (max_good_score - c))
        if new_needle_idx_range_start is None:
            break
        if needle_idx_range_end == subseq_len and c <= min_score:
            min_score = c
            min_score_idx = seq_index
            if min_score < max_good_score:
                max_good_score = min_score
    return (min_score, min_score_idx + 1) if min_score <= max_l_dist else (None
        , None)
