#K84927. Workout Time Calculation

    ID: 36528 Type: Default 1000ms 256MiB

Workout Time Calculation

Workout Time Calculation

Workout Time Calculation

John has planned a sequence of workouts which include Running, Cycling, Swimming, and Weightlifting. Each workout type has a fixed duration given by R, C, S, and W minutes respectively (each between 10 and 120). There is a rule: no two consecutive workouts should be of the same type. Your task is to compute the total time of the workout schedule if it is valid, or output Invalid schedule if it violates the rule.

The input is provided via standard input and the output should be printed to standard output.

inputFormat

Input Format

The first line contains four space-separated integers R, C, S, W representing the durations (in minutes) of Running, Cycling, Swimming, and Weightlifting respectively (10 ≤ each ≤ 120).

The second line contains an integer n (1 ≤ n ≤ 50) representing the number of planned workouts.

Each of the next n lines contains a string which is one of: Running, Cycling, Swimming, Weightlifting.

outputFormat

Output Format

If the workout schedule is valid (i.e. no two consecutive workouts are the same), print a single integer representing the total time (in minutes) of the workouts. Otherwise, print Invalid schedule.

## sample
45 60 30 90
5
Running
Cycling
Running
Swimming
Weightlifting
270