Around and Around We Go
문제
[이미지 1]
A round is a musical arrangement in which two or more voices repeat the same melodic line at times offset from one another. One of the more famous rounds is the nursery rhyme, "Row, Row, Row Your Boat", shown here, where a new voice can enter when the first voice reaches any of the '*'s.
In western music, an integer count of time units can be assigned to each syllable of a word to indicate how long that syllable is sung. Occasionally a pause (called a "rest") of one or more time units is inserted, and is also assigned an integer count of time units. If you know the time allocated to each word and rest, and the time offset at which each next voice begins singing the line, you can figure out which words will overlap in the round.
Write a program to list a two-voice round, lining up the words in the two voices so that syllables being sung simultaneously appear in a vertical column.
For each line of the song, print that line for the first voice, followed by a line for the second voice. The first voice line will contain the same syllables as the original line of input. Implicitly, that line defines a period of time starting with the beginning of the sound or the first syllable and ending of the sound of the last syllable on that line. The second voice line will contain any syllables of the song that start their sound during that time period (though the last syllable might not finish sounding until afterwards).
Each syllable will be printed as far to the left as possible, with plus signs ('+') inserted in front of syllables so as to satisfy the constraints:
- Consecutive symbols in the same line will be separated by at least one '+'.
- The first syllable in a line for the first voice is printed starting in the leftmost column of the line.
- Two syllables that begin at the same time in their respective voices are printed with their leftmost characters in the same column.
- If a syllable S2 in the either voice begins K time units after a syllable S1 in the other voice begins, then the first character of S2 appears in a column at least K to the right of the first letter of S1.
It is possible that some second-voice lines will be empty (if no syllables of the second voice are started during that line).
It is possible (in fact, likely) that not all syllables of the second voice will be printed.
입력
Input will begin with a line containing two integers, and . is the number of lines in the song, . indicates the time at which the second voice begins, assuming that the first voice begins at time zero. .
That will be followed by pairs of lines.
The first line in each pair contains the syllables of that line of the song. A syllable is a string of any non-whitespace characters. Adjacent syllables in the input will be separated by a single blank. These lines will be at most 80 characters long.
The second line in each pair will consist of positive integers, one per syllable from the first line of the pair, indicating the time allocated to the corresponding syllables. These will be in the range .
출력
For each dataset, print lines of output corresponding to two voices in a round, as described above.
예제
예제 1
2 16 Hot cross buns! = Hot cross buns! = 4 4 4 4 4 4 4 4 One a pen- ny, Two a pen- ny, Hot cross buns! = 2 2 2 2 2 2 2 2 4 4 4 4
Hot_cross_buns!_=___Hot_cross_buns!_= ____________________Hot_cross_buns!_= One_a_pen-_ny,_Two_a_pen-_ny,_Hot___cross____buns!_= Hot___cross____buns!_=________One_a_pen-_ny,_Two_a_pen-_ny,
예제 2
5 32 And ev- ry- 1 1 1 one neath a vine and fig tree, = shall live in 2 1 1 2 2 2 2 1 1 1 1 peace and un- a- fraid. = 2 2 2 2 6 2 And in- to plow shares beat their swords. 2 1 1 2 2 2 2 4 Na- tions shall learn war no more = 2 2 2 2 2 2 1 3
And_ev-_ry- / one_neath_a_vine_and_fig_tree,_=_shall_live_in / peace_and_un-_a-_fraid.___= ______________________And_ev-_ry- And_in-___to_plow_shares_beat_their_swords. one_neath_a__vine_and____fig__tree,_=_shall_live_in Na-___tions_shall_learn_war_no_more_= peace_and___un-___a-____fraid._______=