Hamburger
InterviewTime limit1sMemory limit1024 MB
Given a string S of bread, patty, lettuce, and tomato, check whether it is a valid hamburger: bread at both ends, no equal neighbors, and counts within A, B, C, D.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
haru_101 has pieces of bread, patties, lettuce leaves, and tomato slices, all of the same kind. Stack the ingredients under the following rules, and call the result a tasty hamburger.
- Stack the ingredients from bottom to top.
- The bottom ingredient and the top ingredient must both be bread.
- Two adjacent ingredients cannot be the same.
- Not every ingredient has to be used, but the hamburger must be made only from the ingredients on hand.
haru_101 wrote the hamburger to make as a string . Write a program that determines whether this hamburger is a tasty hamburger.
Input
The first line contains the length of the string .
The second line contains the integers , , , and , separated by spaces.
The third line contains the string , which consists only of the lowercase letters a, b, c, and d. The leftmost character of is the bottom ingredient, and the rightmost character is the top ingredient. a is bread, b is a patty, c is lettuce, and d is a tomato.
Output
Print Yes if the hamburger made from is a tasty hamburger. Otherwise, print No.
Constraints
- , , , and are non-negative integers