Last night, an incredible number of shooting stars appeared in the night sky! Each of them popped into existence at some point, moved along a straight line, and then disappeared. You were amazed and happy about the number of wishes you could make, but after double checking with your local fortune teller, you know that you can't wish on two shooting stars that crossed paths in the sky. Although sad, you actually only have two wishes$$$^{\text{∗}}$$$ you really care about.
Now, you only need to find two shooting stars that didn't cross paths. Luckily, you recorded the path of each shooting star. If such a pair of shooting stars does not exist, you would like to figure that out, as otherwise, you might keep searching forever.
$$$^{\text{∗}}$$$World peace and becoming LGM on Codeforces.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$), the number of testcases.
Each testcase consists of:
No endpoint appears twice, and no two shooting stars traveled along parallel paths. There are no three collinear endpoints where two belong to the same shooting star.
The sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.
For each testcase, if there is no pair of shooting stars with non-intersecting paths, output "No". Otherwise, output "Yes", followed by two distinct integers $$$i$$$ and $$$j$$$ ($$$1 \leq i, j \leq n$$$), the indices of two shooting stars without intersecting paths.
340 1 3 21 5 1 12 0 0 54 0 -2 33-2 0 2 0-1 2 -1 -21 -2 2 24-1 -3 2 2-2 -1 1 2-3 0 3 00 -3 0 3
No Yes 2 3 Yes 1 2
After building wells last year, Bob is back to building walls, just as he did two years ago. To help mitigate his boredom from doing the same task again, he is allowed to destroy some part of his own creation. The project he is working on right now is building a wall for a playground with letters written on it.
During the construction, the assembly line feeds him one building block at a time, each with one letter written on the block. He can decide whether to use this block to extend the current wall to the right, or if there is at least one intact block, he can smash the new block into the rightmost existing wall block, destroying both in the process.
Bob knows that the children frequenting the playground are most impressed by large objects, so he wants to create the largest possible writing on the wall; that is, the string formed by the letters of the intact building blocks from left to right should be lexicographically maximal. What is this maximum string Bob can build?
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$), the number of testcases.
Each testcase consists of:
The strings contain only upper case letters, and the sum of $$$|s|$$$ over all testcases is at most $$$10^6$$$.
For each testcase, output one string – the lexicographically largest string Bob can build.
5EDCBAABBAXYZBABAZZAAAAAAAAA
EDCBA BA Z ZZ AAAAAAAAA
In the third testcase, Bob uses the first block to build the wall "X", then smashes the 'Y' block into the wall, leaving behind an empty wall. Finally, he uses the 'Z' block to finish with the wall "Z".
There are $$$n$$$ cities arranged on the border of a circle in cyclic order from $$$1$$$ to $$$n$$$. Neighboring cities are connected by a street; that is, for each $$$i$$$ from $$$1$$$ to $$$n-1$$$, $$$i$$$ is connected with $$$i+1$$$, and there is a street connecting $$$1$$$ and $$$n$$$. There are also $$$m$$$ additional streets connecting two cities in a straight line. No two streets intersect outside the cities.
Due to previous mismanagement of funds, all streets are in dire need of repairs. You are to hire some construction companies to repair every street.
You can hire a construction company to repair a subset of all streets. Each construction company has certain conditions for the streets they repair. Suppose there are two cities $$$u$$$ and $$$v$$$ that are endpoints of (possibly different) streets they repair. Then, if there is a street connecting $$$u$$$ and $$$v$$$, they also need to be hired to repair this street $$$uv$$$. Furthermore, there must not be any cycle in the streets they repair, as workers may get lost and keep repairing the same streets. Note that the streets one construction company repairs do not have to be connected.
As you should not waste any money, no street should be repaired more than once. How many construction companies do you have to hire at least?
The input consists of:
No two streets connect the same pair of cities.
Output one integer, the minimum number of construction companies you have to hire.
6 15 2
2
3 0
3
10 31 44 94 7
2
Consider the first sample. The following picture visualizes the input and shows a valid way to assign streets to companies (company 1 is red and company 2 is blue).
The following picture shows an invalid way to assign companies:
There are $$$n$$$ countries arranged in a straight line. Each country has a fighting power $$$p$$$. We skip the definitely very reasonable explanation of why the combined fighting power of two countries is the bitwise XOR of their two fighting powers.
A pair of countries $$$(l, r)$$$, where $$$l \lt r$$$, is called dangerous if their combined fighting power is stronger than every single fighting power of the countries between them and is also stronger than the two countries on their own. Formally, $$$p_l \oplus p_r \gt \max_{i=l}^r p_i$$$.
Count the number of dangerous pairs of countries.
The input consists of:
Output one integer, the number of dangerous pairs.
43 2 4 1
3
76 2 3 1 5 11 0
5
There are $$$n$$$ countries numbered from $$$1$$$ to $$$n$$$. To "strengthen" their local economies, the countries are planning to introduce a new system for restricting trade between countries: It is only allowed for a company to export or import goods between countries $$$a$$$ and $$$b$$$ if it buys a trading license for doing so. You are running a business in country $$$1$$$ which needs to be able to trade with every other country. To be as cost efficient as possible, you will buy a set of licenses such that its total cost is minimized and you can trade with every other country directly or indirectly.
Currently, it is not known how expensive the licenses will be. According to historical data, it is most reasonable to assume that the cost of the trading licenses is a uniformly random integer between $$$0$$$ and $$$t$$$ (inclusive), and the costs for every pair of countries are chosen independently.
You wonder: what is the expected cost that you will have to pay for the trading licenses?
More formally, given two integers $$$n$$$ and $$$t$$$, we assign an integer weight from $$$\{0, \ldots, t\}$$$ to every edge of a complete graph on $$$n$$$ vertices uniformly and independently at random. What is the expected value of the minimum spanning tree?
Compute the answer modulo $$$998\,244\,353$$$.
The input consists of:
Output one integer, the expected value of the minimum spanning tree modulo $$$998\,244\,353$$$.
Formally, let $$$M = 998\,244\,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
2 2
1
3 1
374341633
1 0
0
42 1337
111521655
In the second sample, the answer is $$$\frac{5}{8}$$$.
Given an array $$$a$$$, find the largest sum of a (possibly empty) subarray.
The input consists of:
Output one integer, the answer modulo $$$998244353$$$.
52 -3 4 -1 3
22
1-1
0
In many stories related to ghosts and supernatural rituals, it is common to draw certain symbols, e.g. a pentagram on the floor to summon or trap some supernatural being. Often, those drawings are made using white chalk. However, this is very unrealistic! As everyone knows, those magic drawings only work if they are made using red and blue colors – and you also have to draw them on a whiteboard instead of using chalk.
Somehow, you received a copy of the book "The $$$998244353$$$ most useful ghosts and how to summon them". One of the pages describes a ghost which can magically double your codeforces rating. The page contains a drawing consisting of $$$n$$$ points and $$$m$$$ line segments, each connecting two of the points. Furthermore, you also notice that two line segments can only intersect at their endpoints. But it is not as easy as copying the drawing on your whiteboard: Since you received a black-and-white print version of the book, you still have to figure out the colors of the $$$m$$$ line segments! Luckily, the book contains the hint:
if there is none, your rating will double!
Thus, you want to color the line segments either red or blue such that there is no triangle whose edges all have the same color. Note that a triangle consists of exactly 3 points such that each pair is connected by one of the $$$m$$$ line segments. In particular, a quadrilateral containing a 180° angle is not a triangle!
The input consists of:
If it is possible to color the line segments in red and blue such that there is no triangle whose edges all have the same color, then output a string of length $$$m$$$ consisting of letters R and B describing the colors of the line segments. Otherwise, output "hoax"
4 50 00 1-1 01 01 21 31 42 32 4
BRRRR
Visualization of the sample output:
A large company has to schedule the order of $$$n$$$ events.
There are no dependencies between those events, so each permutation of them is a valid schedule. To find the best order, the boss assigned the following task to some employee: Look at all possible schedules; and for each of them report a score which is an integer between $$$1$$$ (bad) and $$$n$$$ (good). Since the number of schedules is too large to look at each of them individually, the employee decides to assign scores to the schedules uniformly and independently at random.
The next obvious question for someone who enjoys math is: What is the expected value of the minimum score which is assigned to some schedule?
The input consists of:
Output one integer, the expected value modulo $$$998\,244\,353$$$.
Formally, let $$$M = 998\,244\,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
1
1
2
748683266
3
195814737
In the first test case, there is only one possible schedule and it can only be assigned score 1. Thus, the answer is one.
In the second test case, there are two possible schedules. If both of them are assigned score 2, then the minimum score is 2. This happens with probability $$$\frac{1}{4}$$$. Otherwise, the minimum score is 1. Thus, the answer is $$$\frac{1}{4} \cdot 2 + \frac{3}{4} \cdot 1 = \frac{5}{4}$$$.
In the third test case, there are six possible schedules.
The company Kommunikation-Ist-Toll (KIT) has achieved world wide fame for its various messenger apps – they have already published $$$10^9$$$ of those! Obviously, this is a lot of work for the employees. Thus, KIT is always trying to recruit ICPC participants for internships.
Internally, KIT is organized in a tree structure: Employee $$$1$$$ is the CEO, and every other employee $$$i$$$ has a direct boss numbered $$$p_i$$$. Obviously, KIT uses its own messengers for company intern communication. In particular, employee $$$i$$$ uses the messenger app with id $$$x_i$$$ to communicate with the direct boss $$$p_i$$$.
When someone is doing an internship at KIT, they are assigned some direct boss as well as the messenger app used for communication with this boss. Since KIT offers great jobs$$$^{\text{∗}}$$$, all interns stay at KIT and continue working as ex-interns. Then, they can also become the direct boss of some new interns.
To get the internship at KIT, you have to solve the following interview problem about efficiently simulating the company structure:
$$$^{\text{∗}}$$$For example, you are allowed to play table football during work.
The interactor first sends one line with one integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$), describing the number of events which you have to simulate.
After this, you receive $$$q$$$ lines with events described as above in the following format:
Here, $$$n'$$$ represents the number of employees KIT currently employs prior to this interaction. (Initially, $$$n' = 1$$$) For each event of type 2, output and flush its answer in one line, before reading the next event.
Let $$$q_1, q_2$$$ be the number of events of type $$$1$$$ and $$$2$$$, respectively. It is guaranteed that $$$q_1, q_2 \leq 10^5$$$.
101 1 21 2 22 1 32 2 11 1 22 3 41 4 32 3 41 5 12 3 6
-1 2 2 2 3
You are responsible for delivering $$$n$$$ packages to the houses of a long street. Initially, you are located at position $$$0$$$, and the initial time is $$$0$$$. Moving one position unit takes you one time unit. Note that you can also wait at your current position.
For every package $$$i$$$, you are given a time $$$t_i$$$ and location $$$a_i$$$ meaning that you have to deliver the package to position $$$a_i$$$, and the person who ordered the package wants it to arrive at time $$$t_i$$$.
It is not possible to deliver the package at an earlier time since there might be nobody available.
Also, nowadays people tend to complain a lot. If they want their package to be delivered at time $$$t_i$$$ and it is delivered $$$x$$$ time units later, their angriness level is $$$x$$$. Since you don't want to lose your job because of bad reviews by angry customers, you want to find a way to minimize the maximum angriness level of a customer.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 10^5$$$), the number of testcases.
Each testcase consists of:
Over all testcases, the sum of $$$n^2$$$ is at most $$$5 \cdot 10^5$$$.
For each testcase, output one integer – the minimum maximum angriness level which can be achieved.
23-5 4-4 25 330 1-4 10 2
12 5
Like a true gamer, you are truly a W-key (forward moving) player. You would never do something as shameful as S-keying (going backwards), so you have removed that key from your keyboard entirely.
Your friends have recently introduced you to the genre of platformer games. To your dismay, you have noticed that in these games, you have to move right (D-key) instead of forward. As you want to demonstrate to your friends that you are the superior gamer, you have also removed your A-key (moving left).
One level of the platformer you are playing right now works as follows. Initially, there are some enemies to the left and right of you. Every second, you can do exactly one of the following actions:
Every action has a cooldown of 1 second, so you cannot do the same action twice in a row. After your action, every enemy moves one space closer to you. Note that you cannot move right twice in a row, and you also cannot skip an action.
If at any point an enemy touches you, you die. Note that it is allowed to move outside the visible level (there are no enemies there).
You need to determine if it is possible to survive the level and kill all enemies.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 5 \cdot 10^4$$$), the number of levels.
Each level consists of:
The layout consists of 'X', '.', and '#' , your position, an empty field, and an enemy respectively. You are at exactly one position, and there is at least one enemy.
The sum over the length of all strings $$$s$$$ does not exceed $$$10^5$$$.
For each level, if it is possible to beat it, output "Yes". Otherwise, output "No".
5#..X.##.#X.##X#X.##......##X
Yes Yes No No Yes
This is one possible way to beat the first level of the sample:
#..X.# $$$\xrightarrow{\text{L}}$$$ #..X.# $$$\to$$$ .#.X#. $$$\xrightarrow{\text{R}}$$$ .#.X.. $$$\to$$$ ..#X.. $$$\xrightarrow{\text{D}}$$$ ..#.X. $$$\to$$$ ...#X. $$$\xrightarrow{\text{L}}$$$ ....X.
Here, L means attacking left, R means attacking right, and D means moving right. If nothing is written above the arrow, the enemies move.
Like a true gamer, you are truly a W-key (forward moving) player. You would never do something as shameful as S-keying (going backwards), so you have removed that key from your keyboard entirely.
Your friends have recently introduced you to the genre of platformer games. To your dismay, you have noticed that in these games, you have to move right (D-key) instead of forward. As you want to demonstrate to your friends that you are the superior gamer, you have also removed your A-key (moving left).
One level of the platformer you are playing right now works as follows. Initially, there are some enemies to the left and right of you. Every second, you can do exactly one of the following actions:
Every action has a cooldown of 1 second, so you cannot do the same action twice in a row. After your action, every enemy moves one space closer to you. Note that you cannot move right twice in a row, and you also cannot skip an action.
If at any point an enemy touches you, you die. Note that it is allowed to move outside the visible level (there are no enemies there).
You need to determine if it is possible to survive the level and kill all enemies, and if yes, output one possible way to do this.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$), the number of levels.
Each level consists of:
The layout consists of 'X', '.', and '#' , your position, an empty field, and an enemy respectively. You are at exactly one position, and there is at least one enemy.
The sum over the length of all strings $$$s$$$ does not exceed $$$2 \cdot 10^5$$$.
For each level, if it is possible to beat it, output "Yes". Otherwise, output "No".
If it is possible, output a string of length at most $$$3 \cdot |s|$$$, consisting of the letters 'L', 'R', and 'D', representing shooting left, shooting right, and moving right.
It can be shown that if there is a solution, there is one with at most $$$3 \cdot |s|$$$ actions.
5#..X.##.#X.##X#X.##......##X
Yes RDL Yes LRL No Yes RLRLRLRLRLRLRL Yes LDL
This is one possible way to beat the first level of the sample:
#..X.# $$$\xrightarrow{\text{R}}$$$ #..X.. $$$\to$$$ .#.X.. $$$\xrightarrow{\text{D}}$$$ .#..X. $$$\to$$$ ..#.X. $$$\xrightarrow{\text{L}}$$$ ....X.
Here, the characters above the arrows correspond to the taken action. If there is nothing above an arrow, the enemies move.
You have finally caught the evil Dr. Meta! Now, you plan to use one of his inventions against him: The inescapable energy prison. To power the prison, Dr. Meta built a rectangular grid with $$$n$$$ rows and $$$m$$$ columns, where a power cell can be put in each spot. You might not want to put a power cell in all of them, however, as this might overload the prison. Instead, for the prison to work properly, you need the number of power cells in the $$$i$$$th row to be divisible by $$$i$$$, and likewise, the number of power cells in the $$$j$$$th column to be divisible by $$$j$$$. Furthermore, any row or column without a power cell would lead to a catastrophic energy shortage, setting back humanity's scientific progress by centuries.
To put your plan into action, you need to figure out which spots to fill with a power cell. There is also the possibility that this invention doesn't work – after all, the trap that was supposed to teleport you to the moon didn't work either...
The input consists of:
If it is possible to power the prison, output "Yes" on one line, followed by $$$n$$$ lines with $$$m$$$ characters each: '#' if the spot of the grid should contain a power cell, and '.' otherwise.
If it is not possible, only output "No" on one line.
4 4
Yes ##.# #### .### ####
1 2
No