cswork / OAOpen practice workspace

SierraOA #1

Markdown Header Chunks

Estimated MediumJudge-ready

Topics (AI-labelled)StringsSimulation

Split Markdown by whole lines; if a new chunk starts in the middle of some header level, first replay the currently active header path. For display, lines are joined with |.

The standard input/output format and supplementary bounds of this site are as stated in this problem.

Input

The first line contains maxChunkSize (1≤value≤10^5), followed by the raw Markdown text; lines cannot be split, and the total input length is ≤10^5. An overlong content line forms a chunk on its own, but still carries the active headers.

Output

Output one line per chunk, with its internal lines joined by |; an empty document produces empty output.

Example 1

Input:

20
# A
short
longer line
## B
x
y

Output:

# A | short
# A | longer line
# A | ## B | x | y

Example 2

Input:

30
# Guide
alpha
beta

Output:

# Guide | alpha | beta

Example 3

Input:

10
# X
very long line here

Output:

# X
# X | very long line here

Editorial

Loading solution…