As shown in the figure, in the land of Bugcats, there is a Bugcat chat software containing 7 types of memes. Each meme has three attributes:
Now a Bugcat sends you a string. As the maintainer of the software, you need to determine whether the string is an abbreviation or a description, and also find its corresponding ID.
Note that the string sent by the Bugcat is guaranteed to be the abbreviation or description of one of the 7 memes in the table.
The input consists of a single line, representing the string sent by the Bugcat.
It is guaranteed that the string is one of the following: $$$\texttt{/button}$$$, $$$\texttt{/dead}$$$, $$$\texttt{/eat}$$$, $$$\texttt{/fn}$$$, $$$\texttt{/shui}$$$, $$$\texttt{/veg}$$$, $$$\texttt{/you}$$$, $$$\texttt{bugcat-pressing-the-button}$$$, $$$\texttt{bugcat-dead}$$$, $$$\texttt{bugcat-eating}$$$, $$$\texttt{bugcat-angry}$$$, $$$\texttt{bugcat-sleeping}$$$, $$$\texttt{broccolibugcat}$$$, $$$\texttt{fishbugcat}$$$.
Output a single line.
First, output a string $$$\texttt{abbr.}$$$ or $$$\texttt{description}$$$ (in lowercase) indicating whether the input string is an abbreviation or a description, respectively. Then output a space followed by an integer from $$$1$$$ to $$$7$$$, representing the corresponding ID.
/button
abbr. 1
bugcat-angry
description 4
There is a creature known as Bugcat who wants to play a counting game. At the start of the game, Bugcat chooses a fixed integer $$$k$$$. Then, starting from $$$1$$$, Bugcat begins counting upwards, but it will only call out a number if it meets at least one of the following conditions:
1. The number is a multiple of $$$k$$$.
2. The digit $$$k$$$ appears in the decimal representation of the number.
Bugcat wants to know what the $$$x$$$-th number it calls out will be. Since Bugcat is a bit slow and can only count one by one, it has tasked you with finding the answer.
The input consists of two integers, $$$k$$$ and $$$x$$$ ($$$1 \le k \le 9, x \le 10^5$$$).
Print a single integer representing the $$$x$$$-th number that Bugcat calls out.
3 5
13
4 5
16
In the first test case, the numbers Bugcat calls out are $$$3, 6, 9, 12, 13, \dots$$$. The $$$5$$$-th number in this sequence is $$$13$$$.
In the second test case, the numbers Bugcat calls out are $$$4, 8, 12, 14, 16, \dots$$$. The $$$5$$$-th number in this sequence is $$$16$$$.
Bugcat is currently managing a queue. Bugcat has a specific preference: it does not want any duplicate numbers to appear in the queue at the same time. Additionally, all numbers entering the queue must be within the range $$$[1, m]$$$.
You need to process $$$Q$$$ operations. There are three types of operations:
Your task is to output the result for every Type $$$3$$$ operation.
The first line contains two integers: $$$Q$$$ (the number of operations) and $$$m$$$ (the maximum value of elements), where $$$1 \le Q, m \le 10^6$$$.
The next $$$Q$$$ lines describe the operations:
For each Type $$$3$$$ operation, print the result on a new line.
10 101 31 523 13 21 31 51 83 23 3
5 -1 3 8
There are $$$n$$$ elements $$$a_1, a_2, \dots, a_n$$$, each with a lock. Initially, all elements are unlocked.
Given $$$q$$$ queries, the $$$i$$$-th query consists of four integers $$$(t_s, t_e, l, r)$$$, where $$$1 \le l \le r \le n$$$. Each query performs a locking process and an unlocking process on the timeline.
Locking process: Starting from time $$$t_s$$$, in the next $$$r-l+1$$$ time instants, the elements $$$a_l, a_{l+1}, \dots, a_r$$$ are processed in order. Specifically, at time $$$t_s + k$$$, element $$$a_{l+k}$$$ is processed ($$$0 \le k \le r-l$$$). If this element is currently unlocked, it is locked, and the lock is marked as belonging to the current query; if it is already locked by another query, no operation is performed. That is, if when accessing this lock, it has already been locked by another locking process, this lock will not have any changes.
Unlocking process: Starting from time $$$t_e$$$, in the next $$$r-l+1$$$ time instants, the elements $$$a_l, a_{l+1}, \dots, a_r$$$ are processed in order. Specifically, at time $$$t_e + k$$$, element $$$a_{l+k}$$$ is processed ($$$0 \le k \le r-l$$$). If the current lock on this element was added by this query during the locking process, it is unlocked; otherwise, no operation is performed.
For all operations occurring at the same time on the same element, they are executed in ascending order of query index.
For each query, count the number of elements that were successfully locked during its locking process.
The first line contains two integers $$$n, q$$$ ($$$1 \le n, q \le 1000$$$).
The next $$$q$$$ lines each contain four integers $$$t_s, t_e, l, r$$$ ($$$1 \le l \le r \le n, 1 \le t_s \lt t_e \le 10^9$$$), representing a query.
Output $$$q$$$ lines, where the $$$i$$$-th line contains the number of elements successfully locked by the $$$i$$$-th query.
5 53 5 3 42 5 4 52 4 3 52 5 3 51 3 5 5
0 1 2 0 1
5 51 2 5 52 4 3 53 4 1 41 3 3 52 5 1 2
1 0 2 3 2
Two Bugcats are planning to meet up for a gathering. The map they live on consists of $$$n$$$ nodes and $$$m$$$ directed edges. The first Bugcat starts at Node $$$1$$$, and the second Bugcat starts at Node $$$n$$$.
Each edge $$$i$$$ connects node $$$x_i$$$ to node $$$y_i$$$. There are two ways to traverse an edge:
The two Bugcats have a combined total budget of $$$w$$$ dollars. They can choose to take a taxi on any edge at any time, provided they do not exceed their total budget.
Your task is to find the minimum total stamina the two Bugcats must consume in order to meet at the same node, given their budget constraint.If it is impossible for the two Bugcats to meet, output $$$-1$$$.
The input uses multiple test cases.
The first line contains an integer $$$T$$$, the number of test cases.
For each test case, the first line contains three integers $$$n, m, w$$$ ($$$\sum n, \sum m \le 1000, 0 \le w \le 1000$$$), representing the number of nodes, the number of edges, and the total budget.
The next $$$m$$$ lines each contain three integers $$$x_i, y_i, z_i$$$ ($$$1 \le x_i, y_i \le n, 1 \le z_i \le 10^9$$$), representing a directed edge from $$$x_i$$$ to $$$y_i$$$ with a walking stamina cost of $$$z_i$$$.
For each test case, output a single line representing the minimum combined stamina required for the two Bugcats to meet.If it is impossible for the two Bugcats to meet, output $$$-1$$$.
25 5 21 2 31 3 45 4 24 3 12 3 1005 4 21 2 31 3 45 4 22 3 100
1 -1
Little Z is playing a card game. He has $$$N$$$ cards stacked face-up in a pile. Each card has a single uppercase letter printed on its face.
The game requires him to rearrange the cards into a new pile, such that the sequence of letters from top to bottom of the new pile is lexicographically smallest.
Each time, Little Z can only take a card from either the top or the bottom of the current pile, and place it onto the bottom of the new pile. This operation is repeated until all cards have been moved to the new pile.
Given the initial sequence of letters from top to bottom, help Little Z find the lexicographically smallest sequence he can obtain.
The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 5 \times 10^5$$$).
The following $$$N$$$ lines each contain a single uppercase letter, representing the letters on the cards from top to bottom in the initial pile.
Output a string of length $$$N$$$, representing the lexicographically smallest sequence that can be obtained.
6BCBDCA
ABCBCD
A string $$$s$$$ is lexicographically smaller than a string $$$t$$$ if and only if there exists some index $$$i$$$ such that $$$s_1 = t_1,\ s_2 = t_2,\ \ldots,\ s_{i-1} = t_{i-1}$$$, and $$$s_i \lt t_i$$$; or $$$s$$$ is a proper prefix of $$$t$$$. Characters are compared according to alphabetical order, i.e. $$$\texttt{A} \lt \texttt{B} \lt \cdots \lt \texttt{Z}$$$.
For example, $$$\texttt{AABC} \lt \texttt{ABCA}$$$, since at the second position $$$\texttt{A} \lt \texttt{B}$$$.
This is an interactive problem.
In a layered defense system, there is an $$$n \times m$$$ grid. Rows are numbered $$$1$$$ to $$$n$$$ from top to bottom, and columns are numbered $$$1$$$ to $$$m$$$ from left to right. Some cells initially contain obstacles.
An invading drone starts from an empty cell in row $$$n$$$ and attempts to break through upward. You need to place additional obstacles to intercept it before it reaches row $$$1$$$.
Suppose the drone is currently at cell $$$(r, c)$$$. If $$$r \gt 1$$$, it moves upward one row in this round, and its target can only be one of the following three positions: $$$(r - 1, c - 1)$$$, $$$(r - 1, c)$$$, $$$(r - 1, c + 1)$$$. The cell it moves to must satisfy:
If the drone reaches row $$$1$$$, it is considered to have successfully broken through, and your program fails.
After each move of the drone, if it is currently at $$$(r, c)$$$ with $$$r \gt 1$$$, you may place at most one new obstacle. If you choose to place one, the obstacle must be placed in a currently empty cell $$$(x, y)$$$ satisfying $$$x \in \{r - 1, r - 2\}$$$, $$$1 \le x \le n$$$, $$$1 \le y \le m$$$. That is, you can only add an obstacle in the first or second row above the drone's current position. Newly placed obstacles remain permanently; you may also choose not to place any obstacle in that round.
Your goal is to make the drone unable to perform a move at some moment, thereby intercepting it successfully.
It is guaranteed that for every test case, there exists at least one strategy that ensures you can intercept the drone before it reaches row $$$1$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 100$$$), the number of rows and columns of the board.
The next $$$n$$$ lines each contain a string $$$s_i$$$ of length $$$m$$$, describing the initial board state:
It is guaranteed that row $$$n$$$ contains at least one empty cell.
The last line contains two integers $$$r_0$$$ and $$$c_0$$$, the initial position of the drone $$$(r_0, c_0)$$$. It is guaranteed that $$$r_0 = n$$$ and that this cell is initially empty.
After reading the input, you will interact according to the following rules.
After reading the input, you repeatedly perform the following interaction until the process ends:
If your program continues interacting after reading $$$(0, 0)$$$ or $$$(-1, -1)$$$, or fails to follow the interaction protocol, you will also receive Wrong answer.
After outputting, flush the output buffer; otherwise you may get Idleness limit exceeded. For example:
5 5 ..... ..... #.#.. ..#.. ..... 5 3 4 2 0 0
4 4 3 2
The interactor can be adaptive. That is, the drone's moves are not necessarily fixed before the interaction starts.
Initial obstacles and obstacles you place later remain permanently and never disappear.
The drone never enters a cell containing an obstacle.
You must ensure that no matter how the interactor makes moves, your strategy eventually intercepts the drone.
The sample interaction above proceeds as follows:
As a student of The Chinese University of Hong Kong, Shenzhen, Little B got lost when entering the teaching building for the first time (because TB is above TC, and TC is above TD). Years later, Little B became the designer of the new campus teaching building, and now he is designing the cross-sectional view of the building.
The new teaching building will have $$$2n$$$ teaching areas, numbered from $$$1$$$ to $$$2n$$$. The designed footprint length is $$$2n$$$ units, and the building height is limited to $$$n + 1$$$ units, meaning that the cross-sectional view can be regarded as an $$$(n + 1) \times (2n)$$$ grid. Each grid point must contain a number from $$$0$$$ to $$$2n$$$. $$$1 \sim 2n$$$ indicates the teaching area number at that position, and $$$0$$$ means that the position does not belong to any teaching area. Each teaching area must be 4-connected* in the cross-sectional view.
Let $$$a_{i,j}$$$ denote the teaching area number at the grid point in the $$$i$$$-th row and $$$j$$$-th column. We say that teaching area $$$x$$$ is above teaching area $$$y$$$ ($$$x \ne y$$$) if there exist $$$i, j$$$ ($$$1 \le i \le n$$$, $$$1 \le j \le 2n$$$) such that $$$a_{i, j} = x$$$, $$$a_{i + 1, j} = y$$$.
For structural clarity and elegance, Little B has determined $$$(2n - 1)$$$ relations. The $$$i$$$-th relation is of the form "teaching area $$$x_i$$$ is above teaching area $$$y_i$$$". If we add a directed edge from $$$x_i$$$ to $$$y_i$$$, the $$$2n$$$ teaching areas exactly form a downward tree** rooted at teaching area $$$1$$$.
Now, you need to design a valid cross-sectional view (i.e., assign a teaching area number to each grid cell) such that the directed graph corresponding to this cross-sectional view is exactly the same as the tree given by Little B. (That is, the relationships specified by Little B must be satisfied, while the relationships not specified by Little B must not be satisfied.)
Please output any valid filling scheme, or report that no solution exists.
*4-connected: A set of grid points is called 4-connected if any two points in the set can be connected by a sequence of adjacent (up, down, left, right) grid points that also belong to the set.
**Downward tree: A rooted tree with a specified root, where every edge is directed from the parent to the child (i.e., from the upper level to the lower level). In this problem, the given $$$2n - 1$$$ relations "teaching area $$$x_i$$$ is above teaching area $$$y_i$$$" correspond to directed edges $$$x_i \to y_i$$$, and these edges form a downward tree rooted at $$$1$$$.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 500$$$), indicating the number of test cases.
For each test case, the first line contains an integer $$$n$$$ ($$$1 \le n \le 500$$$).
Then $$$2n - 1$$$ lines follow, each containing two integers $$$x_i, y_i$$$, representing a relation. It is guaranteed that the input forms a downward tree rooted at $$$1$$$.
It is also guaranteed that $$$\sum n \le 2000$$$.
For each test case:
121 21 32 4
2 1 1 12 2 2 34 4 0 3
Bugcat is playing a game. The game provides an undirected graph where each node contains a monster. A monster may also have zero or one minion. A node is considered unlocked only after you defeat all enemies (including the minion, if it exists) at that node. You can move to a node if and only if it is connected to at least one already unlocked node.
However, you do not necessarily need to defeat all enemies when you visit a node. Specifically, you may choose to defeat only the monster's minion and then leave for other nodes. In this case, the node remains locked.
The player starts with an initial HP $$$x$$$. When attempting to kill an enemy with HP $$$y$$$, if $$$x \ge y$$$, the enemy is defeated and the player's HP increases by $$$y$$$ (i.e., $$$x \leftarrow x + y$$$). Otherwise, the player dies immediately.
Maomaochong asks for your help. He provides the undirected graph and the initial HP of the monster at each node (initially, no monsters have minions). There are multiple operations of two types:
The first line contains three integers $$$n, m, q$$$ ($$$1 \le n, m, q \le 2 \times 10^5$$$), representing the number of nodes, edges, and queries.
The second line contains $$$n$$$ integers representing the health of the monster at each node $$$h_i$$$ ($$$1 \le h_i \le 10^6$$$).
The next $$$m$$$ lines each contain two integers $$$x, y$$$ representing an undirected edge between node $$$x$$$ and $$$y$$$. There are no self-loops or multiple edges.
The next $$$q$$$ lines start with an operation type $$$op$$$:
For each Query, output a single integer representing the maximum possible final health.
5 5 51 2 6 6 81 21 31 44 53 52 2 21 3 22 2 21 4 52 4 4
5 27 4
During the Lunar New Year, Bugcat has been playing a Mahjong-themed "roguelike" game (similar to Balatro). In this game, Bugcat draws tiles from a deck and discards them, and it has perfect knowledge of the tile sequence in the "wall" (the deck).
Bugcat starts wondering: if there is a Mahjong set with $$$n$$$ distinct types of tiles, what is the expected number of tiles drawn (including the initial $$$13$$$ tiles) to complete a "Four Concealed Pongs" (Sūankō) hand, assuming optimal play? Output the result modulo $$$10^9 + 7$$$.
Definitions:
Simplified Problem Statement:
There are $$$4n$$$ tiles, categorized into $$$n$$$ colors (types), with $$$4$$$ tiles per color. Even tiles of the same color are considered distinct.
Consider all $$$(4n)!$$$ possible permutations of the deck. For a given permutation, let the "cost" be the smallest index $$$i$$$ such that among the first $$$i$$$ tiles in the sequence, the following two conditions are met:
Find the expected value of the cost $$$i$$$ over all possible permutations. Output the result modulo $$$10^9 + 7$$$.
A single integer $$$n$$$ ($$$1 \le n \le 2 \times 10^6$$$), representing the number of tile types.
A single integer representing the expected cost modulo $$$10^9 + 7$$$.
5
80495372
4
0
A tree by the river can be described as a form with $$$x$$$ nodes numbered $$$1 \sim x$$$:
Little B cannot remember such an abstract concept as a "tree", so he invented two ways to turn a tree into a permutation:

It can be proved that after visiting all nodes, the elements in $$$q$$$ form a permutation of $$$1 \sim x$$$.
A permutation is called ambiguous if it can be obtained from some tree $$$t_1$$$ by method 1 and also from some tree $$$t_2$$$ by method 2. Note that the two trees may be identical, i.e., $$$t_1$$$ may equal $$$t_2$$$.
The bugcat only remembers the positions of $$$1 \sim n$$$ in a permutation $$$a$$$ of length $$$n + m$$$, and asks you to determine, among all possible permutations, how many are ambiguous.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^5$$$) indicating the number of test cases.
For each test case, the first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le m \le 80$$$, $$$1 \le (n + m) \le 10^5$$$).
The second line contains $$$n + m$$$ integers $$$a_{1\sim {n + m}}$$$ ($$$0 \le a_i \le n$$$). If $$$a_i = 0$$$, it means that the bugcat does not remember the value at position $$$i$$$. It is guaranteed that each number from $$$1$$$ to $$$n$$$ appears exactly once in $$$a$$$.
It is also guaranteed that $$$\sum (n + m) \le 3 \times 10^5$$$.
For each test case, output a single integer representing the number of ambiguous permutations, modulo $$$10^9 + 7$$$.
33 01 2 34 11 2 3 0 43 51 2 3 0 0 0 0 0
11109
For the second sample, the only possible permutation is $$$1, 2, 3, 5, 4$$$. It can be obtained from the first tree by method 1, and also from the second tree by method 2, thus it is ambiguous.
There are $$$2 ^ n$$$ bugcats, each with a distinct attribute that can be represented as a number from $$$0$$$ to $$$2 ^ n - 1$$$.
These bugcats are to be paired into $$$2 ^ {n - 1}$$$ groups (each group contains exactly two bugcats) to dine in the restaurant. The bugcats are kind-hearted, so no bugcat appears in more than one group.
The restaurant has $$$2 ^ {n - 1} + 1$$$ tables for two, numbered from $$$1$$$ to $$$2 ^ {n - 1} + 1$$$. It is required that the XOR of the attribute values of the two bugcats at each table equals the table number.
However, Little B, who came to the restaurant alone, has already taken the quietest table $$$x$$$. (That is, table numbered $$$x$$$ cannot be used by the bugcats.)
Can you provide a pairing such that all bugcats in different groups can be seated at different tables for two, and Little B does not move?
The input consists of a single line with two integers $$$n, x$$$ ($$$1 \le n \le 20, 1 \le x \le 2 ^ {n - 1} + 1$$$).
The first line of output should be a string $$$\texttt{YES}$$$ or $$$\texttt{NO}$$$ indicating whether such a pairing exists.
If it exists, output $$$2 ^ {n - 1}$$$ lines, each containing two integers $$$x_i, y_i$$$, indicating that the bugcats with attributes $$$x_i$$$ and $$$y_i$$$ are in the same group.
The groups can be output in any order. If multiple solutions exist, output any one.
3 1
YES 5 7 0 3 2 6 1 4
2 1
NO
3 2
NO
1 2
YES 0 1