import subprocess
from pathlib import Path
import sys

root = Path(__file__).resolve().parent
exe = root / "std"

subprocess.run(
    ["g++", "-std=c++17", "-O2", "-pipe", "-s", str(root / "std.cpp"), "-o", str(exe)],
    check=True
)

for i in range(1, 11):
    with open(root / f"{i}.in", "rb") as fin, open(root / "_tmp.out", "wb") as fout:
        subprocess.run([str(exe)], stdin=fin, stdout=fout, check=True)
    expected = (root / f"{i}.ans").read_bytes()
    actual = (root / "_tmp.out").read_bytes()
    if actual != expected:
        print(f"case {i} failed")
        sys.exit(1)
    print(f"case {i} ok")

(root / "_tmp.out").unlink(missing_ok=True)
exe.unlink(missing_ok=True)
print("all cases passed")
