p02175 Strange Plants_16179
problem

A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties.

* Say "nobiro" to this plant and it will grow $ A $ [cm].
* Say "tidime" to this plant and it will grow $ B $ [cm].
* If you say "karero" to this plant, it will be $ 0 $ [cm].



However, this plant does not have a negative length. Specifically, when it grows from the state of $ C $ [cm] to $ D $ [cm] $ (C + D \ lt 0) $, it is a plant. Stops growing when it reaches $ 0 $ [cm].

Say one of "nobiro", "tidime", "karero" to this plant only once a day for $ N $ days. Find the length [cm] of the plant after $ N $ days.



output

Print the length of the plant after $ N $ days. Also print a newline at the end.

Example

Input

10 30 10
3
nobiro
nobiro
tidime


Output

80
import java.util.*;

class Plant {
    private int length;
    private int glowthOfNobiro;
    private int glowthOfTidime;

    public Plant(int length, int glowthOfNobiro, int glowthOfTidime) {
        this.length = length;
        this.glowthOfNobiro = glowthOfNobiro;
        this.glowthOfTidime = glowthOfTidime;
    }

    public void growPlant(String message) {
        if (message.equals("nobiro")) {
            this.length += this.glowthOfNobiro;
            if (this.length < 0) {
                this.length = 0;
            }
        } else if (message.equals("tidime")) {
            this.length += this.glowthOfTidime;
            if (this.length < 0) {
                this.length = 0;
            }
        } else if (message.equals("karero")) {
            this.length = 0;
        }
    }

    public int getLength() {
        return this.length;
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        Plant plant = new Plant(X, A, B);

        int N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            String S = sc.next();
            plant.growPlant(S);
        }

        System.out.println(plant.getLength());
    }
}


