This page is still under construction.

Parts of this page are still being built. What you see may change.

Table Rendering

Interview

Time limit2sMemory limit1024 MB

Summary
Given per-row cell widths, draw an ASCII table where each horizontal separator has a '+' exactly under or over every vertical bar.
Level

Medium4 of 10

Topics
Implementation, Simulation, Array, String
Solved
No attempts yet

Problem

When developing programs for viewing web pages, one of the most difficult tasks is rendering tables correctly. The company <<Kozilla>>, where you work, plans to develop a new version of the <<Waterrat>> browser for terminal mode and asks you to write the fragment of the web page rendering core responsible for building the structure of tables.

The fragment you must write receives information about the number of rows of a table and the cells of those rows, and must generate the table structure and pass it to the module that renders the table on screen.

A table consists of rows, each row consists of one or more cells, and the jj-th cell of the ii-th row has width ai,ja_{i,j}.

Given the parameters of the table, construct a symbolic image of its structure.

Input

The first line of the input file contains nn, the number of rows in the table (1≤n≤1001 \le n \le 100). The next nn lines of the input file contain descriptions of the table rows.

The description of each row includes the number mim_i, the number of cells in that row, and mim_i integers ai,1,ai,2,…,ai,mia_{i,1}, a_{i,2}, \dots, a_{i,m_i}, the width of each cell in the row (1≤mi≤101 \le m_i \le 10, 1≤ai,j≤201 \le a_{i,j} \le 20).

Output

Output a symbolic image of the table structure to the output file.

The image of the ii-th row of the table must begin with an image of a horizontal line made up of the characters <<+>> (plus) and <<->> (minus). Then a line containing spaces and <<|>> (vertical bar) characters must follow. The first character of the line must be a vertical bar, then ai,1a_{i,1} spaces, then a vertical bar, then ai,2a_{i,2} spaces, and so on, for a total of mim_i blocks of spaces. After the last block a vertical bar must follow. After the last row of the table, an image of a horizontal line must also follow.

In the image of a horizontal line, use the character <<+>> if a vertical bar is above or below that position, and <<->> otherwise. The horizontal line must have the minimum possible length so that there are <<+>> characters above every vertical bar character of the next line and below every vertical bar character of the previous line.

Examples1

  1. Example 1

    Input
    4
    3 3 5 1
    1 2
    1 2
    2 5 1
    
    Expected output
    +---+-----+-+
    |   |     | |
    +--++-----+-+
    |  |
    +--+
    |  |
    +--+--+-+
    |     | |
    +-----+-+