#!/usr/bin/env python3
# $$
# \begin{array}{rl}
# 	T_2 = &
# %	\left(
# 	\begin{array}{rrrrrrrrrr}
# 	1, & 2, & 4, & 8, & 16, & 32, & 64, & 3, & 6, & 12,   \\\\
# 	24, & 48, & 0, & 0, & 9, & 18, & 36, & 72, & 0, & 0,   \\\\
# 	0, & 27, & 54, & 5, & 10, & 20, & 40, & 0, & 81, & 0,   \\\\
# 	15, & 30, & 0, & 7, & 14, & 28, & 56, & 45, & 0, & 0,   \\\\
# 	21, & 42, & 0, & 0, & 0, & 0, & 25, & 63, & 0, & 0,   \\\\
# 	0, & 0, & 0, & 0, & 0, & 0, & 35, & 0, & 0, & 0,   \\\\
# 	0, & 0, & 0, & 0, & 0, & 0, & 49\hphantom{,} 
# 	\end{array}
# %	\right)
# \end{array}
# $$
# 

import re
import sys

ordinary = r'^([0-9,\s&]+|\\\\+|None,|\\hphantom\{.*\}|\\hline|\\ldots|\\color\{\w+\}\{.*\})+$'

if __name__ == '__main__':
    count = 0 if len(sys.argv) == 1 else int(sys.argv[1])

    for line in sys.stdin:
        line = line.rstrip()
        out = None
        if re.match(ordinary, line):
            if re.search(r'\d+', line):
                out = "    {\\tiny\\color{gray}{" + str(count) + "}} & " + line
                ampers = len(re.findall('&', line))
                if re.search(r'\\ldots', line):
                    count = -1000
                else:
                    count += ampers + 1
            else:
                out = line
        elif re.search(r'\\begin\{array\}', line):
            rpat = r'\{(r+)\}'
            match = re.search(rpat, line)
            if match is None:
                out = line
            else:
                rs= "{r" + match.group(1) + "}"
                out = re.sub(rpat, rs, line)
        else:
            out = line
        print(out)
