Hailing from a long lost tribe of vastaya, Neeko can blend into any crowd by borrowing the appearances of others, even absorbing something of their emotional state to tell friend from foe in an instant. No one is ever sure where — or who — Neeko might be, but those who intend to do her harm will soon witness her true colors revealed, and feel the full power of her primordial spirit magic unleashed upon them.
Source: https://bilibili.com/BV1ub421e7cd/ Neeko has infiltrated a grid of characters with dimensions $$$n \times m$$$, each cell in the grid is represented by a string of length $$$k$$$. She can mimic the other cells; however, Neeko's cell has at least one character different from the other cells while all the other cells are the same. Your task is to find Neeko.
The first line of the input contains three integers $$$n, m, k ~(2 \leq n, m \leq 200, 1 \leq k \leq 10)$$$.
The next $$$n$$$ lines contain $$$m \cdot k$$$ characters each, consisting of visible ASCII characters from !(33) to (126). The $$$((j - 1) \cdot k + 1)$$$-th to the $$$(j \cdot k)$$$-th character in the $$$i$$$-th line represents the cell $$$(i, j)$$$.
It's guaranteed that there is no extra space or line break, and the answer can be uniquely determined.
Print two integers $$$r, c$$$, denoting the position of Neeko is in the $$$r$$$-th row and the $$$c$$$-th column.
3 5 3QWQQWQQWQQWQQWQQWQQWQQWQQWQQWQQWQQWQQWQQWQQwQ
3 5
You are given some special Tarot cards from the Major Arcana, including The Lovers, Death, The Star, The Moon, The Sun, and The World, along with some other playing cards in hand. You have at most one of each kind of Tarot card, and each Tarot card has a unique ability that can alter the suits of other playing cards in your hand. Your task is to determine the maximum number of flushes that can be played by the playing cards in hand after using the given Tarot cards each at most once.
The playing cards are standard playing cards, shown as below.
Here is a list of Tarot cards abilities.
![]() | ![]() | ![]() | ![]() |
![]() | ![]() |
You can use the Tarot cards in any order. Each given Tarot card can be used at most once and can never be used at all. There is a special rule about The Lovers:
A flush is a set of $$$5$$$ playing cards, which could be considered a same suit: there is a suit (among Diamond, Club, Heart, and Spade) such that each of the $$$5$$$ playing cards is either of this suit or is a Wild Card.
Playing a flush means that the $$$5$$$ cards forming the flush are discarded from hand, all of which cannot be used in another flush. To the contrary of many card games including Balatro, you draw no new cards from the deck after playing cards.
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 13$$$) — the number of test cases. The description of the test cases follows.
The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 52$$$), the number of playing cards in hand.
The second line contains $$$n$$$ space-separated strings, each representing a playing card in hand. Each playing card is represented by two characters: one for rank and one for suit, where the suit is one of D (Diamonds), C (Clubs), H (Hearts), or S (Spades), and the rank is one of 2-9, T (10, Ten), J (Jack), Q (Queen), K (King), or A (Ace).
The third line contains six space-separated integers $$$t_1, t_2, t_3, t_4, t_5, t_6 ~ (0 \leq t_i \leq 1)$$$, where:
It is guaranteed that the sum of $$$n$$$ among $$$T$$$ test cases does not exceed $$$104 = 52 \times 2$$$, and the playing cards are pairwise distinct in each test case.
For each test case, print the maximum number of flushes that can be played in a single line.
452H 3H 4H 5H 6D1 1 1 1 0 052S 3S 4D 5C 6D0 0 1 0 1 152S 3S 4D 5C 6D0 0 1 0 1 013AS 2S 3S 4S 5H 6H 7H 8H 9H TH JH QH KH0 0 0 0 0 1
1 1 0 2
In the first case, we can convert $$$6 \diamondsuit$$$ into $$$6 \heartsuit$$$ using The Sun, and play $$$2 \heartsuit 3 \heartsuit 4 \heartsuit 5 \heartsuit 6 \heartsuit $$$ as a flush. This is not the only possible way; another possible way to play the same set of cards is:
In the second test case, one possible way to play a flush is:
Note: This is the inverse version of problem "The Emperor" with differences in constraints.
Capoo invented an interesting language named Push-Pop. This language is an interpreted language. The interpreter starts with an empty stack with infinite capacity and reads the first instruction of the custom program. There are only two kinds of instructions in this language:
If the top element of the stack is $$$a$$$, then pop the stack once and transfer the control flow to the $$$x$$$-th instruction (which means the next instruction will be the $$$x$$$-th). Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
If the stack is empty, halt the whole program after executing this instruction. Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
Capoo wants to construct a Push-Pop program that halts after executing exactly $$$k$$$ instructions. Due to the naive implementation of the interpreter, a program can contain at most $$$64$$$ instructions.
The only line contains a single integer $$$k$$$ ($$$1\le k \le 2^{31} - 1$$$, $$$k$$$ is odd).
The first line contains an integer $$$n ~(1\le n\le 64)$$$ denoting the number of instructions, and then follows $$$n$$$ lines denoting the Push-Pop program. For each instruction, $$$1\le a,b\le 128,~ 1\le x,y\le n$$$ should hold.
It is guaranteed that a solution exists for given input.
1
1 HALT; PUSH 1 GOTO 1
5
5 POP 1 GOTO 2; PUSH 1 GOTO 2 HALT; PUSH 1 GOTO 3 POP 1 GOTO 4; PUSH 2 GOTO 4 POP 1 GOTO 2; PUSH 2 GOTO 4 HALT; PUSH 99 GOTO 4
For the second example, instructions are: 1(PUSH), 2(PUSH), 3(POP), 4(POP), 2(HALT).
Key differences in constraints comparing to "The Emperor":
Note: This is the inverse version of problem "The Empress" with differences in constraints.
Capoo invented an interesting language named Push-Pop. This language is an interpreted language. The interpreter starts with an empty stack with infinite capacity and reads the first instruction of the custom program. There are only two kinds of instructions in this language:
If the top element of the stack is $$$a$$$, then pop the stack once and transfer the control flow to the $$$x$$$-th instruction (which means the next instruction will be the $$$x$$$-th). Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
If the stack is empty, halt the whole program after executing this instruction. Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
Capoo wants to upgrade the naive interpreter to deal with more instructions. Given a program of at most $$$1024$$$ instructions, calculate the number of steps the program would execute before halting.
The first line contains an integer $$$n$$$ ($$$1\le n\le 1024$$$), followed by $$$n$$$ lines containing one instruction each. It is guaranteed that $$$1\le a,b\le 1024,~ 1\le x,y\le n$$$ for each instruction.
Print $$$-1$$$ if the program will never halt, or the number of instructions would execute, modulo $$$998\,244\,353$$$.
1HALT; PUSH 1 GOTO 1
1
5POP 1 GOTO 2; PUSH 1 GOTO 2HALT; PUSH 1 GOTO 3POP 1 GOTO 4; PUSH 2 GOTO 4POP 1 GOTO 2; PUSH 2 GOTO 4HALT; PUSH 99 GOTO 4
5
1POP 1 GOTO 1; PUSH 1 GOTO 1
-1
Key differences in constraints comparing to "The Empress":
In the ever-changing and chaotic environment of Night City, uncertainty is the only certainty. For safe travel, edgerunners rely on the best technology. Despite their premium price and corporation background, Delamain AI armed cabs provide the most reliable mode of transportation.
Today, you need to make a lengthy journey across Night City. The Delamain cab's fare structure is as follows:
At any point, you may perform the following operation: stop and re-hail a cab. By doing so, you will immediately settle the cost of your previous cab, and the fare for the next one will be recalculated starting from the base fare. This operation can be performed for any number of times.
Now, you want to determine the minimum cost in eurodollars for traveling $$$D$$$ meters using Delamain cabs.
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 2077$$$) — the number of test cases. The description of the test cases follows.
The input contains six integers in a line: $$$ A, B, C, X, Y, D ~ (0 \lt A, B, C, X, Y, D \lt 10 ^ {2077})$$$ in decimal representation, without leading zeros.
It is guaranteed that the sum of the number of digits of $$$A$$$ among $$$T$$$ test cases does not exceed $$$\texttt{0x2077}$$$. This constraint also applies individually to $$$B, C, X, Y, D$$$.
The value $$$\texttt{0x2077}$$$ used in the constraint is a hexadecimal number, equal to the decimal number $$$8311$$$.
For each test case, output a single line containing the minimized cost in eurodollars for traveling $$$D$$$ meters using Delamain's cabs.
It can be proven that the answer is a positive integer. Please print the integer in decimal form without leading zeros.
5160 27 41 3 12 3160 27 41 3 12 4160 27 41 3 12 991 999 999 1 99 999999 999 1 1 99 9999999999999999
160 187 3226 999 10000000000099799
For the fourth sample, the optimal solution is to hail $$$999$$$ cabs, hailing a new one every meter. It seems quite weird, but you are confident that this is the optimal way to live the life in Night City.
The renowned alchemist Xu Dog discovered that precisely removing impurities could enhance the spiritual essence of the elixirs he was refining. Through day after day of alchemy, he found that the nature of these impurities was intricately related to mathematical problems. Since your progress in Dao is still shallow, Xu Dog decided to tell you the mathematical problem he needs to solve in the most straightforward way, rather than through the esoteric problems of alchemy.
Given two positive integers $$$n \leq m$$$, calculate the sum of the answers to the following problem for all subsets of size $$$n$$$ of $$$\{1, 2, \dots, m\}$$$, modulo $$$998\,244\,353$$$:
The greatest common divisor of a set is defined as the largest value among the common divisors of all elements in the set. For example, the greatest common divisor of the set $$$\{6, 9, 15\}$$$ is $$$3$$$.
Input consists of a single line containing two integers $$$m, n~ (1 \leq n \leq m \leq 10 ^ 5)$$$.
Output an integer representing the answer, modulo $$$998\,244\,353$$$.
4 3
7
11 4
1187
100000 99999
17356471
For the first example, all cases are listed below:
Therefore, the answer is $$$2 + 0 + 2 + 3 \bmod 998\,244\,353 = 7$$$.
The Hierophant and The High Priestess are fascinated by the mysteries of the universe. To explore some of these mysteries on Earth — apparently a part of the universe, they used a strange wheel to study the effect of gravity on random processes.
The wheel is a convex polygon, divided into several triangular regions by lines connecting the center of rotation to each vertex, with each triangular region representing a prize. After spinning the wheel, the prize is determined by the region directly below the stopping position. An unbiased wheel has its center of rotation at its centroid, making the final winning position dependent solely on the angle occupied by each region. Unfortunately, the wheel here may be biased: when the center of rotation is not at the centroid, the result of the wheel is always directed from the center of rotation to the centroid.
Clearly, a biased wheel is boring. To make various wheels meaningful, The Hierophant decided to perturb the result in the following way: placing a small magnetic weight at a uniformly random position within the wheel's area (considered as a point mass located inside the convex polygon) will change the centroid, thus affecting the result.
The first sample: the case without a magnet, and a possible case where the magnet changes the result. The mass of the magnet is $$$w$$$, and the mass per unit area of the wheel is uniformly $$$1$$$. The High Priestess wants to know the probability that each region becomes the final winning region after the aforementioned perturbation.
It can be shown that the set of configurations where the wheel fails to uniquely determine the winning region (e.g., the center of rotation coincides with the centroid or lies on the boundary) has measure $$$0$$$, so you can safely ignore such cases.
The first line contains two integers $$$n, w ~(3 \leq n \leq 100000, 1 \leq w \leq 10^9)$$$, representing the number of vertices of the wheel and the mass of the magnet.
The next $$$n$$$ lines each contain two integers $$$x_i, y_i ~ (|x_i|, |y_i| \leq 30000)$$$, representing the coordinates of the $$$i$$$-th vertex of the wheel, given in counterclockwise order along the boundary.
The last line contains two integers $$$O_x, O_y ~ (|O_x|, |O_y| \leq 30000)$$$, representing the coordinates of the center of rotation, which is strictly inside the convex polygon.
The vertices of the wheel are all distinct, but three points may be collinear: it is guaranteed that when three adjacent points $$$u, v = (u \bmod n) + 1, w = (v \bmod n) + 1$$$ are collinear, point $$$v$$$ is strictly on the segment connecting $$$u$$$ and $$$w$$$, which ensures that all interior angles are within the range $$$(0, \pi]$$$.
It is guaranteed that the area $$$S$$$ of the wheel satisfies: $$$\max \left\{ \frac S w, \frac w S \right\} \leq 1000$$$.
Output $$$n$$$ lines, each containing a real number $$$p_i$$$, representing the probability that the region bounded by the line connecting the $$$i$$$-th vertex and the $$$(i \bmod n) + 1$$$-th vertex is the final winning region. The answer will be considered correct if it has an absolute or relative error not exceeding $$$10^{-6}$$$.
5 51 03 04 22 40 22 2
0.313777778 0.235555556 0.107555556 0.107555556 0.235555556
8 80 01 02 02 12 21 20 20 11 1
0.125000000 0.125000000 0.125000000 0.125000000 0.125000000 0.125000000 0.125000000 0.125000000
3 3-1 -101 -100 10 0
1.000000000 0.000000000 0.000000000
4 36000000-30000 -3000030000 -3000030000 30000-30000 300001 0
0.249998611 0.248327778 0.249998611 0.251675000
4 25005 05 50 50 01 1
0.402977500 0.402977500 0.097022500 0.097022500
People often use approximate methods to express numerical values in everyday conversations. Whether discussing time, money, or other numbers, people tend to round off to make communication simpler and easier. For example, if you and your friends dine at a restaurant with a bill of $$$98$$$ yuan, many would say, "The bill is a hundred yuan," instead of using the exact number.
If we take a more aggressive approach and round multiple times, the final result can become absurd. For instance, you could round $$$145$$$ up to $$$200$$$, because $$$145$$$ can be rounded to $$$150$$$, which can then be rounded to $$$200$$$; when someone says $$$2000$$$, it could actually have been $$$2001$$$, $$$1999$$$, $$$1888$$$, or even $$$11451$$$ before rounding.
Given a number $$$x$$$, calculate the uncertainty of $$$x$$$ within the range $$$[0,z]$$$, which is the count of numbers within the range $$$[0,z]$$$ that can be $$$x$$$ after aggressive rounding. Here, aggressive rounding is defined as performing the following rounding operation arbitrarily (possibly zero) times:
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^5$$$) — the number of test cases. The description of the test cases follows.
The input contains two integers in a line: $$$x$$$ and $$$z$$$ ($$$0 \le x,z \le 10^{18}$$$). Refer to above for their meanings.
Each line contains a single number, representing the uncertainty of $$$x$$$ in the range $$$[0,z]$$$.
50 214748364610 100671232353 1232363123001006660996 3122507962333010100019990010301090 44519984489341188
2147483647 55 0 1919810 114514
In the second test case, $$$10i + j$$$ ($$$i=0,1,\cdots,9$$$, $$$j=5,6,7,8,9$$$) and $$$10,11,12,13,14$$$ can be aggressively rounded to $$$10$$$. Thus, the answer is $$$55$$$.
The rose can be viewed as a tree with $$$n$$$ nodes. To make the rose thornless, Claudette Morel can add several edges to the graph, as long as the addition does not create multiple edges or self-loops. However, she cannot add new nodes to the graph.
A simple graph is thornless if and only if each edge appears in exactly one simple cycle. A simple cycle is defined as a cycle that does not contain any repeated nodes (except for the starting and ending node being the same). The following illustrations explain what is a thornless graph and what is not.
Now, Claudette Morel has taken out her roses, and you are tasked with analyzing whether they can be transformed into a thornless graph.
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1\le T\le 10^5$$$) — the number of test cases. The description of the test cases follows.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of nodes in the tree.
Each of the following $$$n-1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$), indicating that $$$(u_i,v_i)$$$ is an edge on the tree.
It is guaranteed that the sum of $$$n$$$ among $$$T$$$ test cases does not exceed $$$3\cdot 10^5$$$.
For each test case, if the tree cannot be transformed into a thornless graph, output $$$-1$$$.
Otherwise, on the first line, output $$$k$$$ ($$$0 \le k \le n$$$) — the number of edges you added.
In the following $$$k$$$ lines, each line should contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$) — the edges you added. Note that after adding edges, multiple edges and self-loops are not allowed. If there are multiple solutions, print any.
341 22 32 471 21 31 44 54 64 761 22 32 41 55 6
-1 3 1 5 2 3 6 7 2 6 2 4 3
The renowned farmer Chen Loong discovered that a rational planting density could raise production.
Now, the farm can be viewed as a three-dimensional coordinate system, and a plant can be seen as a point in it. There are $$$n$$$ different plants $$$A_i=(x_i,y_i,z_i)$$$. For each plant $$$A_i$$$, its density is defined as follows.
Since Chen Loong's plants love involution, he decides to remove some plants with less density. Please answer the minimum number of plants that need to be removed such that each of the remaining plants has a density greater than or equal to $$$k$$$. Note that after removing a point, the density of other plants may change. In particular, removing all plants is always considered valid.
You need to solve for $$$k=0,1,\ldots,n-1$$$ respectively.
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1\le T\le 2 \times 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line contains an integer $$$n$$$ ($$$1 \le n\le 10^5$$$) — the number of plants.
In the next $$$n$$$ lines, the $$$i$$$-th line contains three integers $$$x_i$$$, $$$y_i$$$, and $$$z_i$$$ ($$$1 \le x_i,y_i,z_i \le 10^5$$$) — the coordinates of each plant.
It is guaranteed that the coordinates of the $$$n$$$ plants are distinct.
It is guaranteed that the sum of $$$n$$$ among $$$T$$$ test cases does not exceed $$$2\times 10^5$$$.
For each test case, output $$$n$$$ integers in a line, representing the answers for $$$k=0,1,\ldots,n-1$$$.
251 1 11 1 21 1 32 3 52 2 431 1 12 2 23 3 3
0 0 2 5 5 0 3 3
People use abbreviations to express succinctly. This can lead to trouble when two phrases share the same abbreviation. For example, searching the term "CCPC" online, you will find not only the desired "China Collegiate Programming Contest", but also "China Car Performance Challenge", "Competition and Consumer Protection Commission", etc.
However, nobody will drive a car while writing code. You decide to resolve the problem by assigning a distinct initialism-like abbreviation to every phrase you often use. There are $$$n$$$ phrases, each consisting of some words in lowercase and uppercase English letters. To create an abbreviation for a phrase, a non-empty prefix of each word in the phrase is chosen and then concatenated in order. For example, "ChCoPrCo" and "CCPContest" are valid abbreviations for "China Collegiate Programming Contest", but "CCCP" and "CCPiC" are not. Each phrase is abbreviated independently from the other phrases: the same word can be abbreviated differently in different phrases.
Construct an abbreviation scheme so that the total length of all abbreviations is minimized, while ensuring $$$n$$$ abbreviations are distinct.
The first line of input contains an integer $$$n~(1 \leq n \leq 128)$$$, representing the number of phrases.
The next $$$n$$$ lines each contain a non-empty phrase consisting of no more than $$$128$$$ non-empty words separated by single spaces. Each word consists of no more than $$$128$$$ lowercase and uppercase English letters only. It is guaranteed that no two phrases are identical.
If there is no possible solution, print "no solution" in a single line.
Otherwise, print $$$n$$$ lines where the $$$i$$$-th line contains the abbreviation of the $$$i$$$-th phrase in the solution, in the order given by input. If there are multiple solutions, print any.
5automated teller machineactive teller machineactive trouble makeralways telling misinformationAmerican Teller Machinery
atm atma actm atem ATM
5Forest Conservation Committee ForumFuming Corruption Collusion FederationFulsome Cash Concealment FoundationFunky Crony Capitalism FacilitatorFunny Cocky Cocky Funny
FCCF FCoCF FuCCF FCCFa FCCFu
3A AAAA AA A A
no solution
There is a useful feature on Mikufans that allows users to leave a message during the video playback, which is called danmaku. Sometimes, there are so many danmaku messages at the same time that Kaguya cannot take them all in.
Source: https://bilibili.com/video/BV1xx411c79H For simplicity, we only focus on the top danmaku messages: top danmaku messages are displayed at the top of the video screen, and each message occupies exactly one line. There is no limit to the number of danmaku messages at the same time (although Kaguya's screen will only display the first $$$10^9$$$ lines, the remaining messages will still be correctly maintained in the overflow area of the screen).
During the video playback, there may be three types of events:
Kaguya has many videos to watch every day, and she is too busy to re-watch the video from the beginning, so she asks you for help. Please help her find the senders of the danmaku messages.
The first line of input contains one integer $$$n$$$ ($$$1 \le n \le 5 \times 10^5$$$), representing the number of events.
Each of the following $$$n$$$ lines contains one event in order. Each event is described in one of the following formats:
For each query of type 3, output the answer in a single line.
71 21 43 32 13 21 43 7
2 0 3
53 63 81 21 53 2
0 0 1
The game is played on an $$$n\times m$$$ table. A cell has its color, which is one of red, blue, or white. Initially, cell $$$(a,b)$$$ is red, cell $$$(c,d)$$$ is blue (These two cells do not coincide), and others are white. We call $$$(a,b)$$$ and $$$(c,d)$$$ special cells and others nonspecial. During the game, the player can perform a certain operation, which consists of three steps:
In other words, in one operation, the player can color a nonspecial cell with the same color as its non-white neighboring cell. Note that a cell may be colored more than once, and the latest color will cover the earlier one.
The player can perform the operation any number of times and then stop the game. After that, the final configuration of the map table is printed.
Unfortunately, Generalissimo is full of cheats, and cheaters can color in any position at any time. In order to advocate Justice, you decide to write a judge program to determine whether the given configuration is possible to be a legal configuration in a normal game, or there must be a cheater.
The input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1\le T\le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$ and $$$2 \le n\cdot m$$$) — the number of rows and columns.
The second line contains four integers $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$ ($$$1 \le a,c \le n$$$ and $$$1 \le b,d \le m$$$).
Each of the next $$$n$$$ lines contains $$$m$$$ characters. Each character is 'R', 'B', or '.', representing a red cell, a blue cell, and a white cell, respectively.
It is guaranteed that cell $$$(a,b)$$$ and $$$(c,d)$$$ do not coincide, and that the character on the $$$a$$$-th row $$$b$$$-th column and $$$c$$$-th row $$$d$$$-th column is 'R' and 'B', respectively.
It is guaranteed that the sum of $$$n \cdot m$$$ among $$$T$$$ test cases does not exceed $$$250\,000$$$.
For each test case, print "YES" (without quotes) if it is a legal configuration and "NO" (without quotes) otherwise.
You can print letters in any case (upper or lower).
43 31 1 1 2RBBRRRBBR6 61 1 6 6RRRRRRBBBBBRBRRRBRBRBBBRBRRRRRBBBBBB5 53 3 4 4BBR.BBBR.BRRR.B...BBBBBB.1 51 1 1 3RBBBR
YES YES NO NO
The following graph shows the first test case and how the player can reach the configuration without cheating. Each crown marks a special cell.