Walk Alone is playing a game recently. In this game, there are $$$n$$$ monsters numbered from $$$1$$$ to $$$n$$$, the $$$i$$$-th of which has an attack ability of $$$a_i$$$. Walk Alone is required to kill all of them in order.
To kill a monster, he needs to battle with it. He can battle with the $$$(i+1)$$$-th monster if and only if all monsters from $$$1$$$ to $$$i$$$ are killed.
Initially, Walk Alone's attack ability $$$m$$$ equals to $$$0$$$. After a battle with the $$$i$$$-th monster, three situations may happen:
When he loses a battle, he will keep trying until he wins.
Now Walk Alone wants to know the expected number of battles he needs to go through in total.
It can be shown that the answer can always be expressed as an irreducible fraction $$$x/y$$$, where $$$x$$$ and $$$y$$$ are integers and $$$y \not\equiv 0 \pmod{998\,244\,353}$$$. Output such an integer $$$a$$$ that $$$0 \leq a \lt 998\,244\,353$$$ and $$$a\cdot y \equiv x \pmod{998\,244\,353}$$$.
The first line contains an integer $$$n\ (1 \leq n \leq 10^3)$$$, the number of monsters.
The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i\ (0 \leq a_i \leq 10^3)$$$ and $$$x_i\ (1 \leq x_i \leq 100 )$$$, and $$$p_{i} = 0.01\,x_i$$$.
Output a single number, the expected number of battles modulo $$$998\,244\,353$$$.
3 1 100 0 50 1 100
499122181
5 2 50 6 30 1 20 5 50 4 40
332748140
In the first example, the result of each battle is as below:
The expected number of battles is $$$4.5$$$, which is congruent to $$$499\,122\,181$$$ modulo $$$998\,244\,353$$$.
Given three integers $$$n,k$$$ and $$$m$$$. Let $$$S=\{i\mid 1\le i\le nm+k,i\in \mathbb Z\}$$$. For all integers $$$r$$$ where $$$0\le r \lt m$$$, you need to output the number of sets $$$T$$$ such that
The only line of the input contains three integers $$$n\ (0\le n\le 10^{13})$$$, $$$k\ (0\le k \lt \min(m,500),nm+k \gt 0)$$$ and $$$m\ (1\le m\le 10^5)$$$ as described above.
Output $$$m$$$ integers in a line, the $$$i$$$-th of which indicates the number of subsets modulo $$$998\,244\,353$$$ when $$$r=i-1$$$.
1 1 2
4 4
1919 8 10
577613260 577613260 822345879 577613260 822345879 577613260 577613260 822345879 577613260 822345879
Walk Alone has two circles. The two circles are externally tangent, and are of radius $$$a$$$ and $$$b$$$ respectively. He keeps the first circle of radius $$$a$$$ stationary, and rotates the second one around the first one, keeping the point of contact without slipping. He wants to know how many times will the second circle revolve after rolling it exactly one trip back to its starting point.
The input consists of multiple test cases.
The first line contains an integer $$$T\ (1 \leq T\leq 10^5)$$$, the number of test cases.
For each test case, the first and the only line contains two integers $$$a$$$ and $$$b\ (1 \leq a, b \leq 10^{18})$$$, denoting the radius of two circles.
For each test case output the answer in a line. The answer should be expressed as a minimal fraction $$$p/q$$$ where $$$\gcd(p,q)=1$$$.
22 14 6
3/1 5/3
Walk Alone has a special random number generator, the pseudocode of which is as follows:
uintk rand(uintk x, int A[]) {
for (int i = 0; i < A.size(); ++i) {
if (A[i] >= 0) x ^= x << A[i];
else x ^= x >> -A[i];
}
return x;
}
Here 'uintk' denotes the type of unsigned integers with $$$k$$$ binary bits ('bitset<k>' in C++).
Given an array $$$A$$$ and an integer $$$k$$$, Walk Alone wants to know the number of integer $$$x\ (0\le x \lt 2^k)$$$ such that $$$\text{rand}(x,A)=x$$$.
The first line contains two integers $$$n\ (0\le n\le 10^3)$$$ and $$$k\ (1\le k\le 10^3)$$$, the size of array $$$A$$$ and the length of type 'uintk' respectively.
The second line contains $$$n$$$ integers, the $$$i$$$-th of which is $$$A_i\ (|A_i| \lt k)$$$.
Print the number of $$$x$$$ modulo $$$998\ 244\ 353$$$.
3 5 2 3 -4
2
0 3
8
Walk Alone has $$$n$$$ piles of stones, and there are $$$a_i$$$ stones in the $$$i$$$-th pile.
He can do an operation to these stones for $$$n-1$$$ times. In each operation, he can select two piles of stones of size $$$x$$$ and $$$y$$$, and merge them (the two piles will become a larger pile of size $$$x+y$$$), and he will get $$$x\cdot y$$$ score after that.
Walk Alone wants to know the maximal total score he can get. Can you help him?
The first line contains an integer $$$n\ (1\le n\le 10^5)$$$, the number of piles of stones.
The second line contains $$$n$$$ integers. The $$$i$$$-th integer $$$a_i\ (1\le a_i\le 10^4)$$$ indicates the number of stones in the $$$i$$$-th pile.
Output an integer representing the maximal score Walk Alone can get.
3 1 2 3
11
6 1 1 4 5 1 4
98
Walk Alone loves strings, and he insists that a contest without a string problem is not a good contest, so here is the string problem.
You are given two strings $$$s$$$ and $$$t$$$. You need to select the longest continuous substring $$$s'$$$ from $$$s$$$, such that it is possible to reverse at most one prefix of $$$t$$$, and after that there exists a prefix of $$$t$$$ (not necessarily the same with the previous one) that equals to $$$s'$$$.
The first line contains two integers $$$n\ (1\le n\le 2\cdot 10^5)$$$ and $$$m\ (1\le m\le 2\cdot 10^5)$$$, indicating the length of $$$s$$$ and $$$t$$$.
The second line and the third line are two strings consisting of only lowercase characters, representing string $$$s$$$ and $$$t$$$, respectively.
Output the length of the longest substring of $$$s$$$ in a line.
8 7 cacbabca abcabcc
6
5 5 abcde fdcba
4
In the first example, you can reverse the prefix of length $$$4$$$ of $$$t$$$. After that $$$t$$$ becomes 'acbabcc', whose prefix of length $$$6$$$ coincides with $$$s_{1:7}$$$, i.e., 'acbabc'.
Walk Alone is afraid of math, especially memorizing formulas. In Walk Alone's math textbook, there are $$$n$$$ formulas connected with $$$n-1$$$ edges, which form a tree rooted at the first formula. To handle the $$$i$$$-th formula, he must remember all formulas in its subtree, including the formula itself, and memorizing the $$$i$$$-th formula consumes $$$h_i$$$ energy.
One day after math class, Walk Alone is assigned with $$$m$$$ math problems as his homework, and he should complete them in order. To complete the $$$i$$$-th problem, he needs to handle the $$$x_i$$$-th formula. However, when he is solving the $$$i$$$-th problem, he can only remember all formulas used in the recent $$$k_i$$$ problems. Formally speaking, he remembers formula $$$u$$$ if and only if there exists a positive integer $$$p$$$ such that $$$i-k_i\le p \lt i$$$ and $$$u$$$ is in the subtree of $$$x_p$$$. For all formulas in the subtree of $$$x_i$$$ that he does not remember, he will consume energy to memorize them.
Walk Alone wants to know the amount of energy he should consume to finish each problem.
The first line contains two integers $$$n\ (1\le n\le 10^6)$$$ and $$$m\ (1\le m\le 2\cdot 10^5)$$$, indicating the number of formulas and problems, respectively.
The second line contains $$$n$$$ integers, the $$$i$$$-th of which, $$$h_i\ (1\le h_i\le 10^9)$$$, indicates the energy needed to memorize the $$$i$$$-th formula.
Each of the following $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v\ (1\le u,v\le n)$$$, indicating an edge between $$$u$$$ and $$$v$$$.
The $$$i$$$-th of the following $$$m$$$ lines contains two integers $$$x_i\ (1\le x_i\le n)$$$ and $$$k_i\ (0\le k_i\le m)$$$ as described above.
Output the amount of energy Walk Alone needs to consume to finish each problem.
5 5 1 2 4 8 16 1 2 1 3 2 4 2 5 1 1 2 1 4 1 5 1 1 2
31 0 0 16 7
Walk Alone has a string, and he wants you to count the number of consecutive 'fyt' in the string.
For example, the answer to 'ffyt' is $$$1$$$ since the second to the fourth character forms a consecutive 'fyt', while 'ffyytt' has no 'fyt' as its substring.
The first line contains an integer $$$n\ (1 \leq n \leq 10^6)$$$, indicating the length of the string.
The second line contains a single string consisting of three characters 'f', 'y', and 't', representing the string.
Output a single integer indicating the number of consecutive 'fyt' in the input string.
6 fytfyt
2
9 fytffyytt
1
ZCY and YYH are good friends. One day, ZCY took a photo of YYH eating a hamburger, and she wants to stick it on every building in the school.
The school contains $$$n$$$ buildings connected with $$$n-1$$$ roads, and there is exactly one path between any two buildings. Initially, ZCY is at building $$$a$$$, and YYH is at building $$$b$$$. In every minute, both of them can walk along a road to the building on the other side. ZCY wants to visit as many buildings as she can, so that she can stick YYH's photos on them. Of course YYH does not want her photo to be found on too many building, so she will try to catch ZCY and stop her as soon as possible. At any moment when YYH and ZCY are at the same building or on the same road, ZCY will be caught by YYH.
Now ZCY wants you to tell her the maximum number of photos that she can stick on the buildings.
The first line contains three integers $$$n\ (1\le n\le 10^6)$$$, $$$a$$$ and $$$b\ (1\le a,b\le n)$$$ as described above.
Each of the following $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v\ (1\le u,v\le n)$$$, indicating a road between $$$u$$$ and $$$v$$$.
Output an integer indicating the maximum number of buildings ZCY can visit.
5 4 3 1 2 1 3 2 4 2 5
3
3 2 2 1 2 2 3
0
In the first example, the buildings that ZCY visit are $$$4\rightarrow 2\rightarrow 5$$$ and YYH are $$$3\rightarrow 1\rightarrow 2$$$. ZCY will be caught by YYH at building $$$5$$$ eventually.
Walk Alone and Salix Leaf are playing a special chess game on an infinite chess board, the center of which locates at $$$(0,0)$$$. There are two Kings on the chess board, the white one belongs to Walk Alone and the black one belongs to Salix Leaf. Walk Alone moves first, after which they take turns moving their Kings.
In one move, a King moves one square in any direction. Formally speaking, if the king locates at $$$(x,y)$$$ at the beginning of one's turn, then it must move to one of $$$(x+\Delta x,y+\Delta y)$$$ where $$$\max(|\Delta x|,|\Delta y|)=1$$$. A King must move if it is able to move. Additionally, a King is forbidden to move into the nearest $$$8$$$ blocks of the other King, or the other King may capture it during the next move.
Walk Alone wants to keep moving right, which means if Walk Alone moves to $$$(10^{100}, y)$$$ for some integer $$$y$$$, he wins. Conversely, Salix Leaf wants to stop him, which means if it is impossible for Walk Alone to move to the place he wants, Salix Leaf wins.
Now the initial coordinates of the two Kings are given, and you should decide who will win if both of them play optimally. If Walk Alone will win, print 'Walk Alone'; otherwise, print 'Salix Leaf' (without quotes).
The input contains multiple test cases.
The first line of the input contains an integer $$$T\ (1\le T\le 10^5)$$$, the number of test cases.
Each test case contains only one line with four integers $$$x_1,y_1,x_2,y_2$$$. The coordinates of Walk Alone's and Salix Leaf's Kings are $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$, respectively. It is guaranteed that $$$\max(|x_1-x_2|,|y_1-y_2|) \gt 1$$$.
The absolute value of all coordinates are less or equal to $$$10^9$$$.
For each test case, output the winner in one line.
30 -1 2 1-2 3 2 32 0 -1 0
Walk Alone Salix Leaf Walk Alone
On the 70th anniversary of HUST (Hualishu University of Science and Technology), the grandstand in the playground near QinYuan is renewed!
Walk Alone loves the new grandstand. He finds that the new grandstand is a matrix of $$$n\times m$$$ seats with $$$n$$$ rows and $$$m$$$ columns, and each seat is colored either blue, red or white. The red seats in the grandstand form the shape of 'HUST' together.
What is more, Walk Alone finds that the shape of the four letters should satisfy the following rules:
For better understanding, it is recommended to see the illustration below ($$$x,y,z$$$ and $$$d$$$ are arbitrary positive integers):
![]() | ![]() |
Now Walk Alone gives you a part of the grandstand, in which some seats are colored red. You need recognize whether it belongs to one of 'H', 'U', 'S', 'T', or Walk Alone is cheating (it does not belong to any of the four letters).
The input contains multiple test cases.
The first line of the input contains an integer $$$T\ (1\le T\le 10)$$$, the number of test cases.
For each test case, the first line contains two integers $$$n$$$ and $$$m\ (1\le n,m\le 3000)$$$, indicating the size of grandstand.
Each of the next $$$n$$$ lines is a string of length $$$m$$$ consisting only of '.' and 'x'. The $$$j$$$-th character in the $$$i$$$-th line is 'x' if and only if the seat located at the $$$j$$$-th column and the $$$i$$$-th row is red.
For each test case, output one of 'H', 'U', 'S' or 'T' as the answer, or 'OOPS!' (without quotes) if none of them are correct.
46 5.xxx..x....xxx....x....x..xxx.5 5xx.xxxx.xxxxxxxxxxxxxx.xx5 5xx..xxx..xxxxxxxxxxxxx..x2 3xxx..x
S H OOPS! OOPS!
Phigros is a music game in which players are required to touch the screen following the rhythm of songs and try to get the highest scores.
The total score of a song is the sum of the following two parts rounded to the nearest integer (assume that the song has $$$n$$$ notes in total):
Recall that $$$$$$ \text{round}(x)=\begin{cases} \lfloor x\rfloor, & x \lt \lfloor x\rfloor+0.5 \\ \lfloor x\rfloor + 1, & x\ge\lfloor x\rfloor+0.5 \end{cases} $$$$$$
Now Walk Alone is playing a song with $$$n$$$ notes. He has already got the judgement of the first $$$k$$$ notes, and he wants to know the maximum score he could get if he played the rest of the song perfectly.
The first line contains two integers $$$n$$$ and $$$k\ (1\le k\le n\le 4000)$$$, the note count of the song and the number of notes Walk Alone has played.
The $$$i$$$-th of the following $$$k$$$ lines contains one of 'perfect', 'good', 'bad' and 'miss' (without quotes), indicating the judgement of the $$$i$$$-th note.
An integer indicating the maximum score Walk Alone could get.
6 5 perfect good perfect bad good
695000
1000 2 miss good
998685
A song has at most $$$4000$$$ notes in Phigros.
Walk Alone has a conjecture which says
He fails to prove it, so he wants you to prove it in a small range. Your work is to construct two integers $$$x$$$ and $$$y$$$ such that
The first line contains one integer $$$T\ (1 \leq T \leq 10^5)$$$, the number of test cases.
Each test case consists of only one line with an integer $$$n\ (1 \leq n \leq 10^8)$$$, denoting the number Walk Alone wants you to prove.
For each test case, print two integers $$$x$$$ and $$$y\ (1 \leq x \lt y \leq 10^{10})$$$ in one line satisfying the constraints above.
3123
2 3 2 4 12 15
Walk Alone is poor at graph theory. In today's graph theory class, Walk Alone is given a graph with $$$n$$$ vertices and $$$m$$$ edges, and he is required to color all vertices red or blue so that each edge has endpoints of differing colors. It is guaranteed that such coloring strategy always exists, i.e., the graph is bipartite. It is a simple task indeed, but Walk Alone colored some vertices incorrectly, so he is asking you for help.
In his bipartite graph, some vertices are colored red, some are colored blue, and the others are not colored yet. Since a colored vertex cannot change its color, your task is to remove as few vertices as possible (as well as the edges connecting with them), so that it is possible to color all uncolored vertices, and each edge should have endpoints of differing colors after that.
The first line contains two integers $$$n\ (1\le n\le 10^4)$$$ and $$$m\ (1\le m\le 10^4)$$$, the number of vertices and edges in the original graph.
The second line contains $$$n$$$ integers. The $$$i$$$-th integer $$$c_i$$$ indecates the color of the $$$i$$$-th vertex: $$$1$$$ for red, $$$2$$$ for blue, and $$$0$$$ if the vertex is not colored.
Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$v\ (1\le u,v\le n)$$$, indicating an edge between vertex $$$u$$$ and $$$v$$$. It is guaranteed that the given graph is bipartite.
Print the minimum number of vertices you need to remove in the first line, and the label of removed vertices separated by spaces in the second line. If there exists multiple solutions, output any of them.
7 7 1 2 1 0 2 1 0 1 5 2 5 3 5 3 6 4 6 2 7 3 7
2 3 5
5 4 1 1 2 2 0 5 1 5 2 5 3 5 4
1 5
3 2 0 0 1 1 2 2 3
0
Here is an illustration for the first example: