def compile_brainrot(code: str) -> str:
    lines = code.splitlines()
    out = []

    INDENT = " " * 4
    indent_stack = [0]

    for raw_line in lines:
        if not raw_line.strip():
            out.append("")
            continue

        # ---------- INDENT HANDLING ----------
        leading_spaces = len(raw_line) - len(raw_line.lstrip(" "))
        current_indent = leading_spaces // 4

        while current_indent < indent_stack[-1]:
            indent_stack.pop()

        if current_indent > indent_stack[-1]:
            indent_stack.append(current_indent)

        stripped = raw_line.strip()

        # ---------- LOOP (grind) ----------
        if stripped.startswith("grind "):
            count = stripped[len("grind "):].rstrip(":")
            out.append(f"{INDENT * current_indent}for _ in range({count}):")
            continue

        # ---------- IF ----------
        if stripped.startswith("valid "):
            condition = stripped[len("valid "):].rstrip(":")
            out.append(f"{INDENT * current_indent}if {condition}:")
            continue

        # ---------- ELSE ----------
        if stripped == "nah:":
            out.append(f"{INDENT * (current_indent - 1)}else:")
            continue

        # ---------- VARIABLE ----------
        if stripped.startswith("cook "):
            _, var, _, value = stripped.split(maxsplit=3)
            out.append(f"{INDENT * current_indent}{var} = {value}")
            continue

        # ---------- INPUT (spill) ----------
        if stripped.startswith("spill "):
            parts = stripped.split()

            # spill name
            if len(parts) == 2:
                var = parts[1]
                out.append(f"{INDENT * current_indent}{var} = input()")
                continue

            # spill age as int
            if len(parts) == 4 and parts[2] == "as":
                var = parts[1]
                dtype = parts[3]

                cast_map = {
                    "int": "int",
                    "float": "float",
                    "str": "str"
                }

                cast = cast_map.get(dtype, "str")
                out.append(f"{INDENT * current_indent}{var} = {cast}(input())")
                continue

        # ---------- PRINT ----------
        if stripped.startswith("yap "):
            out.append(f"{INDENT * current_indent}print({stripped[4:]})")
            continue

        # ---------- EXIT ----------
        if stripped == "dip":
            out.append(f"{INDENT * current_indent}exit()")
            continue

        # ---------- FALLBACK ----------
        out.append(f"{INDENT * current_indent}{stripped}")

    return "\n".join(out)
