Recently, Colin became addicted to the theory of additive combinatorics, which is about counting additive structures in sets. This theory has seen exciting developments and dramatic changes in direction in recent years, thanks to its connections with areas such as number theory, ergodic theory, and graph theory.
One fundamental problem in additive combinatorics is sumsets. For two sets of integers $$$A,B$$$, we define the sumset of $$$A$$$ and $$$B$$$ to be the set of all sums of an element from $$$A$$$ with an element from $$$B$$$. That is, $$$$$$ A+B=\{a+b:a\in A, b\in B\} $$$$$$ Now Colin gives you three sets $$$A,B,C$$$; could you determine whether $$$C$$$ is the sumset of $$$A$$$ and $$$B$$$?
The first line contains three integers $$$n_1,n_2,n_3~(1\le n_1,n_2\le 10^3,1\le n_3\le 10^6)$$$, representing the sizes of $$$A$$$, $$$B$$$, and $$$C$$$.
The second line contains $$$n_1$$$ integers $$$a_1,a_2,\cdots,a_{n_1}~(1\le a_i\le 10^9)$$$, representing the numbers in $$$A$$$.
The third line contains $$$n_2$$$ integers $$$b_1,b_2,\cdots,b_{n_2}~(1\le b_i\le 10^9)$$$, representing the numbers in $$$B$$$.
The fourth line contains $$$n_3$$$ integers $$$c_1,c_2,\cdots,c_{n_3}~(1\le c_i\le 2\times 10^9)$$$, representing the numbers in $$$C$$$.
It is guaranteed that the numbers in the same set are pairwise distinct.
If $$$C$$$ is the sumset of $$$A$$$ and $$$B$$$, output YES. Otherwise, output NO.
2 2 31 22 13 4 2
YES
2 2 21 21 22 3
NO
2 2 41 21 21 2 3 4
NO
Azora the corgi loves music but cannot catch the rhythm well, especially when counting beats! After hard research on music theory, Azora found a hidden theorem: There won't be a note crossing the boundary between the beats for modern songs (or for most barking sessions for that matter).
To simplify the problem, we assume that a modern song consists of several sequential notes whose lengths are $$$l_1,l_2,\cdots,l_n$$$ milliseconds. The notes will be played one by one, which means the song will start playing the first note at time $$$0$$$, and the second note at the beginning of the $$$l_1+1$$$ milliseconds, and the third note at the beginning of the $$$l_1+l_2+1$$$ milliseconds, and so on.
If the length of the beat is $$$L$$$ milliseconds, then there should not exist any note that is playing but not starting to play at the beginning of the $$$kL$$$ milliseconds, for any non-negative integer $$$k$$$. Formally, there should not exist any note $$$i$$$ such that $$$\sum_{j=1}^{i-1} l_j \lt kL$$$ but $$$\sum_{j=1}^il_j \gt kL$$$ for any non-negative integer $$$k$$$.
Now Azora has received a new song from her humans, and she wants to practice counting beats before she barks the song back to them. To challenge herself, Azora wants to find the smallest possible length of a beat, such that it satisfies the theorem. Can you help her?
The first line contains a single integer $$$n~(1\le n\le 2\times 10^5)$$$, representing the number of notes in the song.
The second line contains $$$n$$$ integers $$$l_1,l_2,\cdots,l_n~(1\le l_i\le 10^9)$$$, representing the length of each note.
Output a single integer, representing the minimum possible length of a beat.
51 2 3 6 5
6
51 2 3 4 5
10
Colin is a first-year Ph.D. student, working hard with many beautiful but unrealistic academic fantasies. He aims to design clever algorithms for essential problems and publish them in top conferences.
There are $$$n$$$ conferences Colin is interested in. The $$$i$$$-th one starts receiving submissions at 8 a.m. on the day $$$r_i$$$ , and the deadline to submit papers is 8 p.m. on the day $$$d_i$$$. After the submitted paper has been reviewed by the experts, the authors will be notified of the result at 2 p.m. on the day $$$t_i$$$. The result is either Accepted or Rejected. In addition, there is an impact factor $$$w_i$$$ for the $$$i$$$-th conference, which represents the reputation of the conference. To simplify the problem, we guarantee that the impact factors of conferences are pairwise distinct.
But recently, he sadly found that his papers were rejected again and again. By summarizing the past data, Colin raised an assumption: the probability of acceptance for a paper is equal to the number of times it has been submitted over the impact factor of the conference. Formally, if Colin submits a paper to the $$$i$$$-th conference now, and it has already been submitted for $$$k$$$ times (including this time), then the probability of acceptance this time is equal to $$$$$$ \min(1, \frac{k}{w_i}) $$$$$$ Now Colin has $$$m$$$ papers he would like to submit, and the $$$i$$$-th paper will be finished at 9 a.m. on the day $$$f_i$$$. We say a conference is available at a time if it has already started receiving papers, but its deadline hasn't passed. Once Colin finishes each paper, if there does not exist any available conference at that time, then he will think this paper is not welcome and won't submit it anymore; if there exists any available conference at that time, he will instantly submit it to one of the available conferences with the highest impact factor. Then Colin will repeat as follows:
On the day of receiving the notification of the result, if the paper is Rejected:
If the paper is Accepted, Colin will earn reputation points, which are equal to the impact factor of the conference that accepts the paper. He will not submit the paper to other conferences.
Colin would like to ask, if his assumption is valid, what is the expected value of reputation points he can earn from each paper? If a paper is not accepted in the end, then Colin will earn $$$0$$$ reputation points from it. Please find the answer modulo $$$998244353$$$.
Notice that all the times mentioned are in AOE time, and there is no need to consider any issues related to time zones.
The first line contains two integers $$$n,m~(1\le n\le 5\times 10^3,~1\le m\le 10^5)$$$, representing the number of conferences Colin is interested in, and the number of papers Colin would like to submit.
For the following $$$n$$$ lines, each line contains four integers $$$r_i, d_i, t_i,w_i~(1\le r_i \lt d_i \lt t_i\le 10^9,~1\le w_i\le 10^8)$$$, representing the information for the $$$i$$$-th conference: it starts receiving submissions from 8 a.m. on day $$$r_i$$$, the deadline is 8 p.m. on day $$$d_i$$$, and authors will be notified of the results at 2 p.m. on day $$$t_i$$$ whether their submissions are accepted. It's guaranteed that all the $$$w_i$$$ are pairwise distinct.
For the following $$$m$$$ lines, each line contains a single integer $$$f_i~(1\le f_i\le 10^9)$$$, representing that Colin will finish the $$$i$$$-th paper at 9 a.m. on the day $$$f_i$$$.
For each paper, print a line with a single integer, representing the expected value of reputation points Colin could earn from it, modulo $$$998244353$$$.
5 31 2 3 12 3 4 23 4 5 34 5 6 45 6 7 5123
1 249561091 332748120
For the first paper, Colin will submit it to the first conference, and according to the assumption, the paper will definitely be accepted. Thus, the expected value of reputation he could earn is equal to the impact factor of the first conference, which is $$$1$$$.
For the second paper, Colin will first submit it to the second conference with $$$50\%$$$ probability of being accepted. If it is rejected, he will receive the notification on the day $$$4$$$, then he will submit it to the fourth conference, with $$$\frac{2}{4}=50\%$$$ probability of being accepted. If it is still rejected, then he will receive the notification on day $$$6$$$, then he will submit it to the fifth conference, with $$$\frac{3}{5}=60\%$$$ probability of being accepted. If it is still rejected, then there is no more chance to submit it. Thus, the expected value is $$$2\times 50\%+ 4\times 50\%\times 50\%+5\times 50\%\times 50\%\times 60\%=\frac{11}{4}$$$, which equals $$$249561091$$$ modulo $$$998244353$$$.
Recently, Colin found that DeepSeek is such a useful AI that he can always give it problems he meets and receive lots of good suggestions, especially when Colin turns on the DeepThink option: DeepSeek will show the procedure of thinking, and it makes everything look so clear and convincing!
Although DeepSeek's thinking procedure does look like a human's, Colin found a phenomenon that always starts with, "Okay, so I want to figure out how to..."
Colin wants to build an extraordinary AI by himself: ColinSeek, but since Colin knows too little about AI, he decides to start by imitating. Now, please help Colin write the very first code for the ColinThink option of ColinSeek:
When the user asks in the format How to xxx?, show the thinking procedure as Okay, so I want to figure out how to xxx. The last part (xxx) is the same as the user's question.
A single line represents the user's question. The input is guaranteed to start with "How to "$$$~$$$and end with "?". The input between these two parts consists of lower English letters, digits, and blank spaces. Except for the two sample inputs, the length of the input line (excluding the line ending) is larger than 1024 bytes and less than 16384 bytes.
Output the thinking procedure of ColinSeek, as described in the description.
How to win the champion of gxcpc?
Okay, so I want to figure out how to win the champion of gxcpc.
How to solve these 13 questions ?
Okay, so I want to figure out how to solve these 13 questions .
This is the easy version of the problem. The only difference between the versions is the range of $$$n$$$.
Colin likes to play the Happy Eliminate game to kill time. Usually, the player is asked to find a fixed pattern in the given content, then eliminate it. The variety of patterns makes the game rich and exciting.
To research which pattern makes the game most exciting, Colin built a model: The contents given to the user are represented as a string $$$s$$$, and the pattern is another string $$$t$$$. In each turn of the game, the user can do one of the following two operations, and the game will be kept going until $$$t$$$ becomes empty:
Colin defines a game's excitement as the maximum number of times the second operation can be performed. He wants to find the best pattern to maximize excitement, but he has no idea how to construct it. Thus, he turned it over to you, the top player of Happy Eliminate.
Recall that $$$|s|$$$ represents the length of the string $$$s$$$, and $$$s[i,j]$$$ represents the substring of the string $$$s$$$, starting from the $$$i$$$-th character to the $$$j$$$-th character (including the $$$i$$$-th and the $$$j$$$-th).
The first line contains a single integer $$$T$$$, representing the number of test cases.
For each test case:
The first line contains a single integer $$$n~(1\le n\le 6000)$$$, representing the length of the string $$$s$$$.
The second line contains a string $$$s$$$, consisting only of lowercase letters.
It's guaranteed that the sum of $$$n$$$ is not larger than $$$6000$$$.
For each test case, output a single line with a single integer, representing the maximum possible excitement.
39abcabcabc4aaaa5ababa
343
For the first sample, you can choose $$$t$$$ as $$$abc$$$.
For the second sample, you can choose $$$t$$$ as $$$aaaa$$$.
For the third sample, you can choose $$$t$$$ as $$$aba$$$.
This is the hard version of the problem. The only difference between the versions is the range of $$$n$$$.
Colin likes to play the Happy Eliminate game to kill time. Usually, the player is asked to find a fixed pattern in the given content, then eliminate it. The variety of patterns makes the game rich and exciting.
To research which pattern makes the game most exciting, Colin built a model: The contents given to the user are represented as a string $$$s$$$, and the pattern is another string $$$t$$$. In each turn of the game, the user can do one of the following two operations, and the game will be kept going until $$$t$$$ becomes empty:
Colin defines a game's excitement as the maximum number of times the second operation can be performed. He wants to find the best pattern to maximize excitement, but he has no idea how to construct it. Thus, he turned it over to you, the top player of Happy Eliminate.
Recall that $$$|s|$$$ represents the length of the string $$$s$$$, and $$$s[i,j]$$$ represents the substring of the string $$$s$$$, starting from the $$$i$$$-th character to the $$$j$$$-th character (including the $$$i$$$-th and the $$$j$$$-th).
The first line contains a single integer $$$T$$$, representing the number of test cases.
For each test case:
The first line contains a single integer $$$n~(1\le n\le 5\times 10^5)$$$, representing the length of the string $$$s$$$.
The second line contains a string $$$s$$$, consisting only of lowercase letters.
It's guaranteed that the sum of $$$n$$$ is not larger than $$$5\times 10^5$$$.
For each test case, output a single line with a single integer, representing the maximum possible excitement.
39abcabcabc4aaaa5ababa
343
For the first sample, you can choose $$$t$$$ as $$$abc$$$.
For the second sample, you can choose $$$t$$$ as $$$aaaa$$$.
For the third sample, you can choose $$$t$$$ as $$$aba$$$.
The annual GXCPC (Grand XOR Counting Problem Challenge) is here again! This year, Judge Colin has prepared another super difficult counting problem for the contestants! Can you slay this ultimate counting problem and win the championship?
Eva has two magic parameters $$$k_1$$$ and $$$k_2$$$.
Colin has two integer sequences $$$a_1,a_2,\cdots,a_n$$$ and $$$b_1,b_2,\cdots,b_n$$$.
They want to know how many pairs of indices $$$(i,j)$$$ satisfy:
Where $$$\oplus$$$ represents the bitwise XOR operation.
The first line contains three integers $$$n,k_1,k_2~(1\le n\le 2\times 10^5,1\le k_1,k_2 \lt 2^{30})$$$, representing the length of the two sequences and the magic parameters.
The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_{n}\ (1\le a_i \lt 2^{30})$$$, representing the first sequence.
The third line contains $$$n$$$ integers $$$b_1,b_2,\cdots,b_{n}\ (1\le b_i \lt 2^{30})$$$, representing the second sequence.
A single integer, representing the number of pairs satisfying the condition.
5 1 2 3 4 5 6 7 1 2 3 1 2
2
There are two valid pairs in the sample: $$$(2,3)$$$ and $$$(4,5)$$$
Colin is a big fan of Hollow Knight. The grand world view of Hollownest and the distinctive bosses deeply attracted him, and fortunately, the second generation, Hollow Knight: Silksong, will be released very soon! Silksong follows Hornet, the former princess of Hollow Knight's fallen kingdom of Hallownest and a supporting character in that game, as she is forced to explore a totally new land.
So many people are excited to play Silksong! There's even a comment in 2020 on bilibili that has become famous: "Actually, I'm pretty lucky. I just got into Hollow Knight 1, and Hollow Knight 2 is about to come out." It has received over 28,000 likes now.
Anyway, the most recent news is that Silksong will be released this year! The most exciting news is that people will have the chance to play the demo in Australia on September 18, 2025.
It cannot be luckier for those who haven't played Hollow Knight ever! So Colin strongly suggested that Eva play Hollow Knight before the second generation was released. To value how lucky Eva is, Colin defines the luckiness to be the number of dates between the first day Eva starts to play and the day of demo-play.
Given the date Eva starts to play Hollow Knight, can you help Colin calculate how lucky Eva is?
A single line with three integers separated by a space $$$y,m,d~(2017\le y\le 2025,1\le m\le 12, 1\le d\le 31)$$$, representing the date Eva starts to play Hollow Knight in the year $$$y$$$, month $$$m$$$, and day $$$d$$$. It's guaranteed that the input date is valid, and it is earlier than the day of demo-play of Silksong (September 18, 2025) and later than the day Hollow Knight was released (February 24, 2017).
A single integer, representing the luckiness of Eva.
2025 5 25
116
Recently, Colin has been learning the relationship between sets and bitmasks. We can use binary numbers (bitmasks) to represent sets, and if some bits are 1 in the bitmask, then it means that the sets include the elements corresponding to the indices of these bits.
Now Colin has $$$n$$$ non-negative integers $$$a_1, a_2, \cdots, a_n$$$ and all these integers are less than $$$2^k$$$. Now Colin tries to use the concept of bitmasks and sets to understand the relationship between these integers.
For a non-negative integer $$$x \in\left[0,2^k\right)$$$, Colin defines that $$$a_i$$$ is feasible with $$$a_j$$$ under the augmentation of $$$x$$$, if and only if the set corresponding to the bitmask $$$a_i+x$$$ is a subset of the set corresponding to the bitmask $$$a_j+x$$$. Then Colin uses $$$f(x)$$$ to represent the number of all the pairs $$$(i, j)$$$ such that $$$a_i$$$ is feasible with $$$a_j$$$ under the augmentation of $$$x$$$.
Now Colin would like to ask you to calculate the sum of all the $$$f(x)$$$, modulo $$$998244353$$$ .
Formally, please calculate
$$$$$$ \left(\sum_{x=0}^{2^k-1} f(x)\right) \bmod 998244353 $$$$$$
The first line contains two integers $$$n,k~(1\le n\le 10^6, 1\le k\le 20)$$$, representing the number of integers Colin has and all of these integers are less than $$$2^k$$$.
The following line contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n\left(0 \leq a_i \lt 2^k\right)$$$.
Output a single integer, representing the answer.
2 22 0
10
$$$f(0)=3:(1,1),(2,1),(2,2)$$$
$$$f(1)=3:(1,1),(2,1),(2,2)$$$
$$$f(2)=2:(1,1),(2,2)$$$
$$$f(3)=2:(1,1),(2,2)$$$
Recently, Eva learned several advanced data structure techniques for trees. To show her progress, she asked Colin to give her a challenging problem about tree statistics.
However, Colin just gave her a very typical problem:
Given a tree with $$$n$$$ vertices, and vertex $$$1$$$ is the root. Each vertex has an integer weight $$$w_i$$$.
Let $$$lca(u,v)$$$ represent the lowest common ancestor of the vertices $$$u$$$ and $$$v$$$.
Given two integer sequences $$$a_1,a_2,\cdots,a_x~(1\le a_i\le n)$$$ and $$$b_1,b_2,\cdots,b_y~(1\le b_i\le n)$$$. Define the joint power of these two sequences to be $$$$$$ \sum_{i=1}^x\sum_{j=1}^yw_{lca(a_i,b_j)} $$$$$$
Please calculate the value of this joint power.
Eva thinks this problem is too easy, so she decided to change the problem into an online problem:
First, given the tree and the weight of each vertex. Initially, both sequences are empty.
Then there will be $$$m$$$ operations, each one is of the following two types:
After each operation, you need to output the current joint power of the two sequences.
However, this version of the problem is too hard for Eva, so she added an additional limitation that, after each operation, the sum of values in the first sequence will not exceed $$$10^6$$$. Now Eva turns this problem to you; do you know how to solve it?
The first line contains two integers $$$n,m~(1\le n,m\le 10^5)$$$, representing the number of vertices in the tree and the number of operations.
The second line contains $$$n$$$ integers $$$w_1,w_2,\cdots,w_n(1\le w_i\le 10^5)$$$, representing the weight of each vertex.
For the following $$$n-1$$$ lines, each line contains two integers $$$u_i,v_i~(1\le u_i,v_i\le n, u_i\ne v_i)$$$, representing that there is an edge connecting $$$u_i$$$ and $$$v_i$$$ in the tree. It's guaranteed that all the edges in the input form a tree.
For the following $$$m$$$ lines, each line contains two integers $$$op_i, u_i~(op_i\in\{1,2\},1\le u_i\le n)$$$, representing an operation. It's guaranteed that after each operation, the sum of values in the first sequence will not exceed $$$10^6$$$.
For each operation, output a single line with a single integer, representing the joint power of the two sequences after the corresponding operation.
3 51 2 31 21 31 12 11 22 21 3
0 1 2 5 7
10 61 2 10 5 5 6 5 6 2 21 22 31 44 52 63 76 82 96 102 101 72 51 91 52 6
0 2 3 6 12 17
Colin is a huge fan of the Kingdom Rush franchise tower defense games. Last year, KR released the latest generation of Kingdom Rush: Kingdom Rush 5: Alliance. As a formidable evil arises in the new generation, an unexpected alliance is taking shape! It will take the finest warriors of Linirea and the relentless Dark Army together to stop it. Therefore, the most attractive feature of the latest generation of games is that you can use two heroes simultaneously!
To measure the power of the double-hero feature, Colin would like to do some simple experiments: Assume that a hero's attack range is a circle on the 2D plane with its coordinates as the center. The path of enemies is a segment on the 2D plane. Colin would like to ask you how long the total length of the enemy's path is that is covered by at least one hero's attack range?
The first line contains three integers $$$x_1,y_1,r_1\ (|x_1|,|y_1|\le 10^9, 1\le r_1\le 10^9)$$$, representing the coordinates of the first hero as $$$(x_1,y_1)$$$, and the radius of its attack range is $$$r_1$$$.
The second line contains three integers $$$x_2,y_2,r_2\ (|x_2|,|y_2|\le 10^9, 1\le r_2\le 10^9)$$$, representing the coordinates of the second hero as $$$(x_2,y_2)$$$, and the radius of its attack range is $$$r_2$$$.
The third line contains four integers $$$a,b,c,d~(|a|,|b|,|c|,|d|\le 10^9)$$$, representing the path of enemies as a segment from $$$(a,b)$$$ to $$$(c,d)$$$.
A single line with a number, representing the total length of the enemy's path that is covered by at least one hero's attack range.
Your output will be considered correct if the absolute or relative error to the jury does not exceed $$$10^{-6}$$$.
0 0 11 1 10 0 1 1
1.414213562373095
0 0 12 2 1-1 -1 3 3
4.000000000000000
One day, Colin got lost in a complete undirected graph $$$G$$$ with $$$n$$$ vertices, and each vertex $$$i$$$ is associated with a magic parameter $$$c_i$$$. For each pair of vertices $$$(i,j)$$$, there exists an undirected edge connecting them with weight $$$w_{i,j} = \gcd(c_i, c_j) + \text{lcm}(c_i, c_j)$$$.
Can you find the graph's minimum spanning tree $$$G$$$ to save Colin?
Recall that $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$, and $$$\text{lcm}(x, y)$$$ is the least common multiple of $$$x$$$ and $$$y$$$.
The first line contains a single integer $$$n~(1\le n\le 10^5)$$$, representing the number of vertices in the graph.
The second line contains $$$n$$$ positive integers $$$c_1,c_2,\cdots,c_n~(1\le c_i\le 10^6)$$$.
Output a single line with a single integer, representing the total weight of the edges in the minimum spanning tree of $$$G$$$.
47 8 9 10
163