#!/usr/bin/env python3

# Use Python's trace module to extract the flag
import sys
import subprocess

# Create a wrapper that runs baby.py with trace
wrapper_code = """
import sys
import baby

# Monkey patch the comparison function to log values
original_g0G0SQuid = baby.g0G0SQuid

def debug_g0G0SQuid(a, b):
    result = original_g0G0SQuid(a, b)
    if isinstance(a, str) and len(a) > 0:
        print(f"COMPARE: '{a}' with hash {b} -> '{result}'", file=sys.stderr)
    return result

baby.g0G0SQuid = debug_g0G0SQuid

# Also patch the main validation to extract expected values
if hasattr(baby, 'gog0sQu1D'):
    original_main = baby.gog0sQu1D
    def debug_main():
        print("MAIN VALIDATION STARTED", file=sys.stderr)
        return original_main()
    baby.gog0sQu1D = debug_main

# Run the main
if __name__ == "__main__":
    baby.gog0sQu1D()
"""

with open("trace_wrapper.py", "w") as f:
    f.write(wrapper_code)

print("Running with trace wrapper...")
result = subprocess.run(
    ["python", "trace_wrapper.py"],
    input="test_input_12345",
    capture_output=True,
    text=True,
    timeout=2
)

print("STDOUT:", result.stdout)
print("\nSTDERR:", result.stderr)
