def incr_id_after(id, start, n):
    """Perform the id adjustment necessary for adding n lines before
    start id. The exact logic is as follows:
    
    Suppose start has length k. Find all ids with length at least k,
    where the first k-1 numbers agree with start, and the k'th number
    is greater than or equal to start. Increment the k'th number by n
    and leave the rest unchanged.

    """
    k = len(start)
    if len(id) >= k and id[:k-1] == start[:k-1] and id[k-1] >= start[k-1]:
        return id[:k-1] + (id[k-1] + n,) + id[k:]
    else:
        return id