P28588 [洛谷] Calculator Piano
普及
题目描述

Problem Description

As is well known, calculators can be used for many tasks they were not originally designed for, such as writing essays (refer to Luogu P2549).

Little A has discovered another hidden feature of calculators—playing music.

http://www.bilibili.com/video/av2205500/

Pressing a key, for example, '1', will produce the middle "Do" note.

Here is the table of key-to-pitch mapping:

+ Low Fa
< Low So
* Low La
/ Low Xi
1 Middle Do
2 Middle Re
3 Middle Mi
4 Middle Fa
5 Middle So
6 Middle La
7 High Xi
8 High Do
9 High Re
= High Mi
% High Fa
C High So
M High La

Little A has obtained a musical score—which we call a calculator score, a modified simple score.

The duration (i.e., the length of time a key is pressed) is recorded as follows:

  • '1' is a quarter note, lasting 1 beat.
  • '1-' is a half note, lasting 2 beats.
  • '1---' is a whole note, lasting 4 beats.

For notes shorter than a quarter note, nested parentheses are used, for example:

  • '(1(34(56))2)'
  • '1' and '2' in the first layer of parentheses are eighth notes, lasting 0.5 beats.
  • '3' and '4' in the second layer of parentheses are sixteenth notes, lasting 0.25 beats.
  • '5' and '6' in the third layer of parentheses are thirty-second notes, lasting 1/8 beats. This is quite rare.

The symbol '-' will not appear inside parentheses.

There will not be more than four layers of parentheses.

Adding a dot ' . ' after a note extends its duration by half.

For example:
- '1-. ' is 3 beats, '1. ' is 1.5 beats, '(3.(45.))3' is 3/4 beats, '4' is 1/4 beats, '5' is 3/8 beats.

Dots will not be added consecutively more than once, and no note will last more than four beats.

Other musical symbols are not considered.

Additionally, the score will specify a tempo, an integer indicating how many beats per minute.

For aesthetics, the score may be arbitrarily broken into lines and spaces. These can be ignored.

Now, Little A wants to know how long it will take (in seconds) to play this score.

Input Format

The first line contains two integers n and T, representing the number of lines in the score and the tempo (beats per minute), respectively.

The next n lines provide the score.

Output Format

An integer representing the time required to play the score, in seconds, with the decimal part truncated.

Sample Input and Output

Input Sample #1

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

Output Sample #1

32

Input Sample #2

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- 

Output Sample #2

40

Notes/Hints

  • Sample 1 Explanation: (A total of 32 beats, 60 beats per minute, so it takes 32 seconds. By the way, this is the beginning of "Ode to Joy")
  • Sample 2 Explanation: (A total of 80 beats, I won't tell you how I counted them, but at 120 beats per minute, it takes 40 seconds. As for what piece this is? Due to relevant laws and policies, this part is not displayed.)

http://bd.kuwo.cn/yinyue/4641527

  • For 40% of the data, there are no dots or parentheses.
  • For 100% of the data, the number of parentheses layers does not exceed 3, there are no more than 100 lines, and each line does not exceed 100 characters.
  • One of the data sets is "Senbonzakura".
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 60 3345 5432 1123 322- 3345 5432 1123 211-
样例输出
32