There's a sticker album very popular among the children of Pavussulandia. To fill the album, they need to find $$$M$$$ distinct stickers with identifiers from $$$1$$$ to $$$M$$$. The stickers are sold in packs, and there are $$$N$$$ packs available for purchase. Each pack $$$i$$$, such that $$$1 \leq i \leq N$$$, has $$$K_i$$$ stickers and costs $$$V_i$$$ reais.
In the store, the stickers are arranged on a shelf in order, and you have to choose an interval $$$[i, j]$$$ and buy all the packs from $$$i$$$ to $$$j$$$ (including $$$i$$$ and $$$j$$$). Since the stickers are highly sought after, you can only make one interval choice.
Little Biel is excited to fill his album; however, his family doesn't have much money. With that, he needs your help to spend as little as possible and complete the album. If there is no answer, you must inform Biel, preventing him from unnecessarily wasting money.
The first line contains the integers $$$N$$$ and $$$M$$$ $$$(1 \leq N,M \leq 2 \cdot 10^5)$$$, where $$$N$$$ is the number of packs and $$$M$$$ is the number of distinct stickers.
The next $$$N$$$ lines are formatted as:
Where $$$K_i$$$ $$$(1 \leq K_i \leq M)$$$ is the number of stickers in pack $$$i$$$ $$$(1 \leq i \leq N)$$$, $$$V_i$$$ $$$(1 \leq V_i \leq 10^9)$$$ is the price of pack $$$i$$$, and $$$F_{i,j}$$$ $$$(1 \leq F_{i,j} \leq M)$$$ is the identifier of the sticker.
Note that the same pack may contain duplicate stickers. And it's guaranteed that the sum of all the $$$K_i$$$ quantities of stickers from all the $$$N$$$ packs does not exceed $$$2 \cdot 10^5$$$.
Your program should print $$$-1$$$ if there is no valid interval. If there is, print two lines. The first one with the minimum total spent and the second with the values $$$i$$$ and $$$j$$$ of the chosen interval. In the event of multiple answers, print any of them.
4 5 1 2 5 2 4 1 5 3 5 4 2 1 2 1 3 1
10 2 4
4 5 1 1 5 2 1 1 5 2 1 2 1 2 1 3 1
-1
1 4 4 10 1 2 3 4
10 1 1
In the first example, we have $$$5$$$ distinct stickers (numbered from $$$1$$$ to $$$5$$$) and the following packs:
With the choice of packs in the interval $$$[2,4]$$$, Biel will pay a total of $$$4 + 5 + 1 = 10$$$ and will obtain all $$$5$$$ stickers. It can be shown that this is the least expensive choice to obtain all the stickers.
After participating in the MFP (Matchup of Finalists in Ping-pong) in Campinas, Giovana and Julia are tired of playing ping-pong and decide they need to devise a new sport. They want a sport that, besides physical performance, requires mathematical reasoning and strategy. As both are very fond of binary numbers, they thought of the following game, which they named "Bit Tennis", to play against each other:
Both quickly learned to play optimally and, after playing a few times, they noticed that the game's outcome is always determined before the first move is even made. Curious about this fact, they asked for your help to, given the initial string and number of turns, find out which one of them will win.
The first line of the input consists of the integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$, the size of the string $$$S$$$, and the integer $$$K$$$ $$$(1 \leq K \leq 10^5)$$$, the number of moves each one will make.
The second line contains the string $$$S$$$, which represents the binary number the game starts with, from the most significant bit to the least significant.
Print "GIOVANA" or "JULIA", the name of the winner of the game if both play optimally.
4 1 0111
GIOVANA
10 50 1011111101
JULIA
The traveling salesman Lex doesn't travel from city to city just because it's profitable to sell his exotic products in various different places. Most likely, due to the high availability of exotic items for sale on the Internet at very low prices, his business outcomes began to decline, and since then, Lex has been accumulating debts with loan sharks he meets in the cities.
With the help of an ancient technique taught by his ancestors, Lex has already solved the problem of visiting all the cities by making a route that goes through each of them only once. Now, Lex's problem is to return home while avoiding, as much as possible, the cities where he owes money.
Lex is currently in city $$$1$$$ and lives in city $$$N$$$. He knows exactly in which cities he has debts, and now he needs to find out which path he should take to avoid these cities as much as possible, and obviously, he wants to move as little as possible. Lex tried, but couldn't solve this problem, so he asked for your help.
The first line of the input contains three integers: the number of cities $$$N$$$ $$$(2 \le N \le 10^5)$$$, the number of roads connecting the cities $$$M$$$ $$$(1 \le M \le 10^5)$$$, and the number of cities where Lex owes money $$$D$$$ $$$(1 \le D \le N)$$$.
The second line follows with $$$D$$$ distinct integers, the cities $$$C_i$$$ $$$(1 \le C_i \le N)$$$ where Lex owes to loan sharks.
Then, there are $$$M$$$ distinct lines representing the roads connecting the cities, each one with the integers $$$U$$$ and $$$V$$$ $$$(1 \le U \lt V \le N)$$$, a road that connects the cities $$$U$$$ and $$$V$$$ in both directions.
It is guaranteed that there is a path between city $$$1$$$ and city $$$N$$$.
Print on a single line the minimum number of cities where Lex owes money that he will have to pass through on his way home, and the length of the shortest path to pass through this minimum number of cities.
8 11 4 3 5 6 7 1 2 1 3 1 4 5 6 4 5 3 6 2 7 7 8 6 8 3 4 3 8
1 2
8 9 5 1 7 2 5 4 1 2 1 5 2 5 3 4 4 8 5 8 6 7 3 5 2 3
2 2
Joãozão and Marcel are excited to practice weightlifting at the UDESC gym. The two of them take turns doing sets, where each set consists of exactly $$$M$$$ repetitions of the exercise. Marcel always starts. However, they have a peculiar way of counting the repetitions when they alternate: they count the total $$$N$$$ repetitions that both did, without counting individually how much each one did. Now, after spending a lot of time not knowing whose turn it is to exercise, they asked for your help.
Write a program that, given the total number of repetitions done so far and the number of exercises per set, says who is next to perform the exercise.
The input consists of two lines. The first line contains the integer $$$N$$$ $$$(0 \leq N \leq 10^{9})$$$ representing the repetitions done so far, and the second line contains the integer $$$M$$$ $$$(1 \leq M \leq 10^{9})$$$ representing the repetitions in each set.
Print "MARCEL" or "JOAOZAO", the name of the person whose turn it is to do the exercise.
10 3
JOAOZAO
6 8
MARCEL
20 1
MARCEL
In the first example, each person does 3 repetitions, so the sequence of 10 repetitions is:
Therefore, Joãozão is next to do the exercise, since he has not yet completed his current set of 3 exercises.
In the second example, Marcel did 6 out of his 8 repetitions, so he is still the next one to do the exercise.
The email application that Enzo developed during his college days has now become one of the largest in the world in the electronic mail field. Although some users have complained about the lack of basic features, such as deleting emails and spam checking, the app is still a hit, thanks to its "simplicity", according to Enzo himself.
Enzo's next task is to implement a password recovery system in case a user forgets their password. However, the internal workings of Enzo's email app are anything but "simple":
Enzo wants to create a program that, given a sequence of characters 'a' and 'b', retrieves the string of characters '0' and '1' that represents the user's original password, so he can send it directly to them via SMS (he didn't worry much about security, as long as it works). If it's not possible to retrieve the user's password due to corruption, the program should print ":(" to indicate there was a problem in the process.
However, as he's nearing retirement and has been spending most of his time watching Cruzeiro's soccer games, he's lost his touch and can't solve problems anymore. That's why he's asking for your help.
The first line of the input contains an integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$, the length of the encrypted password. The encrypted password of length $$$N$$$, made up only of characters 'a' and 'b', follows in the second line.
Print a string made up only of characters '0' and '1', the decrypted user password, or, print ":(" (without the quotes) if the password is corrupted.
5 ababa
01
9 ababaabab
0100
8 abababaa
:(
The "Festa Junina", a traditional celebration in Brazil, organized by BRUTE (Bureau for Realization of Unique and Triumphant Events), always features various notable personalities. In the 2023 edition, some of the attendees were acclaimed football players: Gasparinius Jr. and Karinen Sousa.
Upon seeing Gasparinius at the party, Karinen decides to pay a fee of R$ 2.00 to send him to "jail". The "jail" is a common game at Festas Juninas, but BRUTE came up with their own version. In it, whoever is jailed is kept in a locked room indefinitely and is only released when the bail is paid. This measure was necessary because the Bureau was out of budget for upcoming events after impulsively buying a sofa for their office.
Thus, Gasparinius was taken by the BRUTE guards to the jail, where he was eager to know the cost of his bail. The guards told him:
"The cost of your bail will be the cost of a sequence of exactly $$$N$$$ integers you present to us, being strictly ascending (each element is greater than the previous one) and only containing numbers greater than zero. The cost of a sequence is given by the sum of the costs of each of its elements. The cost of an element $$$x$$$ is determined by its binary representation, with each binary digit $$$i$$$ (corresponding to $$$2^i$$$) associated with a cost we call $$$C_i$$$, which will be added to the total if, and only if, the digit in that position is '1'. Again, the cost of the number $$$x$$$ will be the sum of the $$$C_i$$$ for all $$$i$$$ where the digit is '1' in the binary representation of $$$x$$$. We will give you $$$M$$$ cost values, which we guarantee will suffice for the binary representation of at least the $$$N$$$-th number."
Even though it wasn't a real jail, BRUTE is very strict about security and allows those jailed to make only one phone call. Gasparinius Jr. decides to use his call to contact you. Knowing your ability to solve problems like this, he asks you to write a program that calculates the lowest possible cost of a sequence to minimize his bail expenses.
The first line contains the integers $$$N$$$ $$$(1 \leq N \leq \min(2^M-1,100))$$$, the size of the sequence you should consider, and $$$M$$$ $$$(1 \le M \le 1000)$$$, the amount of costs associated with binary digits. The second line contains $$$M$$$ integers $$$C_i$$$ $$$(0 \leq i \lt M, 1 \le C_i \le 10^9)$$$ representing the cost of the binary digit $$$i$$$ for all elements of the sequence.
Print a single value, the minimum cost among all possible sequences of size $$$N$$$.
3 3 1 1 1
3
3 3 1 2 4
6
3 3 4 2 1
6
In the first example, the sequence $$$[1, 2, 4]$$$ has a total value of R$3.00.
In the second example, we can construct the sequence $$$[1, 2, 3]$$$, with a value of R$6.00.
Finally, the sequence $$$[2, 4, 6]$$$ results in the lowest value (R$6.00) for example 3.
The fearless explorer Eric is known for his countless adventures and has always been drawn to the unknown. From mysterious forests to towering mountains, he's faced them all. However, in a remote cave, he stumbled upon an object that promised an entirely new challenge: a magic lamp. Upon rubbing the dusty object, to his surprise, a genie emerged. But this was no ordinary genie. He didn't follow the standard rule of granting three wishes to whoever released him.
Instead, the genie was a fan of counting problems and posed a challenge to Eric: he showed Eric a series of opening and closing parentheses, but with a twist: some parentheses were replaced by '?'. With a sly smile, the genie proposed: "Eric, how many ways can you replace the ?'s with '(' or ')' such that the final sequence is balanced? That's the number of wishes you'll have from me."
A sequence of parentheses is considered balanced if it can be transformed into a valid mathematical expression by inserting only digits and operators between the parentheses. In other words, for every opening parenthesis, there must be a corresponding closing parenthesis in the correct order. For instance, "()()" and "(())()" are balanced sequences, but "())(" or "((()()" are not.
Eric needs to calculate how many wishes he has at his disposal by replacing '?' with '(' or ')' such that the resulting sequence is balanced, help him with this task. As this number of wishes can be quite large, print the remainder of the division of this number by $$$10^9+7$$$.
The first line of the input contains an integer $$$N$$$ $$$(1 \le N \le 3000)$$$, the length of the parenthesis sequence.
The second line is the sequence of parentheses with some (possibly none, possibly all) characters turned into '?' by the genie.
Print on a single line the number of wishes Eric can make to the genie modulo $$$10^9+7$$$.
4 ()(?
1
10 ()??(??)??
6
8 ????????
14
6 (?()??
2
One evening, Eduardo was feeling hungry and decided to order a delivery of his favorite food: Shawarma. Upon opening the delivery app and selecting his favorite restaurant, Eduardo noticed a new intriguing option on the menu: the Hawarma. Although it seemed like a typo, he found out that it was a legitimate option. In the item's description, the restaurant had written: "Order the Hawarma, if you can." Curious, Eduardo continued, provided the delivery address, selected the payment method, and when everything seemed to be going smoothly, he encountered the following message:
Determine all values $$$a$$$ for which $$$f(a) = a$$$
The truth is that, at this point, most people look and think "What a prank!" and end up ordering something else. But not Eduardo: motivated by the challenge and curiosity, he won't give up on the Hawarma. Suppose you are Eduardo, inform how many values satisfy the condition for a certain value of $$$N$$$ and what those values are.
The input consists of a single line containing an integer $$$N$$$ $$$(-300 \le N \le 300, N \ne 0)$$$.
The output should consist of two lines. Print on the first line the quantity $$$K$$$ of values that satisfy the condition. On the second line, print the $$$K$$$ values separated by spaces. You may print the values in any order. It is guaranteed that the quantity of values that satisfy the condition for a given value of $$$N$$$ does not exceed $$$10^4$$$.
3
3 -15 0 6
In the example, we have $$$N = 3$$$, so our function $$$f$$$ is:
We have $$$K=3$$$ values of $$$a$$$ such that $$$f(a)=a$$$. They are:
You are working on DJ software and need to simulate a virtual turntable. A vinyl disc is displayed on the screen, and the user can use mouse movements to make the disc move forward or backward. The simulated vinyl disc spins at $$$33+\frac{1}{3}$$$ RPM (rotations per minute) in a clockwise direction. The user can perform a drag-and-drop motion from any position on the disc to any other position. For instance, if the user initiates a movement from the bottom of the disc and goes upwards and to the right, the disc should rewind:
We aim to approximate the real world by considering only the angle formed by the two positions relative to the center of the disc. Note that there are two angles for any two starting and ending positions, and the program should use the smaller angle to determine how much the disc has rotated. If the user attempts a movement that starts or ends outside the disc, the disc will not be moved.
Mouse positions are given in the first quadrant of the Cartesian plane (meaning the position $$$(0, 0)$$$ is at the lower-left corner), and the disc is scaled on the screen from position $$$(0, 0)$$$ to position $$$(D, D)$$$. So, given the disc's size on the screen and the initial and final mouse positions during a drag-and-drop operation, determine how many seconds of music should be fast-forwarded or rewound.
The first line of input contains an integer $$$D$$$ $$$(1 \le D \le 10^4)$$$, the diameter of the vinyl disc on the screen. The second line provides the coordinates when the mouse button was pressed, the integers $$$I_X$$$ and $$$I_Y$$$ $$$(0 \le I_X, I_Y \le D)$$$. Finally, the coordinates when the mouse button was released are given on the third line, the integers $$$F_X$$$ and $$$F_Y$$$ $$$(0 \le F_X, F_Y \le D)$$$.
It is guaranteed that the mouse movement never passes through the center of the disc and that the angle formed between the two positions is greater than 0.
Print on a single line the number of seconds the music should move forward (positive) or backward (negative) using the drag-and-drop mouse operation. Your answer will be accepted if it has an absolute or relative error $$$\leq 10^{-4}$$$
100 55 20 80 50
-0.402688
36 18 0 0 18
0.45
100 0 0 1 0
0
100 30 25 10 65
0.359481
Fernando is an avid party game player, as they are a great way to liven up social gatherings and facilitate interaction among participants. Many party games involve alternating turns among several players, with each person taking their turn. Therefore, when people want to play a party game, they need to decide on the order of players, which is usually resolved through some playful method that generates a random outcome. Among these decision-making games, Fernando's favorite is the game of "even or odd".
However, the math enthusiasts among the group are never satisfied with this decision method. When they show up at parties (which is rare), they can't help but complain about the lack of fairness in various methods. Even though Fernando and his friends enjoy playing party games just for fun, they decided to listen to the mathematicians' suggestions to achieve a more uniform outcome. They defined some requirements for a method to be truly fair:
Note that it's possible for a method to uniformly determine each player's position, but not all permutations may have the same probability of occurring. One of the mathematicians' favorite methods of random selection is using dice, so they created sets of dice that satisfy some of these properties.
Each of the $$$N$$$ players receives a die identified by a letter of the alphabet, and each number from $$$1$$$ to $$$M$$$ appears on only one die. Thus, each player rolls their own die, and the order of the numbers rolled on the dice is used as the order of the players. The player with the highest-numbered die goes first, the one with the second-highest value goes second, and so on.
A set of dice is described by a string of $$$M$$$ letters, where each position assigns the value of the position index to one of the dice, and the dice are represented by the first $$$N$$$ letters of the lowercase Latin alphabet. For example, the set of dice dcbabccccbabcddddcbabccccbabcd satisfies the fairness property for 4 players:
Well... Fernando and I were also hoping that the dice would at least be of the same size. Apparently not, but anyway. Now, you're curious and want to know if a given set of dice satisfies both position fairness and permutation fairness. To determine that, you need to calculate the probability of each player obtaining each position and the probability of each permutation.
The first line of input contains the integer $$$N$$$ $$$(1 \le N \le 7)$$$, the number of players and dice, and the integer $$$M$$$ $$$(N \le M \le 600)$$$, the number of values to be placed on the dice.
The second line of input contains the set of dice $$$D$$$ with $$$|D| = M$$$. The only allowed characters are the first $$$N$$$ lowercase Latin alphabet letters, and it is guaranteed that the letters appear at least once.
Print $$$N$$$ lines, each describing player $$$i$$$ $$$(1 \le i \le N)$$$, the one who uses the die corresponding to the $$$i$$$-th letter of the Latin alphabet. The lines should consist of $$$N$$$ integers $$$P_{ij}$$$ $$$(1 \le j \le N)$$$, where $$$P_{ij}$$$ is the probability that player $$$i$$$ is in position $$$j$$$ modulo $$$10^9 + 7$$$.
Next, print on a line 'S' if the set of dice has permutation fairness, or 'N' if it doesn't. Finally, print on another line the product of the probabilities of obtaining a specific permutation out of all possible permutations modulo $$$10^9 + 7$$$.
To print a probability $$$\frac{p}{q}$$$, print $$$p \cdot q^{-1} \pmod{10^9+7}$$$. It is proven that $$$q^{-1}$$$ exists for any $$$q$$$ and is unique modulo $$$10^9+7$$$.
4 30 dcbabccccbabcddddcbabccccbabcd
250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 250000002 S 440369483
3 4 abca
500000004 0 500000004 0 500000004 500000004 500000004 500000004 0 N 0
In the first example, all players have the same probability of ending up in any position, which is $$$\frac{1}{4}$$$. Thus, the answer for all positions of all players is the same, $$$4^{-1} = 250000002 \pmod{10^9+7}$$$. All permutations have the same probability of $$$\frac{1}{24}$$$, and the product of the probabilities of all $$$24$$$ possible permutations is $$$\frac{1}{24^{24}}$$$, which is $$$24^{-24} = 440369483 \pmod{10^9+7}$$$.
In the second example, player $$$1$$$ using die a has a $$$\frac{1}{2}$$$ chance of being the first to play (by rolling a 4) and a $$$\frac{1}{2}$$$ chance of being the last to play (by rolling a 1). The other two players have dice with only one face, and their positions depend solely on player $$$1$$$'s die. Player $$$2$$$ with die b is either second or third, and player $$$3$$$ with die c is either first or second. Since there are only two possible permutations of player order, the product of the probabilities of all possible permutations is zero, and this is not a set of dice with permutation fairness.
After disagreements with former team members, Guilherme, Igor, Pedro, and Victor have just recruited Thomas to their e-sports team focused on playing Balloorant. In this game, two teams of five people face each other, one as attackers and the other as defenders. The goal of the attackers is to pop all of the defenders' balloons, while the defenders try to gather as many balloons as possible in a 5-hour programming contest.
While playing a match with Thomas, the other team members became frustrated as they realized he doesn't understand the communication system used by the others. They communicate all of their strategies in the game's voice chat using Knock Code.
Knock Code is a code where each of the 26 letters of the alphabet is represented by a pair of numbers $$$(i,j)$$$ that indicate the position (row, column) of the letter in the 5x5 code matrix. In order to have 25 positions instead of 26, the letters C and K are represented by the same pair of numbers. The pairs of numbers are communicated through knocks (on a table, for example, in a way that can be picked up by the game's microphone). To communicate the number $$$X$$$, $$$X$$$ consecutive knocks are made without pauses. To communicate more than one number, pauses are made between consecutive knocks. We will represent a knock as an asterisk (*) and a pause (the time between sequences of consecutive knocks) as a space ( ).
| 1 | 2 | 3 | 4 | 5 | |
| 1 | A | B | C/K | D | E |
| 2 | F | G | H | I | J |
| 3 | L | M | N | O | P |
| 4 | Q | R | S | T | U |
| 5 | V | W | X | Y | Z |
For example, encoding "NTJ":
"N" is at position (3,3), therefore it is represented by: "*** ***".
"T" is at position (4,4), therefore it is represented by: "**** ****".
"J" is at position (2,5), therefore it is represented by: "** *****".
Thus, the entire encoded word is represented by: "*** *** **** **** ** *****".
Now, the team asks for your help in supporting Thomas in learning the code to be able to communicate with the rest of the team. For this, he needs you to write a program that takes a string representing the message to be communicated and encodes it into Knock Code.
The first line of input contains an integer $$$N$$$ $$$(1 \le N \le 10^4)$$$, the size of the string. The string $$$S$$$ of size $$$N$$$, composed only of uppercase Latin letters, follows in the second line.
Print the encoding of $$$S$$$ in Knock Code on a single line, using an asterisk to represent a knock and a space to represent a pause.
3 NTJ
*** *** **** **** ** *****
4 CTSJ
* *** **** **** **** *** ** *****
2 OK
*** **** * ***
You are the attendant of the best coffee shop in the world: Le Café (a French franchise). One day, near closing time, three students, Malu, Débora, and Lívia, enter the shop and get ready to place their orders. Malu, as she doesn't like coffee, orders only a brownie (world-renowned for being cheap and delicious). Débora and Lívia, on the other hand, order the Vanille Glacée, a mixture of coffee, vanilla essence, milk, and most importantly: SPRINKLES.
After ordering their drinks on the table's tablet, Débora and Lívia approach your counter and make an unusual demand: "We will only accept our Vanille Glacée if both have the exact same number of sprinkles, and that number is greater than zero. If not, cancel our order." After that, the two turn around and hurry back to their table. You, confused, open the sprinkle cabinet and see $$$N$$$ packages, fearing that you won't be able to fulfill the order. Like anyone in such a situation would do, you chat nicely with the two friends to try to reach a consensus you open your notebook and start programming a solution.
Note that each package can be used exactly once, and due to Le Café's policies, a package must be used entirely, and all the sprinkles must go into the same Vanille Glacée. The justification is that this prevents packages from being open for too long, thus affecting the texture of the sprinkles. Therefore, given the quantity of sprinkles contained in each of the packages, inform whether you will be able to serve Débora and Lívia's Vanille Glacée.
The first line of input contains the integer $$$N$$$ $$$(1 \le N \le 2 \cdot 10^5)$$$, the number of sprinkle packages. The following line contains $$$N$$$ integers $$$A_i$$$ $$$(1 \le A_i \le 2 \cdot 10^5)$$$, each representing the quantity of sprinkles in package $$$i$$$.
Print 'S' on a single line if it is possible to serve the Vanille Glacée, or 'N' otherwise.
4 1 2 3 4
S
1 100
N
In the first example, the answer is 'S' as we can use the packages with $$$1$$$ and $$$4$$$ sprinkles in Débora's Vanille Glacée and the packages with $$$2$$$ and $$$3$$$ sprinkles in Lívia's coffee, resulting in both having 5 sprinkles. Another way would be to use the packages with $$$1$$$ and $$$2$$$ sprinkles in Débora's coffee and the package with $$$3$$$ sprinkles in Lívia's, resulting in both having 3 sprinkles.
In the second example, the answer is 'N' as there is only a single package of sprinkles available, and we cannot have the Vanille Glacée without any sprinkles. Therefore, if we decide to use the only package in Débora's coffee, it would have $$$100$$$ sprinkles while Lívia's would have none, and vice versa.
The mayor is trying to cut costs in the city, and one of his latest ideas is to use less powerful light bulbs in the lampposts. After all, each lamppost is wasting energy if its light bulb illuminates more than necessary! Of course, if the distance between the lampposts were uniform, the calculation would be simple. However, since the mayor also cut costs when placing the lampposts, they are in completely arbitrary positions on the city streets.
However, the mayor knows about economies of scale, so he wants to order all the light bulbs with the same power, the minimum needed to illuminate everything. We define the power of a light bulb as the distance it illuminates to the left and right. Now, the city's electricity department has approached you. Given the positions of the lampposts on the street, what power is needed in the light bulbs to illuminate the entire street?
The first line contains the integers $$$N$$$ $$$(1 \le N \le 2\cdot10^5)$$$, the length of the street in meters, and $$$M$$$ $$$(1 \le M \le N + 1)$$$, the number of lampposts.
Following that, there are $$$M$$$ distinct integers on a single line, the positions of the lampposts $$$P_i$$$ $$$(0 \le P_i \le N)$$$ on the street, in meters, sorted from smallest to largest (i.e., $$$P_i \lt P_j$$$ if $$$i \lt j$$$). The length of the mayor's city streets starts at 0 and ends at $$$N$$$.
Print a single integer, the power that the light bulbs in the lampposts must have to illuminate the entire street.
20 5 1 5 9 15 18
3
5 1 1
4
10 2 2 9
4
After completing a 42-kilometer run in the XXVII Campo Grande Marathon, Granza, Joãozinho, and Machado were exhausted but were celebrating their 12th-place finish for their team. This achievement marked a special moment in UDESC's history, as it was their first time receiving a medal in an ICPC (Institute of Circuit Performance Competition) competition. However, as they crossed the finish line, a new rule was announced by the event organizers: only the top-performing teams would receive medals, provided they participated in the activity organized by BRUTE (Building Runners' Universal Trading Experience), the event's sponsor.
The activity involved the youngest team member, in this case, Machado, playing a game based on the classic Nim game against an employee named Cartinha from the BRUTE company. Cartinha was instructed to play optimally. Only teams that managed to defeat Cartinha would be awarded medals. The rules were explained by BRUTE on the event day as follows:
Given values $$$A$$$, $$$B$$$, and $$$K$$$, determine whether Machado can secure the medal for the team or not.
The input consists of a single line containing the integers $$$A$$$, $$$B$$$, and $$$K$$$ $$$(1 \le A, B, K \le 10^7)$$$.
Print "S" on a single line if it's possible for Machado to win the medal, and "N" if it's not.
3 2 6
S
6 5 20
S
2 2 1
N
In the first example, the game starts with $$$2 \cdot 3 = 6$$$ stones, and since $$$K = 6$$$, Machado wins the medal.
In the second example, the game starts with $$$30$$$ stones and Machado can remove $$$6 \cdot 2 = 12$$$ stones (leaving the pile with $$$18$$$) to secure the medal.
Léo and Emanuel are ready to travel to Rio de Janeiro to watch the next football match Vasco da Gama will play, going from Joinville to Rio through the BR-101 highway. During the trip, Emanuel wondered why it was taking so long to reach the destination. They stopped to look at the map and realized they had taken the wrong route, driving in the opposite direction! They immediately stopped and turned around, returning to the correct path. Now, they want to know how many kilometers they will have traveled in total after reaching their destination. However, since they are on the road, they sent you a message asking you to write a program to calculate this for them.
Given the distance that the friends traveled in the wrong direction and the distance from the football stadium to their starting point, provide the total value, in kilometers, that the two will have traveled when they reach their destination.
The input consists of two lines, each containing a single integer value in kilometers.
The first line contains the distance $$$A$$$ $$$(1 \le A \le 10^6)$$$ that Léo and Emanuel traveled in the wrong direction. The second line contains the distance $$$B$$$ $$$(1 \le B \le 10^6)$$$ between their starting point and the destination.
Print a single integer, the answer to Léo and Emanuel's request, in kilometers.
4 2
10
5 7
17
2 4
8
1 10
12