You are given an array $$$a$$$ of length $$$n$$$. For each $$$k=1,2,\ldots,n$$$, consider the following process independently.
Initially, the array is $$$a$$$. You must perform exactly $$$k$$$ operations. In each operation, you may choose one of the following two actions:
Your score is defined as the value of the element removed in the $$$k$$$-th operation.
For each $$$k=1,2,\ldots,n$$$, find the maximum score you can obtain.
The first line contains an integer $$$n$$$, the length of the array ($$$1\le n\le10^5$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$, representing the array $$$a$$$ ($$$1\le a_i\le10^9$$$).
Output $$$n$$$ integers. The $$$k$$$-th integer should be the maximum score you can obtain after performing exactly $$$k$$$ operations.
52 7 8 1 4
4 7 8 8 8
For $$$k=1$$$, we can only delete either the leftmost element $$$2$$$ or the rightmost element $$$4$$$, so the maximum score is $$$4$$$.
For $$$k=2$$$, we can first delete the leftmost element $$$2$$$, and then delete the new leftmost element $$$7$$$. Thus, the element deleted in the second operation is $$$7$$$, so the maximum score is $$$7$$$.
For $$$k=3$$$, we can delete the leftmost elements $$$2,7,8$$$ in order, making the element deleted in the third operation equal to $$$8$$$. Therefore, the maximum score is $$$8$$$.
For $$$k=4$$$ and $$$k=5$$$, we can similarly arrange the previous operations so that the element deleted in the last operation is $$$8$$$.
Alice and Bob are playing a game on a permutation, with Alice moving first.
A sequence of length $$$n$$$ is called a permutation if and only if each integer from $$$1,2,\dots,n$$$ appears exactly once in the sequence.
Initially, a permutation $$$a_1,a_2,\ldots,a_n$$$ of length $$$n$$$ is given. At any moment during the game, the current sequence is always a permutation of some length $$$m$$$. Alice and Bob take turns performing exactly one of the following two operations:
- Choose an index $$$i$$$ $$$(1\le i \lt m)$$$ such that $$$a_i \gt a_{i+1}$$$, and swap $$$a_i$$$ and $$$a_{i+1}$$$.
- Choose an index $$$i$$$ $$$(1\le i \lt m)$$$ such that $$$a_{i+1}=a_i+1$$$, and delete $$$a_i$$$ and $$$a_{i+1}$$$. Then renumber the remaining elements according to their relative order: the $$$k$$$-th smallest remaining element is renumbered as $$$k$$$, so that the remaining sequence becomes a permutation again.
For example, suppose the current permutation is $$$[2,3,4,1]$$$. The adjacent elements $$$2$$$ and $$$3$$$ can be deleted, leaving $$$[4,1]$$$; after renumbering, the permutation becomes $$$[2,1]$$$.
A player who cannot perform any operation loses the game. Assuming that both Alice and Bob play optimally, determine the winner.
Each test contains multiple test cases.
The first line contains an integer $$$T$$$ $$$(1\le T\le 5000)$$$, the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, output Alice if Alice wins; otherwise, output Bob.
51121 222 142 4 1 355 1 4 2 3
BobAliceBobAliceBob
You are given an integer array $$$a$$$ of length $$$n$$$.
In one operation, you may choose two distinct indices $$$i,j$$$ satisfying
$$$$$$ 1\le i,j\le n,\qquad i\ne j, $$$$$$
and perform the following changes simultaneously:
$$$$$$ a_i\gets a_i+3,\qquad a_j\gets a_j-1. $$$$$$
You may perform any finite number of operations, including zero operations. The elements of the array are allowed to become negative during the process.
The range of an array is defined as
$$$$$$ \max_i a_i-\min_i a_i. $$$$$$
Find the minimum possible range of the array after performing any number of operations.
The first line contains a single integer $$$T$$$ — the number of test cases.
Each test case consists of two lines:
The first line contains a single integer $$$n$$$ — the length of the array. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the initial array.
The following constraints hold:
$$$$$$ 1\le T\le 10^4, $$$$$$
$$$$$$ 1\le n\le 2\times 10^5, $$$$$$
$$$$$$ -10^9\le a_i\le 10^9. $$$$$$
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed
$$$$$$ 2\times 10^5. $$$$$$
For each test case, output a single integer — the minimum possible range of the array after performing any finite number of operations.
31520 24-1 9 5 8
021
There are $$$n$$$ resonators placed in order along a corridor. The current frequency offset of the $$$i$$$-th resonator is $$$a_i$$$, and its target offset is $$$b_i$$$.
The tuning device can only be activated from one end of the corridor. In one operation, you may choose any nonzero integer $$$x$$$ and perform one of the following operations:
$$$x$$$ may be positive or negative. Regardless of the magnitude of $$$|x|$$$, the modification counts as exactly one operation.
Find the minimum number of operations required to transform sequence $$$a$$$ into sequence $$$b$$$.
The first line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\times10^5$$$, and the sums of $$$\sum|a_i-a_{i-1}|(i \ge 2)$$$ and $$$\sum|b_i-b_{i-1}|(i \ge 2)$$$, taken over all test cases, do not exceed $$$10^4$$$ respectively.
For each test case, output one integer on a separate line, the minimum number of operations.
430 0 0-1 2 030 0 03 1 441 4 2 86 9 7 132-7 10-7 10
2310
For the first test case, one possible sequence of operations is:
For the third test case, adding $$$5$$$ to the entire sequence is sufficient.
This is an interactive problem.
There is an unknown sequence $$$B$$$ consisting of $$$0$$$s and $$$1$$$s, with 1-based indexing. You can make multiple queries. In each query, you specify a center $$$m$$$ and a radius $$$r$$$, and the interactor will return the number of $$$1$$$s in the punctured neighborhood of indices $$$[m-r,m+r]\setminus\{m\}$$$ of $$$B$$$. Try to determine the total number of $$$1$$$s in $$$B$$$.
Note that the interval you query must not exceed the boundaries of the sequence itself.
There are multiple test cases in this problem.
First, read a line containing a single positive integer $$$T$$$ $$$(1\le T\le1000)$$$, denoting the number of test cases.
For each test case:
The number of queries for each test case must not exceed $$$35$$$.
Violations such as an incorrect interaction format or exceeding the query limit will result in an undefined verdict.
2 4 1 1 5 4 2
? 2 1 ? 3 1 ! 2 ? 3 2 ? 2 1 ! 5
The example demonstrates a possible interaction process. The unknown sequences in the two test cases are 1100 and 11111, respectively.
How to flush the output buffer:
Given an integer $$$n$$$, construct a permutation $$$p_1,p_2,\ldots,p_n$$$ of $$$1,2,\ldots,n$$$ such that the sum of every pair of adjacent elements is not a perfect square. In other words, for every $$$1\le i \lt n$$$, there does not exist an integer $$$x$$$ such that
$$$p_i+p_{i+1}=x^2$$$.
It can be proven that an answer exists for every valid $$$n$$$.
The first line contains an integer $$$T$$$, the number of test cases.
Each of the next $$$T$$$ ($$$1\le T \le10^4$$$) lines contains one integer $$$n$$$ ($$$1\le n \le 4 \cdot 10^6$$$)
and the sum of $$$n$$$ over all test cases does not exceed $$$4\cdot 10^6$$$.
For each test case, output one line containing a permutation satisfying the condition.
If there are multiple valid answers, output any of them.
5 1 2 3 4 5
1 1 2 1 2 3 1 2 3 4 1 4 2 3 5
This is a communication problem.
In this problem, your program will be run twice. Between the two runs, all variables stored in memory will be lost, but the information obtained during the first run may be crucial for solving the problem during the second run.
There are two characters in this problem: "Nailoong" and "Bombloong".
Nailoong has complete structural information about a tree with $$$n$$$ vertices, while Bombloong only knows the number of vertices $$$n$$$. Since Bombloong has been imprisoned by the evil little leopard, Nailoong can only help Bombloong reconstruct a tree that is isomorphic to the original tree through a special one-way communication method.
Two trees $$$T_1(V_1,E_1)$$$ and $$$T_2(V_2,E_2)$$$ are called isomorphic if and only if there exists a bijection $$$f:V_1\to V_2$$$ such that for every $$$\{u,v\}\in E_1$$$, $$$\{f(u),f(v)\}\in E_2$$$.
The rules of communication are as follows:
function DFS(u, parent)
append u to tour
for v in vertices adjacent to u
if v is not parent, then
DFS(v, u)
append u to tour
Endif
Endfor
Endfunction
function GenerateSequence(T, color)
tour <- empty sequence
root <- the starting vertex chosen by the leopard
DFS(root, NIL)
c <- empty sequence
for v in tour
append color[v] to c
Endfor
Return c
Endfunction
Nailoong cannot directly send the vertex indices to Bombloong; she can only send the sequence $$$c$$$. After receiving $$$n$$$ and the sequence $$$c$$$, Bombloong must construct and output a tree isomorphic to Nailoong's tree.
Communication Protocol
In each test, the contestant's program will be run twice. A testing tool is provided in the handout files for local debugging.
First Run
In the first run, you play the role of "Nailoong".
Input
The first line contains a string first, which allows your program to identify that this is the first run.
The second line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2\le n\le2\times10^5)$$$, the number of vertices in the tree.
The next $$$n-1$$$ lines each contain two integers $$$u,v$$$ $$$(1\le u,v\le n)$$$, denoting an edge of the tree.
It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \times 10^5$$$.
Output
Your output should contain $$$T$$$ lines. The $$$i$$$-th line contains a sequence $$$col_1,col_2,\dots,col_n$$$ of length $$$n$$$, where each $$$col_i\in\{\mathbf{0,1,2}\}$$$ $$$(i=1,2,\dots,n)$$$, denoting the color assigned by Nailoong to the $$$i$$$-th vertex. $$$col_i=0$$$ denotes white, $$$col_i=1$$$ denotes black, and $$$col_i=2$$$ denotes grey.
Second Run
In the second run, you play the role of "Bombloong".
Input
The first line contains a string second, which allows your program to identify that this is the second run.
The second line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2\le n\le2\times10^5)$$$, the number of vertices in the tree.
The next line contains $$$2n-1$$$ integers $$$c_1,c_2,\dots,c_{2n-1}$$$, denoting the sequence generated by the judge according to Nailoong's coloring.
It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \times 10^5$$$.
Output
For the $$$i$$$-th test case, let the input number of vertices be $$$n$$$.
Output $$$n-1$$$ lines, each containing two integers $$$u,v$$$ $$$(1\le u,v\le n)$$$, denoting an edge of the reconstructed tree.
You must ensure that the output tree is isomorphic to the tree given in the first run.
The two samples in the PDF statement included in the contest materials correspond to the two runs of the same test case.
Suppose the trees in the first input are $$$t_1,t_2,\dots,t_T$$$ in order, and Nailoong outputs the corresponding colorings $$$col_1,col_2,\dots,col_T$$$, where every vertex is assigned one of the three colors $$$0,1,2$$$.
For each $$$1\le i\le T$$$, let $$$a_i$$$ be the sequence generated by the little leopard from the tree $$$t_i$$$ and the coloring $$$col_i$$$.
The evaluator then randomly generates a permutation $$$p_1,p_2,\dots,p_T$$$ of $$$1,2,\dots,T$$$ and gives the sequences
$$$$$$ a_{p_1},a_{p_2},\dots,a_{p_T} $$$$$$
to Bombloong in this order during the second run.
Suppose the trees output by Bombloong are $$$t'_1,t'_2,\dots,t'_T$$$. For every $$$1\le i\le T$$$, the evaluator checks whether $$$t'_i$$$ is isomorphic to $$$t_{p_i}$$$.
How to Use the Handout Files
python3 tree_communication_testing_tool1.py data.in ./solution
python3 tree_communication_testing_tool1.py --trials 10 data.in ./solution
python3 tree_communication_testing_tool1.py data.in python3 solution.py
Here, solution is a compiled C/C++ executable, and solution.py is a Python source file.
The file data.in contains the input for the first run.
The optional parameter --trials specifies the number of independent simulations. In different simulations, the little leopard may choose different DFS starting vertices and different orders in which adjacent vertices are visited.
This is a communication problem.
In this problem, your program will be run twice. Between the two runs, all variables stored in memory will be lost, but the information obtained during the first run may be crucial for solving the problem during the second run.
There are two characters in this problem: "Nailoong" and "Bombloong".
Nailoong has complete structural information about a tree with $$$n$$$ vertices, while Bombloong only knows the number of vertices $$$n$$$. Since Bombloong has been imprisoned by the evil little leopard, Nailoong can only help Bombloong reconstruct a tree that is isomorphic to the original tree through a special one-way communication method.
Two trees $$$T_1(V_1,E_1)$$$ and $$$T_2(V_2,E_2)$$$ are called isomorphic if and only if there exists a bijection $$$f:V_1\to V_2$$$ such that for every $$$\{u,v\}\in E_1$$$, $$$\{f(u),f(v)\}\in E_2$$$.
The rules of communication are as follows:
function DFS(u, parent)
append u to tour
for v in vertices adjacent to u
if v is not parent, then
DFS(v, u)
append u to tour
Endif
Endfor
Endfunction
function GenerateSequence(T, color)
tour <- empty sequence
root <- the starting vertex chosen by the leopard
DFS(root, NIL)
c <- empty sequence
for v in tour
append color[v] to c
Endfor
Return c
Endfunction
Nailoong cannot directly send the vertex indices to Bombloong; she can only send the sequence $$$c$$$. After receiving $$$n$$$ and the sequence $$$c$$$, Bombloong must construct and output a tree isomorphic to Nailoong's tree.
Communication Protocol
In each test, the contestant's program will be run twice. A testing tool is provided in the handout files for local debugging.
First Run
In the first run, you play the role of "Nailoong".
Input
The first line contains a string first, which allows your program to identify that this is the first run.
The second line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2\le n\le2\times10^5)$$$, the number of vertices in the tree.
The next $$$n-1$$$ lines each contain two integers $$$u,v$$$ $$$(1\le u,v\le n)$$$, denoting an edge of the tree.
It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \times 10^5$$$.
Output
Your output should contain $$$T$$$ lines. The $$$i$$$-th line contains a sequence $$$col_1,col_2,\dots,col_n$$$ of length $$$n$$$, where each $$$col_i\in\{\textbf{0},\textbf{1}\}$$$ $$$(i=1,2,\dots,n)$$$ denotes the color assigned by Nailoong to the $$$i$$$-th vertex.$$$col_i=0$$$ denotes white, and $$$col_i=1$$$ denotes black.
Second Run
In the second run, you play the role of "Bombloong".
Input
The first line contains a string second, which allows your program to identify that this is the second run.
The second line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2\le n\le2\times10^5)$$$, the number of vertices in the tree.
The next line contains $$$2n-1$$$ integers $$$c_1,c_2,\dots,c_{2n-1}$$$, denoting the sequence generated by the judge according to Nailoong's coloring.
It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \times 10^5$$$.
Output
For the $$$i$$$-th test case, let the input number of vertices be $$$n$$$.
Output $$$n-1$$$ lines, each containing two integers $$$u,v$$$ $$$(1\le u,v\le n)$$$, denoting an edge of the reconstructed tree.
You must ensure that the output tree is isomorphic to the tree given in the first run.
The two samples in the PDF statement included in the contest materials correspond to the two runs of the same test case.
Suppose the trees in the first input are $$$t_1,t_2,\dots,t_T$$$ in order, and Nailoong outputs the corresponding colorings $$$col_1,col_2,\dots,col_T$$$, where every vertex is assigned one of the two colors $$$0,1$$$.
For each $$$1\le i\le T$$$, let $$$a_i$$$ be the sequence generated by the little leopard from the tree $$$t_i$$$ and the coloring $$$col_i$$$.
The evaluator then randomly generates a permutation $$$p_1,p_2,\dots,p_T$$$ of $$$1,2,\dots,T$$$ and gives the sequences
$$$$$$ a_{p_1},a_{p_2},\dots,a_{p_T} $$$$$$
to Bombloong in this order during the second run.
Suppose the trees output by Bombloong are $$$t'_1,t'_2,\dots,t'_T$$$. For every $$$1\le i\le T$$$, the evaluator checks whether $$$t'_i$$$ is isomorphic to $$$t_{p_i}$$$.
How to Use the Handout Files
python3 tree_communication_testing_tool2.py data.in ./solution
python3 tree_communication_testing_tool2.py --trials 10 data.in ./solution
python3 tree_communication_testing_tool2.py data.in python3 solution.py
Here, solution is a compiled C/C++ executable, and solution.py is a Python source file.
The file data.in contains the input for the first run.
The optional parameter --trials specifies the number of independent simulations. In different simulations, the little leopard may choose different DFS starting vertices and different orders in which adjacent vertices are visited.
You are given a weighted tree with $$$n$$$ vertices, rooted at vertex $$$1$$$.
Vertex $$$i$$$ has a frequency band $$$c_i$$$ and a transmission time $$$a_i$$$. Each frequency band $$$c$$$ has an importance value $$$w_c$$$.
For two distinct vertices $$$u,v$$$ using the same frequency band, define their synchronization cost as
$$$$$$ D(u,v)=|a_u-a_v|+\operatorname{dist}(u,v), $$$$$$
where $$$\operatorname{dist}(u,v)$$$ denotes the sum of edge weights on the simple path between vertices $$$u$$$ and $$$v$$$.
There are $$$q$$$ queries. Each query gives a vertex $$$x$$$ and a non-negative integer $$$K$$$.
We say that a frequency band $$$c$$$ produces an echo in the subtree of $$$x$$$ if and only if there exist two distinct vertices
$$$$$$ u,v\in\operatorname{subtree}(x) $$$$$$
such that
$$$$$$ c_u=c_v=c $$$$$$
and
$$$$$$ D(u,v)\le K. $$$$$$
Here, $$$\operatorname{subtree}(x)$$$ denotes the subtree rooted at $$$x$$$.
For each query, find the sum of the importance values of all frequency bands that produce an echo, i.e.
$$$$$$ \sum_{c=1}^{m} w_c \left[ \exists\,u\ne v\in\operatorname{subtree}(x),\ c_u=c_v=c,\ D(u,v)\le K \right]. $$$$$$
The square brackets denote the Iverson bracket: its value is $$$1$$$ if the condition inside is true, and $$$0$$$ otherwise.
The first line contains three integers $$$n,m,q$$$ $$$(1\le n\le10^6,\ 1\le m\le10^5,\ 1\le q\le10^6)$$$, denoting the number of nodes, the number of frequency bands, and the number of queries, respectively.
The second line contains $$$m$$$ integers $$$w_1,w_2,\ldots,w_m$$$ $$$(0\le w_c\le10^9)$$$, where $$$w_c$$$ is the importance of frequency band $$$c$$$.
The third line contains $$$n$$$ integers $$$c_1,c_2,\ldots,c_n$$$ $$$(1\le c_i\le m)$$$, where $$$c_i$$$ is the frequency band used by node $$$i$$$.
The fourth line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ $$$(0\le a_i\le10^9)$$$, where $$$a_i$$$ is the transmission time of node $$$i$$$.
Each of the next $$$n-1$$$ lines contains three integers $$$u,v,d$$$ $$$(1\le u,v\le n,\ 0\le d\le10^9)$$$, indicating that there is an undirected edge of weight $$$d$$$ between nodes $$$u$$$ and $$$v$$$.
Each of the next $$$q$$$ lines contains two integers $$$x,K$$$ $$$(1\le x\le n,\ 0\le K\le4\times10^{18})$$$, describing a query.
It is guaranteed that the input edges form a tree and that every answer fits in a signed 64-bit integer.
For each query, output one integer — the sum of the importance values of all frequency bands that produce an echo in the subtree of vertex $$$x$$$.
It is guaranteed that every answer fits in a signed $$$64$$$-bit integer.
7 3 55 7 111 2 1 3 2 1 310 4 13 8 9 20 71 2 21 3 32 4 42 5 13 6 23 7 51 51 62 63 91 15
0 12 7 5 23
The synchronization costs between vertices using the same frequency band are as follows:
Therefore:
Given a 1-indexed string $$$s$$$ of length $$$n$$$. For each $$$1\le i\le n$$$, a non-negative integer $$$r$$$ is called a palindromic radius of center $$$i$$$ if the substring of length $$$2r+1$$$ centered at $$$i$$$ is a palindrome.
For each center $$$i$$$, find the palindromic radius such that the corresponding palindromic substring is lexicographically smallest.
There are multiple test cases.
The first line contains a single integer $$$T$$$ $$$(1\le T\le10^6)$$$, denoting the number of test cases.
For each test case, there is a single line containing a non-empty string $$$s$$$. It is guaranteed that $$$s$$$ consists only of lowercase English letters.
It is guaranteed that $$$\sum|s|\le10^6$$$.
Output $$$T$$$ lines. For each test case, output a line containing $$$|s|$$$ integers, where the $$$i$$$-th integer represents the answer for center $$$i$$$.
2cabacbca
0 0 1 0 0 0 00
In the first sample test case, there are three palindromic substrings centered at $$$3$$$, namely b, aba, and cabac. The lexicographically smallest among them is aba, with a radius of $$$1$$$.
You are given two coprime positive integers $$$p$$$ and $$$q$$$. There are $$$pq$$$ different types of cards, numbered $$$0,1,\ldots,pq-1$$$.
There are two types of standard card packs:
There are now $$$n$$$ cards arranged on the table, where the number of the $$$i$$$-th card is $$$a_i$$$. You need to process $$$Q$$$ operations of the following two types:
Note: When repacking the cards, every card in the interval must belong to exactly one pack, and each kind of standard card pack may be used any number of times.
The first line contains four integers $$$n,p,q,Q$$$ ($$$1\le n,p,q,Q\le 3\times 10^5$$$, $$$2\le p+q\le 3\times 10^5$$$, $$$\gcd(p,q)=1$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i \lt pq$$$), denoting the initial number of each card.
The next $$$Q$$$ lines each describe one operation in the form 1 i x or 2 l r:
For each 2 l r operation, if the specified cards can be partitioned exactly into several standard card packs, output YES; otherwise, output NO.
8 2 3 50 0 2 3 4 1 4 22 1 52 6 81 8 52 6 82 6 7
YES NO NO YES
When $$$p=2,q=3$$$:
For the first query, the multiset of cards in the interval is $$$\{0,0,2,3,4\}$$$. It can be partitioned into $$$\{0,2,4\}+\{0,3\}$$$, so the answer is YES.
For the last query, the multiset of cards in the interval is $$$\{1,4\}$$$. It forms exactly one Type-2 standard card pack, so the answer is YES.
Given a deterministic finite automaton (DFA) with a state set $$$Q=\{1,2,\dots,n\}$$$, a start state $$$q=1$$$, an accept state set $$$F$$$ of size $$$m$$$, and an alphabet $$$\Sigma=\{\texttt{A},\texttt{C}\}$$$. Find the lexicographically smallest string accepted by the automaton with a length of at least $$$k$$$. Since the answer might be very long, if the length of the answer exceeds $$$n$$$, you only need to output the last $$$n$$$ characters of the answer. If no string satisfies the aforementioned requirements, output WA.
A string is accepted by the automaton if and only if there exists a walk starting from the initial state and ending at an accept state, such that the letters on the traversed transition edges exactly form the string. The walk can pass through repeated vertices and edges.
There are multiple test cases.
The first line contains a single integer $$$T$$$ $$$(1\le T\le 5\times 10^5)$$$, denoting the number of test cases.
For each test case:
It is guaranteed that $$$\sum n\le 10^6$$$.
Output $$$T$$$ lines, each containing a string, where the $$$i$$$-th line represents the answer for the $$$i$$$-th test case.
25 1 642 55 34 25 55 53 1 222 33 33 3
CCCCAWA
In the first test case of the sample, the language recognized by the DFA is $$$\{\texttt{A}\texttt{C}^{2t+1}\texttt{A}\mid t\ge 0\}$$$.
You are given an integer $$$n$$$, an integer $$$k$$$, and an integer $$$p$$$.
Consider all functions $$$$$$ f:\{1,2,\ldots,n\}\to\{1,2,\ldots,n\}. $$$$$$
Let $$$f^k$$$ denote the $$$k$$$-fold iteration of $$$f$$$. If $$$x \in \{1, 2, \dots, n\}$$$ satisfies $$$f^k(x) = x$$$, then $$$x$$$ is called a fixed point of $$$f^k$$$.
Find the number of functions $$$f$$$ that have exactly $$$p$$$ fixed points under $$$f^k$$$. Output the answer modulo $$$10^9+7$$$.
Each test contains multiple test cases.
The first line contains an integer $$$T$$$ $$$(1\le T\le10^4)$$$, the number of test cases.
Each of the next $$$T$$$ lines contains three integers $$$n,k,p$$$ $$$(1\le n,k\le10^6,\ 0\le p\le n)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output one integer on a separate line, denoting the answer modulo $$$10^9+7$$$.
73 2 22 1 03 1 03 2 03 3 34 2 44 1 2
1218231054