#P2614. 计算器弹琴

计算器弹琴

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.

+ 低音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 11 beat.

1- is a half note, taking 22 beats.

1--- is a whole note, taking 44 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.50.5 beat.

3 and 4 are inside two layers of parentheses, so they are sixteenth notes, taking 0.250.25 beat.

5 and 6 are inside three layers of parentheses, so they are thirty-second notes, taking 18\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/21/2 of its original duration.

For example, 1-. is 33 beats, 1. is 1.51.5 beats, and in (3.(45.)), 3 is 34\dfrac{3}{4} beat, 4 is 14\dfrac{1}{4} beat, and 5 is 38\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 TT, 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,Tn, T, the number of lines of the score and the beats per minute.

The next nn 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.

2 60
3345 5432 1123 322-
3345 5432 1123 211-
32

5 120
3(1.(3))55 8(7.(6))65 655(3.(1)) (4.(4))32- 
3(1.(2))35 8(7.(6))65 655(4.(3)) (2.(3))21- 
2.(3)44 6(6.(6))(5.(4))3 3.(5)88 (9.(8)7.(6))5-
=.(=)(9.(8))7 9.(8)(7.(6))5  8(856543) (2.(3))43- 
=.(=)(9.(8))7 9.(8)(7.(6))5  8(857654) (3.(4))21- 
40

Hint

  • Sample Explanation

For the first sample, there are 2828 quarter notes and 22 half notes, totaling 3232 beats. With 6060 beats per minute, the total time is 3232 seconds.

  • Constraints

For 40%40\% of the testdata, the characters (, ), and . do not appear.

For 100%100\% of the testdata, 1n100, 50T2001 \le n \le 100,\ 50 \le T \le 200, and each line contains at most 100100 characters.

Translated by ChatGPT 5