Counter with step and reset via closure

JavaScript Medium closures

Task «Counter with step and reset via closure»

Implement the createCounter function, which takes an initial value start and a step step. The function should return an object with three methods: increment() — increases the current value by step and returns it, decrement() — decreases it by step and returns it, reset() — resets the value to the initial start. Use closures to store the state. The initial value start and step step are integers.

Input Format

First line: start (integer). Second line: step (integer). Third line: number of calls n (integer, 1 ≤ n ≤ 20). Next n lines, each contains one command: 'increment', 'decrement', or 'reset'.

Output Format

For each command, output the current value of the counter after executing the command, each on a new line.

Examples

Example 1

INPUT
10 3 3 increment increment decrement
OUTPUT
13 16 13

Example 2

INPUT
-5 2 4 decrement decrement increment reset
OUTPUT
-7 -9 -7 -5

Example 3

INPUT
5 4 6
OUTPUT
78.54 24.00
main.js