import subprocess
import sys


def test_condefects_0():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='6\n1 2\n2 3\n3 4\n4 5\n5 6\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '2 2\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_1():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='9\n3 9\n7 8\n8 6\n4 6\n4 1\n5 9\n7 3\n5 2\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '2 2 2\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_2():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='20\n8 3\n8 18\n2 19\n8 20\n9 17\n19 7\n8 7\n14 12\n2 15\n14 10\n2 13\n2 16\n2 1\n9 5\n10 15\n14 6\n2 4\n2 11\n5 12\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '2 3 4 7\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )
