def make_shard_endpoints(total_length, shard_size=int(1e6)):
    """
    Partition the half-open integer interval [0, total_length) into a
    sequence of half-open subintervals [s0,e0), [s1,e1), ... [s_n, e_n)
    such that s0 = 0, s_(k+1) = e_k, e_n = total_length, and each of these
    subintervals (except possibly the last) has length equal to the given
    shard_size.  Return the sequence of pairs of endpoints of the
    subintervals.
    """
    shard_end = 0
    shards = []
    while True:
        shard_start = shard_end
        shard_end = shard_start + shard_size
        if shard_end > total_length:
            shard_end = total_length
        if shard_start >= shard_end:
            break
        shards.append((shard_start, shard_end))
    return shards