#P5587. Typing Practice KPM

    ID: 18817 Type: Default 1000ms 256MiB

Typing Practice KPM

Typing Practice KPM

R is practicing typing on a specialized website. On the website, a reference text (model text) is given along with an input area. The website accepts only lowercase letters, spaces, and the period character ('.'). The user types characters and the cursor moves accordingly. The user may use the Enter key to move to a new line and may also use the Backspace key (represented by '<') to delete the previously entered character in the same line (if any; if the cursor is at the beginning of a line, the backspace has no effect).

The website compares the reference text and the final processed input text under the following principles:

  • Line-by-line comparison: Each line from the reference text is compared with the corresponding line from the input text. Any extra lines (either in the reference text or input) are ignored.
  • Character-by-character comparison: For each pair of corresponding lines, characters are compared at the same positions. A character is counted as correct if and only if it exactly matches the corresponding character in the reference text. Note that the Enter (newline) key is not counted as a character.

After finishing the typing test, the website displays that R spent T seconds on the test. Your task is to compute his Keys Per Minute (KPM), which is defined as:

[ KPM = \frac{\text{number of correct characters}}{T} \times 60 ]

Round the result to the nearest integer (round half up).

inputFormat

The input is given in the following format:

T
N
reference_line_1
reference_line_2
... (N lines in total)
M
typed_line_1
typed_line_2
... (M lines in total)

Where:

  • T is an integer representing the total time in seconds.
  • N is the number of lines in the reference text, followed by N lines of the reference text.
  • M is the number of lines in the keystroke input, followed by M lines of characters which may include lowercase letters, spaces, periods ., and the backspace character represented by <. In each of these M lines, process the characters from left to right. Each '<' deletes the last character of that line if it exists; if the line is empty, the '<' is ignored.

outputFormat

Output a single integer: the computed KPM (Keys Per Minute), calculated as the rounded value of \( \frac{\text{correct character count}}{T} \times 60 \).

sample

60
1
hello world
1
hello world
11

</p>