More blocks
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Petryk loves playing games where the world consists of cubes. Today he decided to write his own version of such a game.
Petryk wants this game to allow programming simple mechanisms based on an electrical signal. It is considered that the signal has a certain positive strength, denoted by an integer. Also, the signal can be absent, which is denoted as a signal of strength 0. Petryk added three blocks to the game that process the electrical signal in different ways:
Cable receives a signal of strength \(k\) and outputs a signal of strength \(max(k - 1, 0)\).
Repeater amplifies the signal to level 15 when there is a non-zero input signal, and does not output a signal when it is absent. Formally, let the input signal strength be \(k\). Then the repeater outputs a signal of strength 15 if \(k \ge 1\), and a signal of strength 0 if \(k = 0\).
Inverter does not output a signal when there is a non-zero input signal and outputs a signal of strength 15 when the input signal is absent. Formally, let the input signal strength be \(k\). Then the inverter outputs a signal of strength 0 if \(k \ge 1\), and a signal of strength 15 if \(k = 0\).
Petryk gives you an electric line in which cables, repeaters, and
inverters are denoted by the letters k, p,
z respectively. A signal of strength 15 is applied to the
first element of the line. Help Petryk find the output signal of the
last block in the line.
Input
The first line contains a single integer \(n\) — the number of elements in the electric line.
The second line contains the string \(s\) — the sequence of elements in the electric line.
Output
In a single line, output a single number representing the strength of the output signal of the last element in the line.
Constraints
\(1 \le n \le 10^3\),
The string \(s\) consists only of
the letters k, p, z.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 kkkkk | 10 |
| Input (stdin) | Output (stdout) |
|---|---|
| 5 pkkpk | 14 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 zpkz | 15 |
Notes
Visualization of the explanation for the first three examples is shown in the following image:
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|