White, Dark, Mint Chocolate
Time limit1sMemory limit1024 MB
Given a bottom row of W, D, and M chocolates, report the top chocolate's kind after each single-position change to the bottom row.
- Level
Medium7 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Coco wants to decorate one wall of a room with three kinds of chocolate arranged in a triangle. The procedure is as follows.
- First, fill the bottom row with chocolates of any kinds.
- For each row above, look at the two chocolates directly below each cell and choose the kind as follows.
- If the two chocolates are the same kind, place a chocolate of that kind. (Example: above two white chocolates, place a white chocolate.)
- If the two chocolates are different kinds, place a chocolate of the kind that is neither of them. (Example: above a mint chocolate and a white chocolate, place a dark chocolate.)
The finished decoration is shown below.

Coco has not yet decided the design of the bottom row, so Coco changes one chocolate at a time and considers the result. Each time Coco changes a chocolate, report the kind of chocolate on the top.
Input
The first line contains the number of chocolates in the bottom row. ()
The next line contains a string of length that gives the kinds of the chocolates. White chocolate is W, dark chocolate is D, and mint chocolate is M.
The next line contains the number of changes . ()
Each of the next lines contains a position of the chocolate to change and the new kind . (, is one of W, D, M) All changes accumulate.
Output
On the first line, print the kind of the top chocolate for the initial state.
On each of the next lines, print the kind of the top chocolate after each change.