There is a special abacus lying flat on the table with a total of $$$m$$$ vertical rods. Each vertical rod has some beads, forming a total of $$$n$$$ rows. The $$$i$$$-th row from the top contains $$$a_i$$$ beads, where $$$a_i$$$ is a positive integer not exceeding $$$m$$$. Adjacent rows on a vertical rod may not necessarily both have beads. Now, the abacus is stood upright, and all beads fall naturally. Determine the number of beads in each row after the beads have fallen. It can be proved that there are still $$$n$$$ rows after the beads fall.
The process for the first sample case is as follows:

The first line contains two integers $$$n$$$ and $$$m(1\le n,m\le 10^4)$$$.
The next line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$. It is guaranteed that $$$1\le a_i\le m$$$ for all $$$i=1,2,\dots,n$$$.
The only line contains $$$n$$$ integers represent the beads in each row after the process.
4 64 2 6 3
2 3 4 6
7 103 6 6 4 3 1 5
1 3 3 4 5 6 6
Computer Networks is a very important course in computer science. Suppose there are two machines, A and B, that need to transmit data through a chain-like network formed by $$$n-1$$$ routers. Specifically, when machine A wants to send data to machine B, it first sends the data to router 1, which then forwards it to router 2, router 2 forwards it to router 3, and so on, until router $$$n-1$$$ finally forwards the data to machine B.
Now, machine A needs to send $$$K$$$ bits of data to machine B. It first divides the data into $$$m$$$ groups, where the size of each group is $$$l_i$$$, satisfying $$$\Sigma l_i=K$$$. These groups are pushed to router 1 in the order of $$$l_1,l_2,...,l_m$$$. The push rate of machine A is $$$r_0$$$ bit/s, the push rate of router 1 is $$$r_1$$$bit/s, ..., and the push rate of router $$$n-1$$$ is $$$r_{n-1}$$$bit/s. The routers forward data in units of groups. When a router receives bits from a group, it waits until all bits of that group have arrived before starting to push the group to the next router. The forwarding strategy of the routers is first-come-first-served. While a router is forwarding data from one group, data from other groups is stored in the router's buffer, waiting to be forwarded. Assume that once a router or machine pushes a bit, the bit immediately arrives at the next router or machine. The question is: starting from the time when machine A pushes the first bit, at what time will machine B completely receive all $$$K$$$ bits of data sent by machine A?
The first line contains three positive integers $$$n(1 \leq n \leq 10^5), m(1 \leq m \leq 3\times 10^5), K(1\leq K\leq 3\times 10^5)$$$, which represent that the communication between machine A and machine B passes through $$$n-1$$$ routers, machine A divides the data to be transmitted to B into $$$m$$$ groups, and the total number of bits of data that machine A wishes to transmit to B is $$$K$$$, respectively.
The second line contains $$$n$$$ positive integers. The first integer is $$$r_0(1\leq r_0\leq 10^9)$$$, representing the push rate (in bit/s) of machine A. The following $$$n-1$$$ integers are $$$r_i(1\leq r_i\leq 10^9)$$$, where the $$$i$$$-th integer represents the push rate (in bit/s) of the $$$i$$$-th router.
The third line contains $$$m$$$ positive integers. The $$$i$$$-th integer is $$$l_i(1\leq l_i\leq K)$$$, representing the number of bits in the $$$i$$$-th group. It is guaranteed that $$$\Sigma l_i=K$$$.
A real number, in seconds, representing the time from when machine A pushes the first bit until machine B completely receives the entire $$$K$$$ bits of data that machine A intends to transmit to B. Suppose your answer is $$$Your\_Answer$$$ and the standard answer is $$$Answer$$$. If either $$$\frac{|Your\_Answer−Answer|}{Answer}\leq 10^{−9}$$$ or $$$|Your\_Answer−Answer|\leq10^{−9}$$$ is satisfied, then your answer is considered correct.
2 2 32 11 2
3.500000000000000
The data link is: A $$$\to$$$ Router 1 $$$\to$$$ B, where the push rate of A is 2 bit/s, and the push rate of Router 1 is 1 bit/s.
A intends to transmit 3 bits of data to B. Before sending, A divides the data into two groups, with lengths of 1 bit and 2 bits, respectively. A first pushes the group of length 1, followed by the group of length 2.
The second group is completely pushed to Router 1 after waiting for $$$\frac{1+2}{2}=1.5$$$ seconds. Since the first group completely arrives at Router 1 after waiting for $$$\frac{1}{2}=0.5$$$ seconds (i.e., the time for A to push it), and Router 1 takes $$$\frac{1}{1}=1$$$ second to completely push out the first group after fully receiving it, the second group arrives at Router 1 exactly when the first group is completely pushed out from Router 1. Thus, the second group does not need to queue at Router 1 and can be pushed out immediately. Therefore, the answer is $$$\frac{2+1}{2}+\frac{2}{1}=3.5$$$ seconds.
There are $$$n$$$ circles on a plane. The $$$i$$$-th circle has a center at $$$(x_i,y_i)$$$ and a radius of $$$r_i$$$. These $$$n$$$ circles are pairwise non-intersecting, but they may be tangent (including internally or externally). There are two points $$$S$$$ and $$$T$$$ located on the arcs of these circles. Student A starts at point S and can only travel along the circular arcs. Each circle has a parameter $$$v_i$$$, which represents the time per unit length of traveling along the arc of that circle. The goal is to find the minimum total time for Student A to travel from point $$$S$$$ to point $$$T$$$ along the circular arcs.
The first line contains five integers: $$$n(1≤n≤10^4), S_x,S_y, T_x,T_y( |S_x|,|S_y|,|T_x|,|T_y|≤10^9)$$$. Here, $$$n$$$ denotes the number of circles on the plane, $$$(S_x,S_y)$$$ represents the coordinates of the initial position $$$S$$$ of Student A, and $$$(T_x,T_y)$$$ denotes the coordinates of the target destination $$$T$$$.
The next $$$n$$$ lines each contain four positive integers $$$x_i,y_i,r_i,v_i( |x_i|,|y_i|≤10^9, 1≤r_i≤10^8, 0≤v_i≤10^5)$$$, representing the parameters of the $$$i$$$-th circle: the center coordinates are $$$(x_i,y_i)$$$, the radius is $$$r_i$$$, and the cost per unit length of traveling along the arc of this circle is $$$v_i$$$.
The data guarantees that points $$$S$$$ and $$$T$$$ are located on the arcs of two (possibly distinct) circles, no two circles intersect (they may be tangent, either internally or externally), and no two circles are entirely coincident (i.e., there are no two circles with identical center coordinates and equal radius).
Output a single line containing a real number, which represents the minimum total cost for Student A to travel from point $$$S$$$ to point $$$T$$$. If it is impossible to reach the destination, output $$$-1$$$.
The correctness of your answer is judged as follows:
If your determination of whether the destination is reachable (i.e., outputting $$$-1$$$ or a real number) differs from the standard answer, your answer is considered wrong.
If your determination matches the standard answer (both output $$$-1$$$ or both output a real number), and assuming your output is $$$Your\_Answer$$$ and the standard answer is $$$Answer$$$, your answer is considered correct if it satisfies either:$$$\frac{|Your\_Answer - Answer|}{Answer + 1} ≤ 10^{-6}$$$ or $$$|Your\_Answer-Answer| ≤ 10^{-6}$$$.
3 0 1 3 01 1 1 13 1 1 24 1 4 3
6.283185307179586
3 -10 0 0 00 0 10 20 0 8 30 4 4 5
-1
As shown in the example figure above, Circle 1 is denoted by the lowercase letter a, Circle 2 by b, and Circle 3 by c. One possible path achieving the minimum cost to travel from point $$$S$$$ to point $$$T$$$ is marked by the red path.
Dr.Z wants to live a perfect life. In the future, he acquires a time machine that gives him a chance to alter his life. His life is represented by a string $$$S$$$. He can modify the string $$$S$$$ using another string $$$T$$$.
Each modification allows him to choose a positive integer $$$i$$$ in the range $$$[1, |S| - |T| + 1]$$$ and replace the substring $$$S[i : i + |T| - 1]$$$ with $$$T$$$. More precisely, for each $$$j \in [1, |T|]$$$, he sets $$$S_{i+j-1} = T_j$$$. This operation can be performed infinitely many times.Dr.Z considers his life perfect if and only if $$$\forall i \in [1, |S|], S_i = S_{|S| - i + 1}$$$—that is, when the string $$$S$$$ becomes a palindrome.
Dr.Z wants to know whether it's possible for his life to become perfect through these modifications.
There are $$$t$$$ test cases. For each test case, you are given two strings $$$S$$$ and $$$T$$$.If $$$S$$$ can become a palindrome, output Yes. Otherwise, output No.
The first line contains an integer $$$t$$$ means that there are $$$t$$$ test cases.
The next $$$t$$$ lines each contain $$$2$$$ strings $$$S,T\ (1\le |S|\le 10^6,|T|\le 60)$$$.
It is guaranteed that $$$S$$$ and $$$T$$$ contain only uppercase and lowercase letters, and the total length of all strings $$$S$$$ across test cases does not exceed $$$2\times 10^6$$$.
The next $$$t$$$ lines each contain Yes or No.
9asdppsaAA AadpjdaAjcKaA AadpjdsdAadaA AadpjdjAjcKsA AadABAB ABBBA ABabcdDea cdabcdDea cbasbAADbbaaa abbc
Yes Yes Yes No No Yes No Yes Yes
In the first test case, $$$S$$$ can be turned into a palindrome through 3 modifications. By sequentially choosing $$$i = 1, 4, 2$$$, $$$S$$$ is changed as follows: $$$S \to \text{AadppsaAA}\to \text{AadAadaAA}\to \text{AAadadaAA}$$$.
In the fourth test case,there is no way to change.
Dr.Orange is conducting research in animal psychology, and one of the studies involves inferring the number of each animal in the ecosystem based on their dietary habits. It is known that there are $$$n$$$ types of animals in the ecosystem, and the $$$i$$$-th type of animal consumes $$$a_i$$$ portions of bait per time. Dr.Orange's experiment was conducted over $$$m$$$ days, and on the $$$i$$$-th day, $$$t_i$$$ portions of bait were deployed, with all bait being consumed each day. For each of the $$$m$$$ days, different animals take turns to consume bait. You need to answer how many different eating sequences. Two sequences are the same only if the animals at each position in the sequence are of the same species. Since this result can be very large, please provide the answer modulo $$$10^9+7$$$.
The first line contains two integers $$$n, m(1\le n,m\le 100)$$$.
The second line contains $$$n$$$ integers, where the $$$i$$$-th integer represents $$$a_i(1\le a_i\le 100)$$$.
The third line contains $$$m$$$ integers, representing the amount of bait deployed on the $$$i$$$-th day, $$$t_i(1\le t_i\le 10^9)$$$.
Output one line with $$$m$$$ integers, where the $$$i$$$-th integer represents the answer for the $$$i$$$-th day modulo $$$10^9+7$$$.
5 3 5 4 4 2 3 5 8 3
3 16 1
10 5 9 1 6 5 10 4 9 2 7 6 64 92 43 30 2
566507809 840913760 608266829 85862862 2
For the first day of the first sample, there are three possible eating sequences: $$$[1]$$$, $$$[4,5]$$$, and $$$[5,4]$$$. The numbers in the sequences represent the types of animals.
As you all know, you are participating in the SYSUCPC (SYSU Counting Periodic-string Contest) finals.
A string is considered good if and only if it can be rearranged into a perfectly periodic string with sysu as its period (which means several sysu repetitions). For example, sysu,yssu,ssyyssuu are all good, while ussu, sysusys are not. Given a string $$$S$$$, determine how many of its substrings are good.
A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by the deletion of several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.
The only line contains a single string $$$S(4\le |S|\le 2\times 10^5)$$$. It is guaranteed that $$$S$$$ only contains lowercase English letters.
An integer, representing the number of good substrings of $$$S$$$.
ilovesysusysu
6
There are $$$6$$$ good substrings : sysu,ysus,susy,usys,sysu,sysusysu.
Gray code is a binary numeral system where two successive values differ in only one bit. This property makes it useful in various applications, such as minimizing errors in digital communication and measurement systems. Gray code is also known for its reflective and cyclic characteristics, which help eliminate significant errors during random sampling. It was invented by Frank Gray in the 1940s and has various construction methods.
An $$$n$$$-bit Gray code $$$G_n=[G_{n,0},G_{n,1},\cdots,G_{n,2^n-1}]$$$ can be generated by the following algorithm:
For example, $$$G_2=[0,1,3,2]$$$, $$$G_3=[0,1,3,2,6,7,5,4]$$$.
Now there is an array $$$a_0,a_1,\cdots,a_{2^n-1}$$$ of length $$$2^n$$$. Initially, for all $$$i\in\{0,1,\cdots,2^n-1\}$$$, $$$a_i=i$$$. We will perform $$$q$$$ operations on this array, where each operation is one of the following two types:
Please output the results of each query in order.
The first line of input contains two integers, which are $$$n$$$ ($$$1\le n\le 10$$$) and $$$q$$$ ($$$1\le q\le 5000$$$).
The next $$$q$$$ lines describe the operations. Each of these lines starts with an integer $$$\text{op}$$$ ($$$\text{op}\in\{1,2\}$$$), indicating the type of operation.
It is guaranteed that the sum of $$$m$$$ over all type-1 operations does not exceed $$$5000$$$.
Output the binary forms of all the results of the type-2 operations without leading zeros, each on its own line.
3 42 01 4 1 2 3 22 1002 10
0 110 11
Initially, $$$[a_0,a_1,\cdots,a_{2^n-1}]=[0,1,2,3,4,5,6,7]$$$.
After the second operation, $$$[a_0,a_1,\cdots,a_{2^n-1}]=[0,1,3,2,6,7,5,4]$$$.
As you all know, you are participating in the SYSUCPC (SYSU Constructive Problem Contest) finals. Undoubtedly, the Constructive Kingdom of Sun Yat-sen University is eager for you to tackle some related problems.
Given a string $$$S$$$ containing only lowercase letters, determine the maximum number of disjoint subsequences of length $$$4$$$ that can be formed, such that all subsequences are sysu. Formally, a subsequence of a string $$$S$$$ is a subset of characters of $$$S$$$ that read from left to right.
A greedy algorithm is currently used: each time, starting from the end, an unused u is considered, and it is matched with nearest unused s,y,s sequentially to form a qualified subsequence, which is then removed.
You are now requested to provide a string $$$S$$$ such that the answer obtained by the greedy method is $$$x$$$, while the correct answer is $$$y$$$. If no such $$$S$$$ exists, output $$$-1$$$.
The only line contains two integers $$$x,y(1\leq x,y\leq 10^5)$$$.
A string $$$S$$$ such that the answer obtained by the greedy method is $$$x$$$, while the correct answer is $$$y$$$. If no such $$$S$$$ exists, output $$$-1$$$. The length of $$$S$$$ must not exceed $$$4\times 10^5$$$.
1 1
ilovesysu
2 1
-1
Student A is studying numeral systems. For a natural number $$$n$$$, Student A wants to know the smallest digit sum among the representations of $$$n$$$ in bases from $$$2$$$ to $$$R$$$. For example, the natural number $$$6$$$ has a representation of $$$(110)_2$$$ in base $$$2$$$, with a digit sum of $$$2$$$, and a representation of $$$(20)_3$$$ in base $$$3$$$, also with a digit sum of $$$2$$$.
There are multiple test cases.
The first line of input contains a positive integer $$$T(1\leq T \leq 100)$$$, indicating the number of test cases.
The next $$$T$$$ lines each contain two positive integers $$$n,R(2\leq n,R\leq 10^{12})$$$.
Output $$$T$$$ lines, each containing an integer, representing the smallest digit sum.
46 37 430 5999967000273 999983
2 3 2 3
For $$$6$$$, the digit sum is minimized in base $$$2$$$ or base $$$3$$$. For $$$7$$$, the digit sum is minimized in base $$$2$$$ or base $$$3$$$. For $$$30$$$, the digit sum is minimized in base $$$5$$$.
Recently, Student A has been studying strings. Certain peculiar strings caught his attention, so he named such strings "quasi-palindromic strings".
A string $$$s$$$ is a quasi-palindromic string if and only if the following two conditions are both satisfied:
1. There does not exist any contiguous substring $$$t$$$ of $$$s$$$ with length greater than or equal to 2 that is a palindromic string.
2. Suppose the length of $$$s$$$ is $$$n$$$, there exist $$$l,r$$$ satisfying $$$1\leq l\leq r\leq n$$$, such that after reversing the substring $$$s[l...r]$$$, $$$s$$$ becomes a palindromic string.
For example: The string "aac" is not a quasi-palindromic string because it contains the contiguous substring "aa" of length 2, which is a palindrome. The string "abdc" is not a quasi-palindromic string because there do not exist $$$l,r$$$ such that reversing the substring $$$s[l...r]$$$ would turn $$$s$$$ into a palindrome. The string "bcabca" is a quasi-palindromic string.
Now, given a string $$$T$$$, Student A wants to know how many contiguous substrings of $$$T$$$ are quasi-palindromic strings.
Here, contiguous substrings are distinguished solely by their starting and ending positions in the original string. For instance, in the string "aba", the contiguous substring [1,1] (the first "a") and the contiguous substring [3,3] (the last "a") are considered two different contiguous substrings, even though they are both the character "a".
A string $$$T(1\leq |T|\leq 5\times 10^5)$$$.
An integer representing the number of contiguous substrings of $$$T$$$ that are quasi-palindromic strings.
abcabc
9
abc
3
In the first sample, all contiguous substrings of length 1 are quasi-palindromic strings. Among substrings longer than 1, the quasi-palindromic strings are "abcab", "bcabc", and "abcabc".
Dr.Z is studying a permutation $$$p$$$ of length $$$n$$$ (i.e., $$$p$$$ contains each integer from $$$1$$$ to $$$n$$$ exactly once). He performs $$$q$$$ experiments, each defined by parameters $$$(l, r, x)$$$.
In each experiment, he processes the subarray $$$p_l, p_{l+1}, \dots, p_r$$$ sequentially. Starting with value $$$x$$$, for each element $$$p_i$$$ in the subarray:
Dr.Z needs your help to compute:
The first line contains two integers $$$n,q\ (1 \le n, q \le 500000)$$$
The second line contains $$$n$$$ distinct integers $$$p_1, p_2, \dots, p_n\ (\forall 1\le i\le n,1\le p_i\le n)$$$
The next $$$q$$$ lines each contain 3 integers $$$l,r,x\ (1 \le l \le r \le n,1 \le x \le n)$$$
For each experiment, output two integers:
6 6 1 4 3 2 5 6 1 6 4 3 4 2 3 4 4 5 5 1 2 5 3 6 6 4
2 4 1 1 2 1 5 1 2 2 4 0
In his recent work on permutation properties, Dr.Z investigates the relationship between element values and their indices. A key focus is the cardinality of the set of indices $$$i$$$ where $$$p_i \gt i$$$ (called larger position) and where $$$p_i \lt i$$$ (called smaller position). To formalize this, he defines $$$f(n,x,y)$$$ as the number of permutations of $$$n$$$ elements containing exactly $$$x$$$ larger positions and $$$y$$$ smaller positions. Dr.Z now aims to characterize this function completely by determining the values of $$$f(n,x,y)$$$ across all valid positive integers $$$x$$$ and $$$y$$$ after modulo $$$m$$$. Could you help him solve this problem efficiently?
The only line contains two integers $$$n,m(2\le n\le 2000,2\le m\le 10^9+7)$$$.
There are $$$n-1$$$ rows in total. The $$$i$$$-th row contains $$$n-i$$$ integers. The $$$j$$$-th integer represents the result of $$$f(n,i,j)$$$ modulo $$$m$$$.
5 998244353
10 10 5 1 10 35 21 5 21 1
The five permutations of $$$x=1,y=3$$$ are $$$[1,5,2,3,4], [4,1,2,3,5], [5,1,2,4,3], [5,1,3,2,4]$$$, and $$$[5,2,1,3,4]$$$.
The highway system of Province G can be viewed as a weighted undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge represents a segment of the highway, and each node represents a city. Every highway segment is bidirectional. The $$$i$$$-th highway segment connects the two cities $$$u_i$$$ and $$$v_i$$$, with a length of $$$w_i$$$ kilometers.
Miss Orange is currently commuting in Province G. Her car consumes one unit of fuel per kilometer traveled. Any city has a gas station where the car's fuel tank can be fully refilled, and the fuel consumption of Miss Orange's car while driving within the city is negligible. Miss Orange has planned $$$q$$$ trips. The $$$i$$$-th trip starts from city $$$x$$$ and ends at city $$$y$$$. She wants to know the minimum fuel tank capacity required for this trip.
However, she has not decided on $$$x$$$ and $$$y$$$ but only knows that $$$x$$$ and $$$y$$$ lie within the interval $$$[l_i, r_i]$$$. Specifically, for all $$$l_i \le x \lt y \le r_i$$$, Miss Orange wants to know the sum of the minimum fuel tank capacities required to travel from $$$x$$$ to $$$y$$$. Formally, let $$$f(x, y)$$$ denote the fuel tank capacity required for a trip starting at $$$x$$$ and ending at $$$y$$$. You need to output $$$\sum\limits_{l_i \le x \lt y \le r_i} f(x, y)$$$.
Since she needs to consider her next plan based on the current one, certain constraints will be imposed on you in the problem.
The first line contains two integers $$$n(1\leq n \leq 5 \times 10^{4})$$$ and $$$m(1 \leq m \leq 2 \times 10^{5})$$$.
The next $$$m$$$ lines each contain three integers $$$u,v(1\leq u,v\leq n),w(1\leq w \leq 10^{9})$$$, representing an edge between $$$u$$$ and $$$v$$$ with a weight of $$$w$$$. It is guaranteed that the graph is connected.
Then, one line contains an integer $$$q(1\leq q \leq 5 \times 10^4)$$$.
The next $$$q$$$ lines each contain two integers $$$l',r'(0\leq l',r'\leq 10^{18})$$$, representing the encrypted queries. Each time, you need to XOR the current $$$l'$$$ and $$$r'$$$ with the previous answer to obtain the real $$$l$$$ and $$$r$$$.The data guarantees that the real $$$l$$$ and $$$r$$$ satisfy $$$1 \leq l \leq r \leq n$$$.
Output $$$q$$$ lines, each containing one integer representing the answer.
5 101 2 131 3 131 4 124 5 114 4 74 2 104 5 131 4 82 4 83 4 854 42 428 2910 101 5
0 24 11 0 92