Mail merge nesting
Your task
A mail merge template is compiled from a flat list of block markers. Every entry in markers reads either "open|loop" or "close|loop", where the text after the pipe is the block name, and block names may repeat. A template compiles when each open is closed by a close carrying the same name, and blocks close in the reverse order they opened, so a block opened inside another must close before the outer one does. Return -1 when the whole list compiles. Otherwise return the position of the first entry the compiler cannot accept, meaning a close that names something other than the innermost block still open, or a close arriving while no block is open. When the list runs out with blocks still open, return the position of the earliest marker still open. An empty list compiles.
Examples
template_nesting_fault(markers: list[str]) -> inttemplate_nesting_fault(["open|loop", "open|if", "close|if", "close|loop"])-1template_nesting_fault(["open|loop", "close|if"])1template_nesting_fault(["open|header", "open|row"])0