import itertools
import re
import sys

from collections import deque
from typing import NamedTuple


RE_OUTLINE = re.compile(r, re.M)

COLORS = itertools.cycle(
    [
        ,
        ,
        ,
        ,
        ,
    ]
)


class Node:
    def __init__(self, indent, value, parent, children=None):
        self.indent = indent
        self.value = value
        self.parent = parent
        self.children = children or []

        self.color = None

    def depth(self):
        if self.parent:
            return self.parent.depth() + 1
        return -1

    def height(self):
        
        if not self.children:
            return 0
        return max(child.height() for child in self.children) + 1

    def colspan(self):
        if self.leaf:
            return 1
        return sum(child.colspan() for child in self.children)

    @property
    def leaf(self):
        return not bool(self.children)

    def __iter__(self):
        
        q = deque()
        q.append(self)
        while q:
            node = q.popleft()
            yield node
            q.extend(node.children)


class Token(NamedTuple):
    indent: int
    value: str


def tokenize(outline):
    
    for match in RE_OUTLINE.finditer(outline):
        indent, value = match.groups()
        yield Token(len(indent), value)


def parse(outline):
    
    
    tokens = list(tokenize(outline))

    
    temp_root = Node(-1, , None)
    _parse(tokens, 0, temp_root)

    
    root = temp_root.children[0]
    pad_tree(root, root.height())

    return root


def _parse(tokens, index, node):
    
    
    if index >= len(tokens):
        return

    token = tokens[index]

    if token.indent == node.indent:
        
        current = Node(token.indent, token.value, node.parent)
        node.parent.children.append(current)
        _parse(tokens, index + 1, current)

    elif token.indent > node.indent:
        
        current = Node(token.indent, token.value, node)
        node.children.append(current)
        _parse(tokens, index + 1, current)

    elif token.indent < node.indent:
        
        _parse(tokens, index, node.parent)


def pad_tree(node, height):
    
    if node.leaf and node.depth() < height:
        pad_node = Node(node.indent + 1, , node)
        node.children.append(pad_node)

    for child in node.children:
        pad_tree(child, height)


def color_tree(node):
    
    if not node.value:
        node.color = 
    elif node.depth() <= 1:
        node.color = next(COLORS)
    else:
        node.color = node.parent.color

    for child in node.children:
        color_tree(child)


def table_data(node):
    
    indent = 

    if node.colspan() > 1:
        colspan = f'colspan='
    else:
        colspan = 

    if node.color:
        style = f'style='
    else:
        style = 

    attrs = .join([colspan, style])
    return f


def html_table(tree):
    
    
    table_cols = tree.colspan()

    
    row_cols = 0

    
    buf = []

    
    for node in tree:
        if row_cols == 0:
            buf.append()

        buf.append(table_data(node))
        row_cols += node.colspan()

        if row_cols == table_cols:
            buf.append()
            row_cols = 0

    buf.append()
    return .join(buf)


def wiki_table_data(node):
    
    if not node.value:
        return 

    if node.colspan() > 1:
        colspan = f
    else:
        colspan = 

    if node.color:
        style = f'style='
    else:
        style = 

    attrs = .join([colspan, style])
    return f


def wiki_table(tree):
    
    
    table_cols = tree.colspan()

    
    row_cols = 0

    
    buf = ['{| class= style=']

    for node in tree:
        if row_cols == 0:
            buf.append()

        buf.append(wiki_table_data(node))
        row_cols += node.colspan()

        if row_cols == table_cols:
            row_cols = 0

    buf.append()
    return .join(buf)


def example(table_format=):
    

    outline = (
        
        
        
        
        
        
        
        
        
        
        
        
    )

    tree = parse(outline)
    color_tree(tree)

    if table_format == :
        print(wiki_table(tree))
    else:
        print(html_table(tree))


if __name__ == :
    args = sys.argv[1:]

    if len(args) == 1:
        table_format = args[0]
    else:
        table_format = 

    example(table_format)