Find the number of different strings of length $$$k$$$ that you can get by concatenating prefixes of a given string $$$S$$$.
Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 2000$$$) — the number of test cases. The description of test cases follows.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq k \leq 2000$$$) — the length of $$$S$$$ and the size of the desired strings.
The second line contains a string $$$S$$$ consisting of $$$n$$$ lowercase letters. It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$2000$$$.
For each test case, print a line with one integer — the answer to the problem. Since the answer may be huge, print it modulo $$$998244353$$$.
45 7aaaaa4 4abcd3 3aba7 15abacaba
1832809
Baus, the top laner of Los Ratones, is legendary for his Sion strategy: equipping Ghost and Teleport, ignoring every enemy on the map, and running in a straight line toward the enemy Nexus. The champion dies on impact, but the passive keeps him rolling, dealing massive damage to structures even in death. It is chaotic, it is reckless, and it works.
When Baus announced a dedicated Sion stream, the Los Ratones community went wild. Thousands of viewers flooded the channel, filling the chat with messages. Bastian and Franchesco, the team's two most dedicated fans and self-appointed chat moderators, recorded the username of every viewer who sent at least one message during the stream. All usernames in the registry are distinct.
After the stream, they realized the list had grown too large to manage. They agreed it needed to be trimmed by exactly $$$k$$$ usernames enough to keep it under control, but no more, since every extra deletion risks removing a genuine fan. The only moderation tool at their disposal works as follows: given a search string $$$t$$$, the system displays all usernames that begin with $$$t$$$, and a single confirmation removes every username shown in those results.
Bastian and Franchesco need to choose which $$$k$$$ usernames to remove and execute the deletions using as few searches as possible. Can you help them?
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^4$$$, $$$1 \le k \lt n$$$), the number of usernames in the registry and the number of usernames to remove.
The next $$$n$$$ lines each contain one username consisting of lowercase English letters. All usernames are distinct. The sum of the lengths of all usernames does not exceed $$$10^5$$$.
Print a single integer. The minimum number of search operations needed to remove exactly $$$k$$$ usernames from the registry.
5 2 sion sionfan sionbot run runner
1
5 4 sion sionfan sionbot run runner
2
The evil math magician Matematicus is about to destroy the world! and he has given Ana, Beto and Carlos a last chance to defeat him. He will give them a number $$$N$$$ and each one of them will guess a random number between $$$1$$$ and $$$N$$$, and if the number guessed by Ana and by Beto added equals the number guessed by Carlos, they'll pass the test. If they manage to do this $$$k$$$ times, the world will be saved.
To make it more interesting Matematicus used his magic to ensure that the number that Ana guesses is smaller than the number guessed by Beto, and that the number guessed by Beto is smaller than the number guessed by Carlos. Our heros have asked you, what's the probability the world will be saved by them?
On the first line a number $$$k$$$, ($$$1\leq k\leq 10^6$$$) the number of times they'll have to do the test. On the next $$$k$$$ lines, a number $$$N_i$$$($$$3\leq N\leq 10^6$$$) the $$$i$$$-th number given by Matematicus.
$$$k$$$ lines, in the $$$i$$$-th line a number representing the probability that they passed the first $$$i$$$ tests. It can be proven that the answer can be represented as a rational number $$$\frac{p}{q}$$$ with coprime $$$p$$$ and $$$q$$$. You need to output $$$p \cdot q^{-1}$$$ mod $$$10^{9}+7$$$.
13
1
33510
1 800000006 466666670
The Dragon King's palace is unlike any structure in the mortal realm. Rather than walls and corridors, its grounds consist of two great circular gardens, each centered around an enchanted fountain. The gardens may overlap, lie apart, or one may even contain the other — the Dragon King enjoys architectural ambiguity.
Once a century, the Dragon King holds his Grand Procession: an honor guard must march in a perfectly straight line, never stepping outside the palace grounds (the union of the two gardens). To impress visiting dignitaries, the procession route must span at least $$$K$$$ units in length.
You are given two circles $$$C_1$$$ and $$$C_2$$$ in the plane, with centers $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$ and radii $$$r_1$$$, $$$r_2$$$ respectively. Determine whether there exists a line segment of Euclidean length at least $$$K$$$ such that every point on the segment belongs to $$$C_1 \cup C_2$$$ — that is, lies within or on the boundary of at least one of the two gardens.
The first line contains a single integer $$$T$$$ $$$(1 \le T \le 10^3)$$$, the number of procession scenarios the Dragon King wishes to evaluate.
Each test case consists of three lines.
The first line contains three integers $$$x_1$$$, $$$y_1$$$, and $$$r_1$$$ $$$(-10^9 \le x_1,\, y_1 \le 10^9,\ 1 \le r_1 \le 10^6)$$$, the center and radius of the first garden $$$C_1$$$.
The second line contains three integers $$$x_2$$$, $$$y_2$$$, and $$$r_2$$$ $$$(-10^9 \le x_2,\, y_2 \le 10^9,\ 1 \le r_2 \le 10^6)$$$, the center and radius of the second garden $$$C_2$$$.
The third line contains a single integer $$$K$$$ $$$(1 \le K \le 4 \times 10^6)$$$, the minimum required length of the procession route. All values are integers.
For each test case, print YES if a valid procession route exists, NO otherwise.
10 0 50 0 310
YES
10 0 310 0 37
NO
10 0 54 0 512
YES
You have been hired by a Taqueria who's facing a serious problem, its clients keep calling the "taquero" by "mesero", and he refuses to answer to it. So now, you have to create a censorship program that replaces every instance of the word "mesero" with "taquero".
A string $$$S$$$ ($$$1\leq |S| \leq 10^6$$$) made up of lowercase letters with no spaces, the string you'll have to process.
A string $$$R$$$, the string $$$S$$$ after replacing all instances of "mesero" with "taquero".
mesero
taquero
icpc
icpc
You are given $$$n$$$ trapezoids, all of height $$$1$$$.
Trapezoid $$$i$$$ is described by four positive integers $$$l_{i,0}$$$, $$$r_{i,0}$$$, $$$l_{i,1}$$$, $$$r_{i,1}$$$. At height $$$y = 0$$$, it occupies the interval $$$[-l_{i,0}, r_{i,0}]$$$. At height $$$y = 1$$$, it occupies the interval $$$[-l_{i,1}, r_{i,1}]$$$.
Equivalently, its vertices are $$$(-l_{i,0}, 0)$$$, $$$(r_{i,0}, 0)$$$, $$$(r_{i,1}, 1)$$$, $$$(-l_{i,1}, 1)$$$.
Before placing a trapezoid, you may reflect it with respect to the horizontal axis, the vertical axis, both, or neither.
The following picture shows the four possible orientations of the same trapezoid.
You have to place all trapezoids inside the strip $$$0 \le y \le 1$$$. You may translate each trapezoid only along the $$$x$$$ axis, and you may choose any left-to-right order.
The interiors of different trapezoids must not intersect, but they are allowed to touch at the boundary.
The width of a placement is $$$\max_x - \min_x$$$, where $$$\max_x$$$ is the largest $$$x$$$-coordinate covered by at least one trapezoid, and $$$\min_x$$$ is the smallest one.
Find the minimum possible width.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 20$$$).
Each of the next $$$n$$$ lines contains four integers $$$l_{i,0}$$$, $$$r_{i,0}$$$, $$$l_{i,1}$$$, $$$r_{i,1}$$$ ($$$1 \le l_{i,0}, r_{i,0}, l_{i,1}, r_{i,1} \le 10^9$$$).
For the given input format, it can be proved that the answer is always an integer.
Print one integer: the minimum possible width.
31 8 8 14 4 4 48 1 1 8
33
52 9 9 28 3 1 103 8 10 15 5 5 51 7 6 2
58
In the first sample, one optimal placement uses the order $$$1, 3, 2$$$. In the picture below, the left panel shows the order $$$1, 2, 3$$$, while the right panel shows the order $$$1, 3, 2$$$.
The right panel has width $$$33$$$, so the answer is $$$33$$$.
It's school time, and Professor Carlos's next assignment is going to be done on pairs. And he wants to avoid as much problems as possible, so he has decided that the pairs shouldn't be friends. He has made a list of who is friend with who, and knows that the friendship in the school follows 3 rules:
So given the list of $$$M$$$ friendships he has observed and the number of students $$$N$$$, help him make as many pair of non friends as possible.
The first line of input contains two integers $$$N$$$ and $$$M$$$ ($$$1\leq N\leq 10^5$$$, $$$0\leq M \leq 10^6$$$) — The number of students and the number of friendships Carlos has registered.
The next $$$M$$$ lines contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$0\leq a_i, b_i\leq N-1$$$) — The pair $$$(a_{i}, b_{i})$$$ means that $$$a_i$$$ is friend with $$$b_i$$$.
In the first line a number $$$k$$$ indicating the maximum number of pairs Carlos can make. In the next $$$k$$$ lines, 2 numbers $$$c_i$$$ and $$$d_i$$$ representing the $$$i$$$-th pair you would make.
5 30 11 23 4
2 2 4 1 3
The Legendary Huron airlines is going through a tough time: tariffs are increasing and their customer satisfaction is plummeting. A particular customer complaint that they receive often is that the time that it takes to board one of their planes is too long. To try and tackle this problem their optimization department is developing an algorithm and your job is to test it.
For a set of $$$N$$$ passengers the algorithm outputs a fixed order $$$A$$$ in which the passengers are supposed to board the plane. Given this order your job is to compute how much time will it take to onboard the $$$N$$$ passengers. For the $$$i$$$-th passenger you know in what row ($$$r_i$$$) their seat is and how many seconds ($$$k_i$$$) it takes them to store their luggage in the overhead compartment. It takes $$$1$$$ second to move from the $$$\rho$$$-th row to the $$$(\rho+1)$$$-th one, thus the total time it takes the $$$i$$$-th passenger to take a seat is $$$r_i + k_i$$$ (since the door can be seen as row $$$0$$$ of the plane). It's impossible for two or more passengers to be on the same row at the same exact time. Hence, no two passengers can onboard at the same time.
A new rule was added since no one wants to wait on the aisle. This rule states that a passenger is only allowed to start onboarding if all of the previous passengers that are seating in a closer row (to the door) than them have already seated. More formally, this rule states that the $$$i$$$-th passenger can only begin to onboard the plane at time $$$\tau$$$ if there's no $$$j \lt i$$$ such that $$$r_j \leq r_i$$$ and $$$t_j + r_j + k_j \gt \tau$$$, where $$$t_j$$$ is the time at which the $$$j$$$-th passenger started onboarding the plane.
Help the Legendary Huron airlines improve their customer satisfaction!
In the first line you will get one integer $$$N$$$ $$$(1 \leq N \leq 4 \cdot 10^5)$$$ — the number of passengers that will onboard the plane.
In the next line you will get $$$N$$$ integers $$$r_i$$$ $$$(1 \leq r_i \leq 10^5)$$$ — the row for the $$$i$$$-th passenger. It's confirmed that any row doesn't repeat more than $$$4$$$ times in the input.
In the last line you will get $$$N$$$ integers $$$k_i$$$ $$$(1 \leq k_i \leq 10^9)$$$ — the time it takes the $$$i$$$-th passenger to store their luggage in the overhead compartment.
Print a single integer — the time, in seconds, that it takes to onboard the $$$N$$$ passengers onto the plane.
210 51 2
11
210 51 6
12
34 5 25 3 1
17
Problem B — Bad Latex from 2026 ICPC Gran Premio de Mexico - Primera Fecha had some trouble with its testcases. Apparently, the input format didn't specify correctly the format restrictions on the testdata and contestants ended up very confused about it.
This time, you will help Racsó by coding a validator for the currently generated test cases. The restrictions Racsó set up so that the problem becomes easy to solve are the following:
Can you handle these test cases?
The first line of input contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — The number of lines of the test case.
The following $$$n$$$ lines contain a string $$$s_{i}$$$ ($$$1 \leq |s_{i}| \leq 1000$$$) — The $$$i$$$-th line contains the contents of the $$$i$$$-th line of the test case.
It is guaranteed that all $$$s_{i}$$$ consists of printable ASCII characters (codes in range $$$[32, 126]$$$).
Print a single line — "Ok" if the test case is valid or "Validation failed" otherwise.
4This example shows a valueOf 1000000000 without being compressed to 10^{9}Which is annoying when read. $ S_{10} = 2^{100000} + 780000 $My ID is RA180000 but that was back in the year 20000
Ok
3This example should showAn incorrect test case since 100.10^{1000}Should not be correct.
Validation failed
2Another simple example with multiple incorrect braces$$ 10^{100} = 10 {14} $$
Validation failed
1$ 100^{2x + 1} $ should not be possible
Validation failed
1Leading and Trailing
Validation failed
2Hey, this one looks like it is not valid.However, it is even if it contains a single 0
Ok
1Hello, this has two consecutive spaces.
Validation failed
1Wait, is 000 valid?
Validation failed
1No nested $ X_{10_{11}} $ allowed!
Validation failed
1My email is [email protected]
Validation failed
Jorge, as a dedicated ICPC participant, was upsolving the problems from the 2026 ICPC Gran Premio de Mexico 1ra Fecha contest. The last problem he upsolved was $$$F(x,l,r)$$$, a problem that asks contestants to find the sum of a function over all subarrays of a given array. Immediately after he finished upsolving, he started thinking about more problems that ask for the sum of a function over all subarrays, and he came up with the following problem:
For a given array $$$A=[a_1,a_2,\dots,a_n]$$$, Jorge defines $$$F(l,r)$$$ as:
$$$$$$ F(l,r)=\prod_{i=l}^r a_i $$$$$$
Jorge defines the value of the array $$$A$$$ as the sum of $$$F(l,r)$$$ over all its subarrays:
$$$$$$ \sum_{l=1}^n \sum_{r=l}^n F(l,r) $$$$$$
Jorge immediately found the answer to this problem, so he thought that it was too easy. Then he thought, "What if we now find the sum of the values of all permutations of length $$$n$$$?" This problem is not as trivial as Jorge thought, so he asks you to solve it.
You are given an integer $$$n$$$. Help Jorge find the sum of the values of all permutations of the integers $$$1,2,\dots,n$$$. Since the answer might be huge, find it modulo $$$998244353$$$.
Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases.
Each test case consists of a single line with an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the permutation.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a line with an integer — the answer to the problem modulo $$$998244353$$$.
51235100
11011641532586129619
Remember to upsolve all the problems!
You are given two simple undirected graphs $$$G_1$$$ and $$$G_2$$$ on the same set of labeled vertices $$$1, 2, \dots, n$$$.
In one operation, you choose exactly $$$k$$$ vertices. Then, for every pair of chosen vertices:
In other words, you toggle every edge inside the chosen set of $$$k$$$ vertices.
Determine whether it is possible to transform $$$G_1$$$ into $$$G_2$$$ after some number of operations.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 200000$$$).
The second line contains one integer $$$m_1$$$ ($$$0 \le m_1 \le \min(300000, \frac{n(n-1)}{2})$$$), the number of edges of $$$G_1$$$.
Each of the next $$$m_1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$), describing one edge of $$$G_1$$$.
The next line contains one integer $$$m_2$$$ ($$$0 \le m_2 \le \min(300000, \frac{n(n-1)}{2})$$$), the number of edges of $$$G_2$$$.
Each of the next $$$m_2$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$), describing one edge of $$$G_2$$$.
It is guaranteed that both graphs are simple.
Print YES if it is possible to transform $$$G_1$$$ into $$$G_2$$$, and NO otherwise.
5 4041 22 33 44 5
NO
6 5081 31 41 51 62 32 42 52 6
YES
It is the year 1912 and you are in the United Kingdom, attending the Fifth International Congress of Mathematicians (ICM). The internet, League of Legends, and Geosé don't exist yet... what a wonderful world!
Sir Abraham Marckess and Sir Feet Tester (Yes, that name is actually pretty common in Zacateland, the city he is from) are two assistants to the brilliant mathematician Edmund Landau.
Landau is about to present four fundamental problems related to prime numbers at this congress. What they don't yet know is that the year 2026 will arrive and these problems will still remain unsolved. Mr. Landau already has the first three prepared, but for the last one, he still has some things to verify. The problem is:
Or said more simply:
Since computers as we know them today didn't exist back then, and Landau didn't want to look incompetent at the congress, he needed to verify empirically that his proposal was correct at least up to a very large number.
Thus, Landau tasked Sir Marckess and Sir Tester with the enormous task of calculating how many $$$f(n)$$$ are truly primes up to a given $$$N$$$. However, not trusting their abilities completely, Landau decided to test them by posing this question through many queries.
Your mission is to help Sir Marckess and Sir Feet Tester answer them all correctly before the conference begins.
The first line contains a single integer $$$Q$$$ ($$$1 \le Q \le 4 \times 10^6$$$), the number of queries.
The next $$$Q$$$ lines each contain an integer $$$N$$$ ($$$1 \le N \le 7 \times 10^7$$$).
For each query, print a single integer: the count of values $$$n$$$ in the range $$$1 \le n \le N$$$ for which $$$f(n) = n^2 + 1$$$ is prime.
3101001000
519112
For the first query ($$$N = 10$$$): $$$f(n) = n^2 + 1$$$ for $$$n \in \{1, 2, \ldots, 10\}$$$ yields the values $$$\{2, 5, 10, 17, 26, 37, 50, 65, 82, 101\}$$$. Among these, the primes are $$$\{2, 5, 17, 37, 101\}$$$, for a total of 5.