broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('pass-through-overlap-gate fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('pass-through-overlap-gate fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('pass-through-overlap-gate fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('pass-through-overlap-gate fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('pass-through-overlap-gate fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('pass-through-overlap-gate fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('pass-through-overlap-gate fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('pass-through-overlap-gate fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('pass-through-overlap-gate fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('pass-through-overlap-gate fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('pass-through-overlap-gate fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps<=x['max_overlaps'] and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('pass-through-overlap-gate fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('pass-through-overlap-gate fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('pass-through-overlap-gate fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('pass-through-overlap-gate fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('pass-through-overlap-gate fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('pass-through-overlap-gate fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('pass-through-overlap-gate fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('pass-through-overlap-gate fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('pass-through-overlap-gate fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('pass-through-overlap-gate fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('pass-through-overlap-gate fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('pass-through-overlap-gate fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A range-set guard limits amplification before serving resolved byte ranges: any tolerated overlap still forces coalesced output.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<=extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('remainder-front-loaded fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('remainder-front-loaded fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('remainder-front-loaded fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('remainder-front-loaded fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('remainder-front-loaded fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('remainder-front-loaded fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('remainder-front-loaded fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('remainder-front-loaded fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('remainder-front-loaded fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('remainder-front-loaded fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('remainder-front-loaded fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if extra and i==0 else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('remainder-front-loaded fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('remainder-front-loaded fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('remainder-front-loaded fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('remainder-front-loaded fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('remainder-front-loaded fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('remainder-front-loaded fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('remainder-front-loaded fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('remainder-front-loaded fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('remainder-front-loaded fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('remainder-front-loaded fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('remainder-front-loaded fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('remainder-front-loaded fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: remainder bytes go one each to the leading workers.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=base
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('segment-cursor-advance fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('segment-cursor-advance fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('segment-cursor-advance fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('segment-cursor-advance fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('segment-cursor-advance fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('segment-cursor-advance fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('segment-cursor-advance fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('segment-cursor-advance fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('segment-cursor-advance fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('segment-cursor-advance fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('segment-cursor-advance fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start=start+size-1 if size else start
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('segment-cursor-advance fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('segment-cursor-advance fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('segment-cursor-advance fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('segment-cursor-advance fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('segment-cursor-advance fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('segment-cursor-advance fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('segment-cursor-advance fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('segment-cursor-advance fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('segment-cursor-advance fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('segment-cursor-advance fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('segment-cursor-advance fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('segment-cursor-advance fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: each segment begins after the previous segment actual size.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('data-overrun fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('data-overrun fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('data-overrun fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('data-overrun fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('data-overrun fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('data-overrun fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('data-overrun fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('data-overrun fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('data-overrun fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('data-overrun fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('data-overrun fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('data-overrun fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]>w[i][1]: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('data-overrun fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('data-overrun fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('data-overrun fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('data-overrun fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('data-overrun fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('data-overrun fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('data-overrun fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('data-overrun fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('data-overrun fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('data-overrun fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('data-overrun fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('data-overrun fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('data-overrun fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: accepted bytes cannot advance a worker past its assigned end.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if i>=len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('worker-index-sign fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('worker-index-sign fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('worker-index-sign fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('worker-index-sign fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('worker-index-sign fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('worker-index-sign fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('worker-index-sign fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('worker-index-sign fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('worker-index-sign fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('worker-index-sign fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('worker-index-sign fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if i>=len(w) or i<-len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('worker-index-sign fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('worker-index-sign fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('worker-index-sign fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('worker-index-sign fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('worker-index-sign fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('worker-index-sign fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('worker-index-sign fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('worker-index-sign fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('worker-index-sign fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('worker-index-sign fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('worker-index-sign fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('worker-index-sign fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: negative worker indices are rejected rather than addressing the last worker.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w): continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('steal-requires-idle fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('steal-requires-idle fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('steal-requires-idle fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('steal-requires-idle fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('steal-requires-idle fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('steal-requires-idle fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('steal-requires-idle fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('steal-requires-idle fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('steal-requires-idle fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('steal-requires-idle fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('steal-requires-idle fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('steal-requires-idle fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('steal-requires-idle fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('steal-requires-idle fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('steal-requires-idle fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('steal-requires-idle fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('steal-requires-idle fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('steal-requires-idle fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('steal-requires-idle fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('steal-requires-idle fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('steal-requires-idle fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('steal-requires-idle fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-requires-idle fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: only a finished worker may take over part of another range.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]>w[j][1]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('victim-remaining-size fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('victim-remaining-size fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('victim-remaining-size fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('victim-remaining-size fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('victim-remaining-size fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('victim-remaining-size fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('victim-remaining-size fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('victim-remaining-size fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('victim-remaining-size fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('victim-remaining-size fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('victim-remaining-size fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][0]<w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('victim-remaining-size fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('victim-remaining-size fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('victim-remaining-size fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('victim-remaining-size fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('victim-remaining-size fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('victim-remaining-size fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('victim-remaining-size fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('victim-remaining-size fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('victim-remaining-size fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('victim-remaining-size fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('victim-remaining-size fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-remaining-size fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: the victim is chosen by remaining bytes rather than range position.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>=w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('victim-tie-lowest fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('victim-tie-lowest fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('victim-tie-lowest fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('victim-tie-lowest fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('victim-tie-lowest fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('victim-tie-lowest fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('victim-tie-lowest fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('victim-tie-lowest fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('victim-tie-lowest fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('victim-tie-lowest fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('victim-tie-lowest fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0] or w[t][1]-w[t][0]==w[j][1]-w[j][0] and w[t][0]>w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut-1
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('victim-tie-lowest fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('victim-tie-lowest fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('victim-tie-lowest fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('victim-tie-lowest fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('victim-tie-lowest fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('victim-tie-lowest fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('victim-tie-lowest fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('victim-tie-lowest fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('victim-tie-lowest fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('victim-tie-lowest fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('victim-tie-lowest fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('victim-tie-lowest fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: equal remaining work selects the lowest worker index.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[j][1]=cut-1
            w[i]=[cut,w[j][1]]
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('steal-assignment-order fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('steal-assignment-order fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('steal-assignment-order fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('steal-assignment-order fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('steal-assignment-order fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('steal-assignment-order fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('steal-assignment-order fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('steal-assignment-order fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('steal-assignment-order fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('steal-assignment-order fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('steal-assignment-order fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[j][1]=cut
            w[i]=[cut,w[j][1]]
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('steal-assignment-order fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('steal-assignment-order fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('steal-assignment-order fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('steal-assignment-order fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('steal-assignment-order fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('steal-assignment-order fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('steal-assignment-order fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('steal-assignment-order fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('steal-assignment-order fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('steal-assignment-order fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('steal-assignment-order fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('steal-assignment-order fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: the thief copies the victim end before the victim is shortened.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            pass
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('donor-shrink fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('donor-shrink fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('donor-shrink fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('donor-shrink fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('donor-shrink fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('donor-shrink fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('donor-shrink fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('donor-shrink fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('donor-shrink fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('donor-shrink fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('donor-shrink fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T=x['total']
    k=x['workers']
    if k<=0 or T<0: return None
    base,extra=divmod(T,k)
    w=[]
    start=0
    for i in range(k):
        size=base+(1 if i<extra else 0)
        if size>0: w.append([start,start+size-1])
        start+=size
    for ev in x['events']:
        if ev[0]=='data':
            i,n=ev[1],ev[2]
            if not 0<=i<len(w) or n<0 or w[i][0]+n>w[i][1]+1: return None
            w[i][0]+=n
        elif ev[0]=='steal':
            i=ev[1]
            if not 0<=i<len(w) or w[i][0]<=w[i][1]: continue
            j=None
            for t in range(len(w)):
                if j is None or w[t][1]-w[t][0]>w[j][1]-w[j][0]: j=t
            rem=w[j][1]-w[j][0]+1
            if rem<2: continue
            cut=w[j][0]+(rem+1)//2
            w[i]=[cut,w[j][1]]
            w[j][1]=cut
    return ['bytes=%d-%d'%(c,e) for c,e in w if c<=e]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('donor-shrink fixture 0', json.loads(json.dumps(solve({'events':[],'total':11,'workers':3}))), json.loads(json.dumps(['bytes=0-3','bytes=4-7','bytes=8-10'])))
check('donor-shrink fixture 1', json.loads(json.dumps(solve({'events':[],'total':2,'workers':4}))), json.loads(json.dumps(['bytes=0-0','bytes=1-1'])))
check('donor-shrink fixture 2', json.loads(json.dumps(solve({'events':[],'total':0,'workers':2}))), json.loads(json.dumps([])))
check('donor-shrink fixture 3', json.loads(json.dumps(solve({'events':[],'total':5,'workers':0}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 4', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,6]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 5', json.loads(json.dumps(solve({'events':[['data',0,5],['data',1,3]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9'])))
check('donor-shrink fixture 6', json.loads(json.dumps(solve({'events':[['data',-1,2]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 7', json.loads(json.dumps(solve({'events':[['data',0,5],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=8-9','bytes=5-7'])))
check('donor-shrink fixture 8', json.loads(json.dumps(solve({'events':[['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=0-4','bytes=5-9'])))
check('donor-shrink fixture 9', json.loads(json.dumps(solve({'events':[['data',0,4],['steal',0]],'total':10,'workers':2}))), json.loads(json.dumps(['bytes=4-4','bytes=5-9'])))
check('donor-shrink fixture 10', json.loads(json.dumps(solve({'events':[['data',0,4],['data',2,1],['steal',0]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=6-7','bytes=4-5','bytes=9-11'])))
check('donor-shrink fixture 11', json.loads(json.dumps(solve({'events':[['data',2,4],['steal',2]],'total':12,'workers':3}))), json.loads(json.dumps(['bytes=0-1','bytes=4-7','bytes=2-3'])))
check('donor-shrink fixture 12', json.loads(json.dumps(solve({'events':[['data',0,2],['data',1,1],['steal',0]],'total':4,'workers':2}))), json.loads(json.dumps(['bytes=3-3'])))
check('donor-shrink fixture 13', json.loads(json.dumps(solve({'events':[['data',0,-1]],'total':10,'workers':2}))), json.loads(json.dumps(None)))
check('donor-shrink fixture 14', json.loads(json.dumps(solve({'events':[],'total':4*N,'workers':2}))), json.loads(json.dumps(["bytes=0-%d"%(2*N-1),"bytes=%d-%d"%(2*N,4*N-1)])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A parallel downloader splits a representation into worker ranges and rebalances idle workers: the victim stops before the stolen suffix instead of downloading it twice.

x has total length, worker count and events. Initial segments follow array-split sizing: base=total//workers, the first total%workers workers get one extra byte; zero-size segments are dropped and later worker indices refer to the surviving list. Each segment is [cursor,end]. data(i,n) advances worker i by n>=0 accepted bytes; an invalid or negative index, negative n or overrun past its end returns null. steal(i) is ignored unless i is a valid finished worker; the victim is the worker with the most remaining bytes (lowest index on ties); a victim with fewer than2 remaining bytes is left alone; otherwise the victim keeps the first ceil(rem/2) bytes and the thief takes the rest. Return Range header values for unfinished workers in worker order. workers<=0 or negative total returns null.

split: open-access