P2614 Playing Piano on a Calculator
Background
Xiao A discovered another hidden feature of a calculator — playing piano.

Description
In a certain mode of the calculator, pressing a key, for example `1`, will produce the middle pitch `Do`.
Here is the key-to-pitch table.
```plain
+ 低音Fa
< 低音So
* 低音La
/ 低音Xi
1 中音Do
2 中音Re
3 中音Mi
4 中音Fa
5 中音So
6 中音La
7 高音Xi
8 高音Do
9 高音Re
= 高音Mi
% 高音Fa
C 高音So
M 高音La
```
Now Xiao A has obtained a piece of sheet music — we call it calculator notation, a variant of numbered musical notation (jianpu).
Durations (i.e., how long you press) are recorded as follows, for example:
`1` is a quarter note, taking $1$ beat.
`1-` is a half note, taking $2$ beats.
`1---` is a whole note, taking $4$ beats.
For notes shorter than a quarter note, we use nested parentheses, for example:
`(1(34(56))2)`
`1` and `2` are inside one layer of parentheses, so they are eighth notes, taking $0.5$ beat.
`3` and `4` are inside two layers of parentheses, so they are sixteenth notes, taking $0.25$ beat.
`5` and `6` are inside three layers of parentheses, so they are thirty-second notes, taking $\dfrac{1}{8}$ beat.
At most thirty-second notes will appear in the testdata; there are no shorter notes.
The symbol `-` will not appear inside parentheses.
Adding a dot `.` after a note means the note is extended by $1/2$ of its original duration.
For example, `1-.` is $3$ beats, `1.` is $1.5$ beats, and in `(3.(45.))`, `3` is $\dfrac{3}{4}$ beat, `4` is $\dfrac{1}{4}$ beat, and `5` is $\dfrac{3}{8}$ beat.
There will not be two or more consecutive dots. A whole note will not be dotted.
Ignore other musical symbols.
In addition, the entire score provides an integer $T$, the number of beats per minute.
For readability, the score may contain arbitrary line breaks and spaces. They can be ignored when reading the input.
Now Xiao A wants to know how many seconds it takes to finish playing this score.
Input Format
The first line contains two integers $n, T$, the number of lines of the score and the beats per minute.
The next $n$ lines contain the score.
Output Format
Output a single integer: the total time in seconds needed to perform the score. If the exact time is fractional, round down to an integer.
Explanation/Hint
- Sample Explanation
For the first sample, there are $28$ quarter notes and $2$ half notes, totaling $32$ beats. With $60$ beats per minute, the total time is $32$ seconds.
- Constraints
For $40\%$ of the testdata, the characters `(`, `)`, and `.` do not appear.
For $100\%$ of the testdata, $1 \le n \le 100,\ 50 \le T \le 200$, and each line contains at most $100$ characters.
Translated by ChatGPT 5