Rodingo "Cria", the god of Creation, has invited the demigods Renang and Wan to spend their break on Mount Olympus. The two of them love fruits, so they will visit the $$$t$$$ markets of this Greek region, known for their high-quality kakis, plantains and other delicacies.
When Renang and Wan enter a market, they visit each of the $$$n$$$ selling points inside this market and buy exactly one packet of fruits from each selling point. All sellers in the market sell their fruits in packets with different numbers of fruits which are sorted in increasing order on their tables.
After leaving the market, to satisfy a whim from Rodingo, Renang and Wan want to open their packets and distribute all their fruits between them in such a way that they are left with the same number of fruits each after the distribution.
However, none of our character is very good with calculations. Therefore, you must help them decide whether or not, for each visited market, they can or cannot accomplish Rodingo's whim.
The first line of input is an integer $$$t$$$ ($$$1 \leq t \leq 100$$$), the number of markets on Mount Olympus. The markets are then described.
The first line of each market's description is an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$), the number of selling points in the market. The selling points are then described.
The first line of each selling point's description is the number $$$m$$$ ($$$1 \leq m \leq 10^5$$$) of packets available there. The second line of each selling point's description contains $$$m$$$ distinct positive integers $$$a_1 \lt a_2 \lt \dots \lt a_m$$$ ($$$1 \leq a_j \leq 10^9$$$, for $$$j = 1,2,\dots, m$$$), separated by spaces, where $$$a_i$$$ is the number of fruits inside the $$$i$$$-th packet over this selling point's table.
It is guaranteed that the sum of the number of packets in all markets is at most $$$10^5$$$.
For each market, output in a single line "SIM" (without quotes) if Renang and Wan can buy and distribute the fruits to accomplish their task or "NAO" (without quotes) if they cannot.
221122 4132 5 8
NAO SIM
There are $$$2$$$ markets.
In the first market, there are $$$2$$$ selling points: the first one sells $$$1$$$ packet with $$$1$$$ fruit and the second one sells $$$2$$$ packets with $$$2$$$ and $$$4$$$ fruits, respectively. It can be proven that, no matter how Renang and Wan buy the two packets their task is impossible.
In the second market, there is only $$$1$$$ selling point, selling packages with $$$2$$$, $$$5$$$ and $$$8$$$ fruits, respectively. Renang and Wan may satisfy Rodingo's whim (for example by buing the packet with $$$8$$$ fruits and each of them will be left with $$$4$$$ fruits after the distribution).
Byakronos was organizing the first marathon contest. However, near the beginning of the competition, he realized that there weren't enough balloons!
Because of this, Byakronos sent Mori to get balloons from the MaratonUSP's carriage. Fortunately, Mori came across the shop of the God Helios, which sells 'quantum' balloons. So, Mori bought inflated balloons (to save time!) of $$$N$$$ colors, where $$$b_i$$$ balloons of color $$$i$$$ $$$(1 \leq i \leq N)$$$ were purchased.
When Mori loaded the balloons onto the truck, he realized that the carriage could hold a maximum of $$$S$$$ inflated balloons. Thus, Mori needs to deflate balloons so that there are at most $$$S$$$ inflated balloons left.
As the balloons are quantum, they only deflate if Mori looks at them. Furthermore, the inflated balloons follow the rules of radioactive decay, with a half-life of $$$1$$$ second. In other words, every $$$1$$$ second Mori looks at $$$x$$$ inflated balloons, $$$\left \lfloor \frac{x}{2} \right\rfloor$$$ will still be inflated at the end of that second.
Therefore, to deflate the balloons, Mori will choose a color $$$i$$$ every second and look at balloons of that color for exactly $$$1$$$ second (if Mori were to look at more than one color, he'd lose track!).
Clearly, looking at quantum balloons for too long is not healthy. So, Mori wonders, what is the minimum number of seconds needed for at most $$$S$$$ inflated balloons to remain?
Input consists of 2 lines.
The first line contains two integers $$$N, S$$$ ($$$1 \leq N \leq 10^5, 0 \leq S \leq 10^9$$$) separated by a space - representing the number of balloon colors and the maximum number of inflated balloons the truck can hold, respectively.
The second line contains $$$N$$$ integers $$$b_1, b_2, \dots, b_N$$$ $$$(1 \leq b_i \leq 10^9)$$$ - representing the quantity of balloons of each color purchased.
Print an integer, the minimum number of seconds needed for there to be at most $$$S$$$ inflated balloons remaining.
2 5 3 5
1
5 0 1 1 1 1 1
5
The members of MaratonUSP were invited by the god Zeos to visit Mount Olympus. May, knowing about the legendary banquets that take place there, quickly agreed.
After a long stroll through the fields of Caieffes, the MaratonUSP members were invited to a banquet. However, to the surprise of almost everyone, the banquet consisted only of cheese balls and coxinhas! Secretly, Thilio, the finicky one, told the gods that this was the only food that MaratonUSP members liked, so he wouldn't have to deal with any ancient Greek food.
May was revolted because she hates coxinhas. The gods served the snacks on a table, organized in $$$n$$$ rows and $$$m$$$ columns. Since May still wants to visit more places before returning to IME, she doesn't have time to feast with her colleagues. She decided to go to the snack table and take all the snacks from a rectangular subsection of the table at once. To make it easier, she will select a rectangular subsection of the table (that is, a contiguous subset of rows and columns) and take all the snacks from this subsection. The following image shows some valid choices for the third test case.
Help May discover the maximum number of cheese balls she can take in this way without taking any coxinhas.
The first line contains two positive integers $$$n$$$ and $$$m$$$ separated by a space, the dimensions of the snack table. It is guaranteed that $$$n \times m \leq 400$$$.
The following $$$n$$$ lines contain $$$m$$$ numbers $$$a_{i, j} \in \{0, 1\}$$$ separated by spaces. If $$$a_{i, j} = 0$$$, it indicates that the snack in row $$$i$$$ and column $$$j$$$ is a coxinha. If $$$a_{i, j} = 1$$$, it's a cheese ball.
An integer, the maximum number of cheese balls that May can take.
2 2 1 1 1 1
4
4 4 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1
4
3 3 1 0 1 0 1 1 0 1 1
4
For the first example, May can select columns 1-2 and rows 1-2.
For the second example, May has several options:
Henrique and Juliana are a sertanejo duo from Panteão Olímpico Lírico dos Imortais (POLI), which goal was to create divine music to honor the gods. The score of a divine music is a sequence of notes represented by only the numbers 0, 1 and 2. Also, it is such that the sum of every three consecutive numbers is equal to 3.
Nowadays, an old score of the famous duo was found, but some of its notes were blurred. Hence, Pedro, the musician, was commissioned to recover the original score. Pedro is afraid that this work may not be possible: it could exist more than one divine music score such that, if some of their notes were blurred, would be equal to the found score.
Tormented by that possibility, Pedro asks you to count the number of distinct divine music scores that could be the one originally written by the sertanejo duo. Notice that the answer to this question could be 0.
The first line of the input has only one integer $$$n$$$ ($$$3 \leq n \leq 10^6$$$), the number of notes in the score.
The second line contains $$$n$$$ integers $$$d_i$$$ ($$$-1 \leq d_i \leq 2$$$ for every $$$1 \leq i \leq n$$$), the notes of the score. The integer -1 represents a blurred note.
Print one integer: the number of distinct divine music scores that could be the one originally written by Henrique and Juliana.
5 0 -1 1 -1 2
1
5 -1 -1 2 -1 -1
2
Otávio, the archaeologist, was about to enter the archaeological site where he is currently conducting his research when he was stopped by the sphinx known as Matheusphinx.
In order to pass and continue his research, Otávio would need to answer the sphinx's riddle. This time, Matheusphinx asked a simple question: 'What percentage of statistics are false?'
The question caught Otávio off guard, and he immediately answered '75%', which was completely incorrect. Fortunately, sphinxes work retroactively, meaning that if for some reason this answer becomes correct, the sphinx will grant passage to Otávio.
Otávio has spent his entire life studying archaeology, so he knows the exact number of true statistics $$$v$$$ and the number of false statistics $$$f$$$.
Another thing Otávio learned in his research is that proclaiming the phrase 'More than 75% of the statistics are false' counts as a statistic and changes the number of true or false statistics according to $$$v$$$ or $$$f$$$. If $$$\frac{f}{v + f} \gt 75\%$$$ and this phrase is proclaimed, it is true, and therefore the value of $$$v$$$ increases by $$$1$$$. Otherwise, the value of $$$f$$$ would increase by $$$1$$$.
Otávio needs to get back to work and has asked for your help to write a program that, given the number of true statistics $$$v$$$ and the number of false statistics $$$f$$$, shows him how many times the phrase 'More than 75% of the statistics are false' needs to be used so that exactly 75% of the statistics will then be false.
The input contains multiple test cases.
The first line of the input contains a number $$$1 \leq t \leq 10^5$$$, the number of test cases.
Each of the next $$$t$$$ lines contains two numbers $$$v$$$ and $$$f$$$ ($$$0 \leq v, f \leq 10^8$$$), the number of true statistics and the number of false statistics, respectively. It is guaranteed that $$$v + f \gt 0$$$ and that $$$\frac{f}{v + f} \neq 0.75$$$.
The output should contain $$$t$$$ numbers, one for each test case. The $$$i$$$-th number should be the number of times Otávio needs to say "More than 75% of the statistics are false" so that exactly 75% of the statistics are false in the $$$i$$$-th test case.
5 1 0 1 2 1 5 1 6 0 1
3 1 2 1 3
In the quest for adoration and ego enhancement, the gods of Olympus organize an election on Earth every 100 years to determine the most adored god by humans. In this edition, $$$m$$$ deities, including Byakronos, Marceloki, and Zeos, the favorites, are competing for the title. Only a few randomly selected individuals are invited to vote.
The prophet Kobus, a fervent follower of Zeos, is determined to secure his victory. She possesses privileged knowledge about the voters and knows exactly how many votes each god has received up to the moment. For the $$$i$$$-th god, she has information that they have received the partial quantity of votes $$$a_i$$$.
However, Kobus needs your help to determine the minimum quantity $$$t$$$ of votes she must purchase to ensure Zeos' victory. In other words, Zeos must have more votes than any other deity in the competition. It is important to note that Zeos is the first god on the list provided by Kobus and that when she buys a vote, it is taken from another god and transferred to Zeos.
The first line contains an integer $$$m$$$ ($$$3 \leq m \leq 2 \cdot 10^5$$$) - the number of gods competing for the title.
The second line provides $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \leq a_i \leq 10^9$$$) - where $$$a_i$$$ indicates how many humans voted for the $$$i$$$-th god.
The output should be a single integer $$$t$$$ indicating the minimum number of votes that Kobus needs to buy.
3 1 1 7
4
3 1 2 6
3
6 2 4 2 5 6 5
4
In the first example, it can be proven that $$$3$$$ votes are not enough since, regardless of how Kobus buys them, the third candidate would still have more votes than Zeos.
On the other hand, if she buys $$$4$$$ votes from the third candidate for Zeos, he would have $$$5$$$ voters (while the third candidate has only $$$3$$$).
The ancient and bustling city of Cnossos was renowned for its mysterious labyrinth, composed of a set of $$$N \times M$$$ square rooms arranged in an $$$N$$$ by $$$M$$$ grid. The rooms were named by an ordered pair $$$(A,B)$$$, where $$$A$$$ represented the row and $$$B$$$ represented the column in which the room was located. The entrance to the labyrinth was at position $$$(1,1)$$$.
In this city, there was a fearless adventurer named Gusteseu. He was known for his courage and skill in unraveling the most complex riddles.
One day, Gusteseu received an extraordinary mission: to explore the labyrinth and find a legendary treasure rumored to be hidden in its depths. However, there was a daunting challenge in Gusteseu's path. The labyrinth was inhabited by a creature feared by all: the mighty Maynotauro.
The Maynotauro, a creature with the body of a woman and the head of a bull, guarded the labyrinth's entrance and protected the path to the treasure. Its dwelling was known as the Maynotauro's room, located at position $$$(X,Y)$$$ in the labyrinth.
Determined to complete his mission, Gusteseu knew he had to avoid the Maynotauro's room. He understood that passing through that room would result in his capture and failure in the quest for the treasure.
Due to the unpleasant conditions within the labyrinth, Gusteseu aimed to reach the treasure room as efficiently as possible, passing through the fewest number of rooms. He disregarded any other ways of achieving this path.
With his sharp mind and expertise in competitive programming, Gusteseu decided to employ his skills to calculate the number of efficient ways to reach the treasure room, located at position $$$(N,M)$$$, without passing through the Maynotauro's room.
The input consists of a single line with four integers separated by spaces: $$$N$$$, $$$M$$$ ($$$1 \leq N, M \leq 30$$$), $$$X$$$ ($$$1 \leq X \leq N$$$), and $$$Y$$$ ($$$1 \leq Y \leq M$$$).
$$$N$$$ and $$$M$$$ indicate the size of the labyrinth and the position $$$(N,M)$$$ of the treasure room.
$$$X$$$ and $$$Y$$$ indicate the position $$$(X,Y)$$$ of the Maynotauro's room.
Print a single number indicating the number of distinct efficient ways to reach the treasure room as calculated by Gusteseu.
2 3 2 2
1
4 4 3 2
11
30 30 15 15
23844478996709040
Example of test case 1:
There is only one valid way, which is highlighted.
According to historical evidence, it is believed that in ancient Nlogonia, all citizens lived in peace and harmony, confident that they were protected from any enemy thanks to a powerful hero: Morethor. The god Hadesoko, known for his terrifying monsters, constantly sought to torment humanity, but our hero prevented his evil deeds. However, recent discoveries point to a period of darkness: after Morethor's encounter with the god Promethilio, our hero went missing for a long time, allowing Hadesoko to invade the lands of our ancestors. We know that Morethor reappeared at some point in the past and immediately began hunting the monsters sent by Hadesoko and facing them in the order they were encountered. However, despite the collected data, researchers have not yet been able to conclude whether Morethor defeated all the forces of evil or if he failed in his mission. Thus, they have asked for your help to evaluate the data and resolve this great doubt!
Given Morethor's ability $$$H$$$ right after his return, determine if he is capable of facing all $$$N$$$ monsters from Hadesoko. The $$$i$$$-th encountered monster has a strength $$$F_i$$$. Morethor faces only one monster at a time and is able to defeat it if his current ability is greater than or equal to the monster's strength. If our hero wins the battle, he acquires the strength of his opponent (meaning he adds the monster's strength to his ability). Otherwise, he is defeated.
The first line contains an integer $$$N$$$ ($$$0 \le N \le 10^5$$$) and an integer $$$H$$$ ($$$0 \le H \le 10^4$$$) — the number of monsters and the hero's initial ability, respectively.
The second line contains $$$N$$$ integers $$$F_i$$$ ($$$0 \le F_i \le 10^4$$$) — the $$$i$$$-th monster's strength.
Print "SIM" (without quotes) if the hero is able to fight all the monsters, and "NAO" (without quotes) otherwise.
5 10 1 2 3 4 5
SIM
4 1 1 2 4 8
SIM
4 7 1 1 1 11
NAO
In the second example, the hero starts with an ability of 1, being capable of defeating the first monster and increasing his ability to 2. In the second battle, he is also able to defeat the monster and his ability becomes 4. The same happens in the third and fourth battles, with our hero being able to face all the monsters.
Before we start telling this magnificent tale, we need a few definitions:
Now we shall tell the story of the origin of competitive programming among humans. Legend has it that thousands of years ago, in ancient Nlogonia, the god Rárada constantly invented new problems and algorithms to solve them, sharing these ideas among the gods. It is known that the gods used very few words when communicating with each other, more specifically, the deities only used words from the set $$$U =$$$ {AC, AMOR, BRASILEIRO, CAVALO, MARATONUSP, OSSO, OVO, PATA, RARADA, TLE, VOO}; do not question why they chose these words, and, yes, the gods from Nlogonia spoke portuguese. Among these gods was Promethilio, who, amazed by these new ideas, believed that this knowledge should be passed on to humans. However, fearing that humans would become too powerful, he didn't convey exactly the same message as Rárada. Every time Promethilio heard a phrase $$$T \in U*$$$ from Rárada, he would choose a permutation $$$\mathcal{P}$$$ and send the text $$$\mathcal{P}(T)$$$ to the hero Morethor (perhaps you've heard of him in another question). Morethor would then transcribe the phrase $$$\mathcal{P}(T)$$$ onto stone tablets with the aim of disseminating these ideas and preserving competitive programming knowledge forever.
Otávio, the archaeologist, has found a stone tablet with a text $$$S$$$ and is extremely excited about the possibility of having discovered one of the ancient tablets written by Morethor containing Rárada's foundational ideas. He now needs your help to decide whether he has truly found a historical relic or just an ordinary text.
The input consists of two lines. The first line contains an integer $$$N$$$. The second line contains the text $$$S$$$ written on the tablet. The text contains exactly $$$N$$$ words and $$$1 \leq |S| \leq 10^6$$$, meaning the text has between 1 and 1000000 characters. All characters are uppercase letters or whitespace. All words are separated by exactly one space.
If there exists a text $$$T \in U*$$$ and a permutation $$$\mathcal{P}$$$ such that $$$\mathcal{P}(T) = S$$$, the output should consist of two lines: the first line should print "Y", and the second line should contain the permutation $$$\mathcal{P}$$$ in the format "$$$\mathcal{P}[1]\mathcal{P}[2] ... \mathcal{P}[26]$$$". If for any text $$$T \in U*$$$ and any permutation $$$\mathcal{P}$$$ we have $$$\mathcal{P}(T) \neq S$$$, then the output should be a single line containing "N".
3 NBSBUPOVTQ PWP BD
Y BCDEFGHIJKLMNOPQRSTUVWXYZA
2 BD CMOR
N
6 PSDETVXTSQ DHQS SDSDRD QEEQ ADKD DG
Y DPGRXBCFTIJVHLQAMSEKNOUWYZ
2 OSSO PATA
Y ABCDEFGHIJKLMNOPQRSTUVWXYZ
In the first test case, the phrase spoken by Rárada was MARATONUSP OVO AC. In the second test case, there is no permutation that would lead a phrase spoken by Rárada to the input text. In the third test case, the phrase spoken by Rárada was BRASILEIRO AMOR RARADA OSSO PATA AC.
For the positive cases, note that multiple permutations could be accepted as an answer.
On special occasions, the gods meet at the university restaurant for a joyful feast. Anthena always invites Nathena to such feasts, but Nathena often refuses to join arrogantly.
As his presence at the university restaurant is so extremely rare, legends tell that, since Nathena emerged from Zeos' head, he has only recharged his university restaurant credit balance once. It is known that one can buy at most 200 drachmas (yes, the gods still use this currency) worth of credit at once. It's also known that each meal at the university restaurant costs exactly two drachmas.
Knowing how many drachmas worth of credit Nathena bought on his recharge and his current credit balance, discover how many times he has feasted at the university restaurant.
The input consists of a single line with two integers $$$x$$$ and $$$y$$$ separated by a space, the value in drachmas of Nathena's refill and his current balance, respectively. It's guaranteed that $$$0 \leq y \leq x \leq 200$$$ and that both $$$x$$$ and $$$y$$$ are of the same parity.
The output should contain a single integer, representing the number of times Nathena feasted at the university restaurant.
50 34
8
131 47
42