from __future__ import annotations

import asyncio
import sys

from typing import Optional
from typing import TextIO


class OutOfInkError(Exception):
    


class Printer:
    def __init__(self, name: str, backup: Optional[Printer]):
        self.name = name
        self.backup = backup

        self.ink_level: int = 5
        self.output_stream: TextIO = sys.stdout

    async def print(self, msg):
        if self.ink_level <= 0:
            if self.backup:
                await self.backup.print(msg)
            else:
                raise OutOfInkError(self.name)
        else:
            self.ink_level -= 1
            self.output_stream.write(f)


async def main():
    reserve = Printer(, None)
    main = Printer(, reserve)

    humpty_lines = [
        ,
        ,
        ,
        ,
    ]

    goose_lines = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
    ]

    async def print_humpty():
        for line in humpty_lines:
            try:
                task = asyncio.Task(main.print(line))
                await task
            except OutOfInkError:
                print()
                break

    async def print_goose():
        for line in goose_lines:
            try:
                task = asyncio.Task(main.print(line))
                await task
            except OutOfInkError:
                print()
                break

    await asyncio.gather(print_goose(), print_humpty())


if __name__ == :
    asyncio.run(main(), debug=True)