eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків

Stylish

\textit{Stylish} is a programming language whose syntax comprises \textit{names}, that are sequences of Latin alphabet letters, three types of \textit{grouping symbols}, periods ('\textbf{.}'), and newlines. Grouping symbols, namely round brackets ('\textbf{(}' and '\textbf{)}'), curly brackets ('\textbf{\{}' and '\textbf{\}}'), and square brackets ('\textbf{\[}' and '\textbf{\]}'), must match and be nested properly. Unlike most other programming languages, Stylish uses periods instead of whitespaces for the purpose of term separation. The following is an example of a Stylish program. \includegraphics{https://static.e-olymp.com/content/3e/3eacd2f4ffd5c764c82be9abe02fa6681827095c.jpg} As you see in the example, a Stylish program is indented by periods. The \textit{amount of indentation} of a line is the number of leading periods of it. Your mission is to visit Stylish masters, learn their indentation styles, and become the youngest Stylish master. An indentation style for \textit{well-indented} Stylish programs is de ned by a triple of integers, (\textbf{R}, \textbf{C}, \textbf{S}), satisfying \textbf{1} ≤ \textbf{R}, \textbf{C}, \textbf{S} ≤\textbf{20}. \textbf{R}, \textbf{C} and \textbf{S} are amounts of indentation introduced by an open round bracket, an open curly bracket, and an open square bracket, respectively. In a well-indented program, the amount of indentation of a line is given by \textbf{R(r_o-r_c)+C(c_o-c_c)+S(s_o-s_c)}, where \textbf{r_o},\textbf{c_o}, and \textbf{s_o} are the numbers of occurrences of open round, curly, and square brackets in all preceding lines, respectively, and \textbf{r_c}, \textbf{c_c}, and \textbf{s_c} are those of close brackets. The rst line has no indentation in any well-indented program. The above example is formatted in the indentation style \textbf{(R, C, S) = (9, 5, 2)}. The only grouping symbol occurring in the rst line of the above program is an open round bracket. Therefore the amount of indentation for the second line is \textbf{9·(1-0)+5·(0-0)+2·(0-0) = 9}. The rst four lines contain two open round brackets, one open curly bracket, one open square bracket, two close round brackets, but no close curly nor square bracket. Therefore the amount of indentation for the fth line is \textbf{9·(2-2)+5·(1-0)+2·(1-0) = 7}. Stylish masters write only well-indented Stylish programs. Every master has his/her own indentation style. Write a program that imitates indentation styles of Stylish masters. \InputFile The input consists of multiple datasets. The first line of a dataset contains two integers \textbf{p} (\textbf{1} ≤ \textbf{p} ≤ \textbf{10}) and \textbf{q} (\textbf{1 }≤ \textbf{q} ≤ \textbf{10}). The next \textbf{p} lines form a well-indented program \textbf{P} written by a Stylish master and the following \textbf{q} lines form another program \textbf{Q}. You may assume that every line of both programs has at least one character and at most \textbf{80}characters. Also, you may assume that no line of \textbf{Q} starts with a period. The last dataset is followed by a line containing two zeros. \OutputFile Apply the indentation style of \textbf{P} to \textbf{Q} and output the appropriate amount of indentation for each line of \textbf{Q}. The amounts must be output in a line in the order of corresponding lines of \textbf{Q} and they must be separated by a single space. The last one should not be followed by trailing spaces. If the appropriate amount of indentation of a line of \textbf{Q}cannot be determined uniquely through analysis of \textbf{P}, then output \textbf{-1} for that line.
Ліміт часу 30 секунд
Ліміт використання пам'яті 128 MiB
Вхідні дані #1
5 4
(Follow.my.style
.........starting.from.round.brackets)
{then.curly.brackets
.....[.and.finally
.......square.brackets.]}
(Thank.you
{for.showing.me
[all
the.secrets]})
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
(I.learned
how.to.use.round.brackets)
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
[I.have.not.learned
how.to.use.square.brackets]
2 2
(Be.smart.and.let.fear.of
..(closed.brackets).go)
(A.pair.of.round.brackets.enclosing
[A.line.enclosed.in.square.brackets])
1 2
Telling.you.nothing.but.you.can.make.it
[One.liner.(is).(never.indented)]
[One.liner.(is).(never.indented)]
2 4
([{Learn.from.my.KungFu
...}])
((
{{
[[
]]}}))
1 2
Do.not.waste.your.time.trying.to.read.from.emptiness
(
)
2 3
({Quite.interesting.art.of.ambiguity
....})
{
(
)}
2 4
({[
..............................................
...
Вихідні дані #1
0 9 14 16
0 9
0 -1
0 2
0 0
0 2 4 6
0 -1
0 -1 4
0 20 40 60
Джерело ACM International Collegiate Programming Contest, Asia Regional Contest, Tokyo, 2012-11-18