P8874 [Chuanzhi Cup #5 Preliminary] F - Two-Person Monopoly Game.

Background

As college students, Renko and Merry have more free time after class than they did in high school. When they have no classes, they like to play Monopoly and share their joys and sorrows during the game. ![](https://cdn.luogu.com.cn/upload/image_hosting/u7z3486k.png) As shown in the figure, this is a Monopoly map with $n=10$. Players move on the circular tiles, while buildings can be constructed on the square tiles. Each circular tile corresponds to exactly one square tile. **(Friendly reminder: gambling is wrong.)**

Description

Renko and Merry are playing a Monopoly game. This Monopoly game is customized by Chuanzhi Podcast, and **it is slightly different from the usual Monopoly rules**, so it is also called Chuanzhi Monopoly. The Monopoly game consists of $n$ tiles, numbered counterclockwise as $1,2,\dots,n$, forming a ring. Renko and Merry both start on tile $1$. At the beginning, both Renko and Merry have $m$ dollars. In each round, Renko rolls the dice first, then Merry rolls the dice. When a player takes an action, let the number on the top face of the die be $k$; then the player moves $k$ steps counterclockwise. During the movement, for every tile the player passes through, there are two cases: - If the current tile (suppose it is numbered $i$) has a building and the building belongs to the moving player, then the moving player can gain an additional $a_i$ dollars. - If the current tile has a building but it belongs to the other player, then the moving player must transfer $a_i$ dollars to the other player. After the movement ends, there are also two cases: - If the current tile (let it be numbered $i$) has no building, then the moving player may choose to pay $C_{i,0}$ dollars (only if the player's current money is at least $C_{i,0}$) to build a building, and then $a_i$ is initialized to $C_{i,0}$. - If the building on the current tile belongs to the moving player, and suppose it is a level $j$ building, then the moving player may choose to spend $C_{i,j}$ dollars to upgrade the building, with the effect $a_i \gets a_i+C_{i,j}$. Here, $C_{i,j}$ is the cost to upgrade the level $j$ building on tile $i$ to a level $j+1$ building. Multiple upgrades can be performed within the same turn. In particular, the maximum building level is $L$. If the current building level has already reached the maximum, it cannot be upgraded. - After all building operations are finished, the control is transferred to the other player. After both players complete one full round, every building on the ring provides money to its owner. Specifically, the building on tile $i$ provides its owner with $d_i$ money. The game ends if and only if there exists a player whose money becomes negative during their action or at the end of their action. That player becomes the loser (in other words, having $0$ money during the process is allowed). Given the operations in each of the $q$ rounds for Renko and Merry, determine who will be the loser.

Input Format

The first line contains four positive integers $n,m,q,L$, representing the number of tiles, the initial money, the number of rounds, and the maximum building level. Starting from the second line, the next $n$ lines each contain $L$ positive integers, representing $C_{i,j}$, where $j$ ranges from $0$ to $L-1$. Line $(n+2)$ contains $n$ positive integers representing $d_i$. Starting from line $(n+3)$, there are several lines, and each line is one of the following two types: - $\texttt{1 k}$, meaning the current player rolled the dice and the top face is $k$. Then the player moves $k$ steps counterclockwise. - $\texttt{2 k}$, meaning the current player performs **building or upgrading** a total of $k$ times at the current position. - During this process, if the current position already has the opponent's building, then this operation is ignored. - If there is not enough money to upgrade $k$ times, then only upgrade to the highest level allowed by the available money. - During this process, if performing the next upgrade would make the building level exceed $L$, then all subsequent upgrades are ignored. In particular, except for the first time, each time an operation $\bm 1$ appears, it means the player switches. That is, when the first $\texttt{1 k}$ operation appears, the acting player is Renko; the second time it is Merry; the third time it is Renko; and so on. Note that an operation $\texttt{2 k}$ **does not** switch the acting player. In addition, it is **guaranteed that after each $\bm 1$ operation, there is at most $\bm 1$ $\bm 2$ operation following it**.

Output Format

If the winner and loser have already been determined, output the loser (output $\texttt{Renko}$ if Renko loses; output $\texttt{Merry}$ if Merry loses). If no winner is determined, output their current money in the order: Renko first, then Merry.

Explanation/Hint

**[Sample Explanation 1]** In the first round, Renko first moves $4$ steps and arrives at tile $5$, and then tries to build and upgrade the building on tile $5$ a total of $3$ times. However, $C_{5,0}+C_{5,1}+C_{5,2}=48$, so she can only build it up to level $2$. At this time, Renko has $16$ dollars left. Next, Merry moves $2$ steps and arrives at tile $3$, and then tries to build and upgrade the building on tile $3$ a total of $5$ times. Since $C_{3,0}+C_{3,1}+C_{3,2}=26$, and upgrading five times would exceed the maximum level $L$, she can only perform $3$ upgrades, and at this time Merry has $14$ dollars left. After the round ends, each building provides its owner with $d_i$ money. That is, Renko now has $21$ dollars, and Merry has $17$ dollars. In the second round, Renko first moves $3$ steps and arrives at tile $2$. Then Merry moves $2$ steps and arrives at tile $5$, and pays/collects $a_i$ money. Since $a_i=24$, Merry's money becomes negative, so output $\texttt{Merry}$. **[Sample Explanation 2]** Only the initial money differs slightly from the first sample, so no winner can be determined within these rounds. Therefore, output the current money of the two players. **[Constraints]** For all data, it is guaranteed that $1 \leq n,L\leq 100$, $1 \leq q \leq 10^4$, $1 \leq m,C_{i,j},d_i \leq 10^6$, $1 \leq k \leq 10^3$ (you do not need to care how to get a die with $k$ faces). The data guarantees that the number of operation $1$ is exactly $2\times q$. Translated by ChatGPT 5