"""usage: py -3.15 c1_to_cert.py BEST.npy OUT.json [--scale 1e13]
Round float heights (scaled so the mean is SCALE) to nonnegative integers and write the ladder
certificate {"heights": [...]}. Then run c1_score.py OUT.json for the exact score."""
import json, sys
import numpy as np
if len(sys.argv) < 3: print(__doc__); sys.exit(1)
scale = float(sys.argv[sys.argv.index("--scale") + 1]) if "--scale" in sys.argv else 1e13
a = np.load(sys.argv[1]).astype(np.float64)
a = np.clip(a, 0, None); a = a / a.mean() * scale
h = [int(round(x)) for x in a]
json.dump({"heights": h}, open(sys.argv[2], "w"))
print(f"wrote {sys.argv[2]}: N={len(h)} max={max(h)} zeros={h.count(0)}")
