IX MaratonUSP Freshman Contest
A. Arc surveillance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After years of investigation and pursuit, the fugitive Miguelez, accused of high treason against USP (Union of Solar Planets), was captured by the famous space detective Morete. Due to the gravity of his crime, he was sent to the maximum-security prison on Neptune, which employs the panoptic system: all 360 cells of the complex are arranged along a circle, numbered from 1 to 360, with the watchtower located at the center of this circle, allowing the prison guard to see all the cells.

Detective Morete is concerned that Miguelez may plot an escape, so he wants to enhance surveillance of the prison cells by installing a new set of cameras in the watchtower, which will cover a single contiguous interval of cells. Morete has access to the record of which cells are occupied in the complex and wants to install the cameras in such a way that they cover the entire set of these cells; however, due to budget constraints, he wants to determine the size of the smallest interval of cells that need to be monitored to ensure all occupied cells are observed.

Busy with his duty to uphold the law, Morete has requested your assistance: given the $$$n$$$ cells $$$c_i$$$ in the circle that are occupied, what is the minimum number of cells that should be covered by the cameras so that all occupied cells are under surveillance?

Input

The first line of input has as integer $$$n$$$ ($$$1 \le n \le 360$$$) — the number of occupied celss.

The second line of input has $$$n$$$ distinct integers $$$c_i$$$ ($$$1 \le c_i \le 360$$$) — the number of the $$$i$$$-th occupied cell.

Output

The output should contain a single integer, which is the size of the smallest interval of cells that should be covered by the cameras.

Examples
Input
2
2 32
Output
31
Input
3
10 330 30
Output
61
Note

In the first test case from the examples, the smallest contiguous interval that satisfies the statement is from cell 2 to 32, covering 31 cells.

In the second test case from the examples, the smallest contiguous interval that satisfies the statement is from cell 330 to 30, totaling 61 cells.

B. Battle in space
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nathan is a shrewd interplanetary gambler who spends his life deceiving extraterrestrials. On one of his expeditions to Uranus, our space duelist challenged an alien by saying he could beat him in any game of his choosing, imagining that his tricks would guarantee victory. Then, the alien proposed an intense intellectual battle.

Upon learning the rules of the battle, Nathan finds himself in a predicament and ends up asking for your help. Pay close attention, because the rule is somewhat complex: in the first round, the Uranian will say an integer $$$n$$$. In the second and final round, it will be Nathan's turn to say an integer $$$m$$$. The winner is the one who says the larger number.

After knowing the number $$$n$$$ said by the alien, your task is to determine which number $$$m$$$ will guarantee victory for Nathan.

Input

The input consists of a single line containing an integer number $$$n$$$ ($$$1 \le n \le 100$$$) — the number chosen by the alien.

Output

The output must contain a single integer number $$$m$$$ ($$$0 \le m \le 10^5$$$) — a winning answer for Nathan.

Example
Input
12
Output
124

C. Cosmic candidates
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

With the approaching Interplanetary Programming Marathon, Enrique, the Coach of the Union of Solar Planets Marathon Group (MaratonUSP), is determined to bring all $$$n$$$ members of the group to participate in this historic competition, which will be held on Earth for the first time.

Members of MaratonUSP are organized into teams of $$$3$$$ members. Enrique is confident that the members will be excited about the opportunity to compete with talents from across the universe. He understands that, to ensure the participation of each team, he only needs to convince the majority of the 3 members, as the last member will immediately agree to participate.

With a tight schedule, the Coach seeks your assistance in determining the minimum number of people he needs to convince to participate in the Interplanetary Programming Marathon, ensuring that all MaratonUSP teams agree to compete in this space event.

Input

The input consists of a single line containing an integer $$$n$$$, $$$n \le 100$$$.

It is guaranteed that $$$n$$$ is a multiple of $$$3$$$.

Output

Print a single number: the minimum number of MaratonUSP members that the coach must convince to participate in the Interplanetary Programming Marathon to ensure the participation of all teams in the competition.

Examples
Input
3
Output
2
Input
6
Output
4

D. Dividing the solar pizzas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Carlinhos, the best pizza maker in the solar system, discovered a new technique for cooking his pizzas: baking them on the Sun! The news of Carlinhos' new pizzas quickly spread throughout the galaxy. So, Rachel and Matheuzin, space pizza sommeliers, decided to travel to the Sun to try the novelty.

Rachel and Matheuzin went to Carlinhos' pizzeria with a group of $$$2n$$$ friends, each of whom has a favorite pizza flavor. Since they spent a lot of money on the trip, they decided to save on pizzas. Therefore, they will order $$$n$$$ pizzas, each divided into two halves of different flavors. The price of a pizza whose halves have values $$$p$$$ and $$$q$$$ is $$$\max(p,q)$$$.

Help Rachel and Matheuzin find a way to pay as little as possible for the pizzas.

Input

The first line of input has a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of pizzas that will be ordered.

The second line of input has $$$2n$$$ integers $$$p_1, p_2, \dots, p_{2n}$$$ ($$$1 \leq p_i \leq 10^4$$$), where $$$p_i$$$ is the price of the flavor which the $$$i$$$-th wants to eat.

Output

Print a single integer, the least possible price of the $$$n$$$ pizzas with the required flavors.

Example
Input
2
3 5 3 4
Output
8

E. Excavating Mercury
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It is finally time for humanity to colonize Mercury. However, a major problem for creating cities on the closest planet to the Sun is its rugged terrain. For proper city construction, the terrain of the planet needs to be leveled.

Paulo is a flat-earther (i.e., someone who flattens the earth) from IME (International Mercury Excavation), hired to fix Mercury's terrain. Mercury's horizon consists of $$$n$$$ hills, each with a height $$$a_i$$$. Due to the quantum nature of Mercury's sand, it is not possible to move sand between hills, so Paulo can only reduce their height and never increase it.

Antônio, president of the ACM (Association for the Conservation of Mercury), is very concerned about the changes that will be made to the planet and would like the terrain to be altered as little as possible, that is, the total number of meters of sand removed should be minimized. Paulo, being a natural flat-earther, is not good at math and needs your help to calm Antônio. Help Paulo determine the minimum meters of sand that must be removed from Mercury's hills so that the terrain is uniform.

Input

The input consists of two lines.

The first line contains a single positive integer $$$n\ (1 \leq n \leq 10^5)$$$ — the number of hill in Mercury's horizon.

The second line contains $$$n$$$ numbers $$$a_i\ (1 \leq a_i \leq 10^4)$$$ — the heights in meters of wach hill.

Output

Print a single non-negative integer, the minimum number of meters Paulo must dig so that Mercury's horizon becomes uniform.

Examples
Input
2
4 10
Output
6
Input
4
5 15 13 27
Output
40
Input
6
3 4 3 5 7 6
Output
10

F. Festival of the Moon
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Festival of the Moon is an anual tradition from the people of the Moon. Every waning moon, beings from all around the solar system gather to celebrate and dance around flaming craters. It is also a great oportunity to experience the great lunar cuisine, like the cheese bread made from the soil cheese in the moon.

This lunar year, May is responsible for the organization of such an important festival. With all her influence and popularity, she invited lots of planets to gather on this special date. However, May was worried that the own lunar people wouldn't appear at the meeting, since they show less and less interest over the years to participate in their own tradition, prefering to gather on the dark side and party on their own way.

Cauê, who was responsible for managing and selling the tickets, suggested an ideia: the organization could use the money they won from USP (Union of Solar Planets) through PIPA prize (Program of Incentive for Playful Activities, which aims to invest in the best parties in the Solar System), to offer tickets for half the price to the Festival of the Moon, exclusively to lunar people.

The tickets were sold and the party rocked hard. Cauê was having so much fun that he made a terrible accounting mistake: he forgot to count how many people in the party were from the Moon, and wouldn't be able to establish a good metric to check whether or not his idea was good.

Cauê then asks your help to solve this problem before he gets fired. Luckily, he was still able to write down the ammount raised, $$$a$$$, in lunar currency, and how many people, $$$p$$$, went to the festival. You may assume that everyone who bought a ticket went to the party. With this information, and with the full price of the ticket, $$$v$$$, help Cauê find out how many people at the party were from the Moon.

Input

The input consists of 3 integers $$$a$$$, $$$p$$$, and $$$v$$$ ($$$0 \leq a, p \leq 10^6$$$, $$$1 \leq v \leq 10^6$$$, $$$v$$$ is even) — the ammount raised in the Lunic Festival, how many people went to the party, and the full price of the ticket, respectively.

Output

A single integer $$$y$$$ corresponding to the total number of people in the party who where habitants from the Moon. It is guaranteed that the answer is a non-negative integer.

Examples
Input
7 5 2
Output
3
Input
22 7 4
Output
3
Input
150 10 30
Output
10
Note

In the first test case, out of the 5 people in the festival, 3 paid half-price and 2 paid full price, adding up to 7 lunar coins. Thus, there were 3 lunar people in the festival.

G. Genealogy of aliens
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The planet Venus is known for its toxic atmosphere and infernal temperatures, where apparently any civilization would be unable to live and thrive. However, records of an ancient civilization (the "Venirics") that inhabited Venus millions of years ago have been recently detected on this planet.

Faced with this surprising discovery, the Union of Solar Planets (USP) decided to send to this planet the only specialist capable of retrieving these records and revealing more details about the history of the Venutian civilization: the space archaeologist Otávio.

In his extensive research, Otávio discovered surprising facts about the generations of Venirics:

  • Generation $$$0$$$ of the Venirics was composed of exactly $$$a \geq 1$$$ inhabitants.
  • In the life cycle of a Veniric capable of reproduction, they have exactly $$$r \gt 1$$$ offspring through asexual reproduction. The value of $$$r$$$ is the same for Venirics of any generation. That is, if all $$$a$$$ Venirics from generation $$$0$$$ were capable of reproduction, then generation $$$1$$$ was composed of exactly $$$ar$$$ Venirics, and so on.
  • Due to a genetic reason still unexplained, all individuals of a certain generation $$$m \geq 0$$$ were unable to reproduce, but all individuals up to the previous generation were capable of reproduction. Thus, the Venirics civilization ended after the death of individuals from generation $$$m$$$.

The only intact record that Otávio found about the size of the historical Venirics population was its total number (i.e., the sum of the sizes of all populations from generation $$$0$$$ to generation $$$m$$$), but he was unable to deduce anything about the values of $$$a$$$, $$$r$$$, and $$$m$$$, and therefore asked for help from Marcelo, the space computer scientist.

Marcelo was also unable to deduce the values of $$$a$$$, $$$r$$$, and $$$m$$$ from $$$n$$$, as he wisely noticed that different values of these parameters could have led to the same value of $$$n$$$. The only thing he knows is that there are not many possibilities for the sizes of the generations given $$$n$$$, and he wishes to determine how many there are.

Since returning from the toxicity of Venus, however, he can no longer type, and so he asked you to write a program that answers the question for him.

Input

A single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$), the total historical population of the Venirics.

Output

A single positive integer $$$t$$$, the number of possibilities for the sizes of the Veniric generations that would have made the total historical population of Venirics equal to $$$n$$$.

Examples
Input
7
Output
3
Input
1000000000
Output
101
Note

For $$$n=7$$$, the $$$3$$$ possibilities for the sizes of the generations are:

  • Generation $$$0$$$ with $$$7$$$ inhabitants who did not reproduce.
  • Generation $$$0$$$ with $$$1$$$ inhabitant who reproduced and had $$$6$$$ offspring ($$$r=6$$$), and generation $$$1$$$ with $$$6$$$ inhabitants who did not reproduce.
  • Generation $$$0$$$ with $$$1$$$ inhabitant who reproduced and had $$$2$$$ offspring ($$$r=2$$$). Generation $$$1$$$ with $$$2$$$ inhabitants who reproduced, each having $$$2$$$ offspring. Generation $$$2$$$ with $$$4$$$ inhabitants who did not reproduce.

H. Honor to Saturn
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As part of the celebrations for the 90th anniversary of its creation, the Union of the Solar Planets (USP) decided to pay tribute to Saturn. The tribute will also serve as a symbol of the peace treaty to be signed between the USP and the kingdom of Saturn, ruled by the malevolent monarch Mori.

When consulted about the tribute, the malevolent monarch Mori ordered the construction of a gigantic necklace of asteroids for his planet. After all, what good are rings without a necklace? Furthermore, as if the task were not already fantastical enough, to symbolize the ideals of freedom and equality of the treaty, each asteroid must be either amber (a) or blue (b), coincidentally the colors of the USP flag.

To carry out this astronomically proportioned challenge, two space jewelers with vast experience in colorful asteroids, Rafael and Pedro, were summoned. The task proved even more difficult than the jewelers expected, but with little time remaining before the deadline, they managed to complete the construction of a string with $$$n$$$ amber and blue asteroids, without a specific order.

Only the final step of joining the two ends of the string remained when the monarch Mori maliciously machinated yet another restriction on the tribute: now, one half of the necklace must consist only of amber asteroids and the other half only of blue asteroids. Considering the tight deadline and the colossal proportions of the project, the jewelers would not be able to construct a new string in time. Then an idea emerged: remove a contiguous segment of the string (possibly the entire string) and join the two ends of this segment to form a necklace that meets the new restrictions.

Now Rafael and Pedro need to assess the feasibility of this plan and have asked for your help to determine the maximum size (in number of asteroids) of a necklace that can be created with this technique, also meeting the restrictions that the malevolent monarch Mori maliciously machinated. Note that a necklace of size zero is also valid according to the restrictions, and that the initial string is not circular, meaning the first and last asteroids are not initially connected to each other.

Input

The first line of input contains an integer $$$1 \leq n \leq 2\cdot 10^5$$$ — the amount of asteroids in the string.

The second line of input contains a string of size $$$n$$$ with characters equal to 'a' and 'b' — the sequence of colors of asteroids in the string.

Output

Print a single line containing an integer — the size of the largest necklace that can be obtained from the string following the described technique.

Examples
Input
9
babbbaabb
Output
6
Input
6
bababa
Output
2
Input
7
baaaabb
Output
4
Input
1
a
Output
0
Note

In the first example, valid necklaces of different sizes can be obtained, as shown in the figure below, but the largest one is the necklace obtained from the segment "abbbaa", with a size of six.

In the second example, only valid necklaces of size zero or two can be obtained.

In the third example, the largest valid necklace that can be obtained has a size of four, from the segment "aabb" at the end of the string.

In the fourth example, no valid necklace larger than size zero can be obtained.

I. Investigating Mars
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Nathalia, a software engineer and marathon enthusiast, is currently engaged with the MaratoNasa development team, working on the Mars exploration project. Her role is crucial in developing the software for the incredible exploratory robot K-IA-FFA.

The planet Mars is represented by a board with dimensions $$$n$$$ by $$$m$$$, where '$$$\#$$$' indicates a wall and '$$$.$$$' represents an empty space. Nathalia is currently in the testing stage of the final version of the K-IA-FFA software, which commands the movements of the exploratory robot. Her task is to evaluate the software's effectiveness in terms of board coverage.

The operation of the software follows a logical pattern:

  • If possible, the robot moves forward one square in the current direction.
  • Otherwise, it rotates $$$90^\circ$$$ counterclockwise and tries to move forward again.

It is important to note that the edges of the board are also considered walls to prevent the robot from escaping. Nathalia needs to calculate how many distinct squares on the board the robot will be able to visit in various possible scenarios.

Input

Each instance will represent a scenario. The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n, m \leq 10^3$$$) separated by a space, the dimensions of the board.

The next $$$n$$$ lines contain $$$m$$$ characters $$$a_{i, j} \in \{L, D, R, U, \cdot, \#\}$$$. The $$$L$$$ represents the initial position of the robot facing left, $$$R$$$ represents the initial position of the robot facing right, $$$D$$$ represents the initial position of the robot facing down, and $$$U$$$ represents the initial position of the robot facing up.

It is guaranteed that there is exactly one element from $$$\{L, D, R, U\}$$$ on the board and that this position is empty.

Output

The output must be a single integer $$$x$$$ which is the number of distinct squares of the board that K-IA-FFA will visit.

Examples
Input
2 2
.L
.#
Output
3
Input
2 2
L.
.#
Output
2
Input
4 4
#..#
#...
##.#
U..#
Output
9
Note

Consider the first example test case. The K-IA-FFA robot will follow these steps:

He will keep moving, but will not visit any new squares.

J. Jupiter's Dinner
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In 2024, the Union of the Solar Planets (USP) is celebrating its 90th anniversary! To mark this occasion, Maystronauta and Astronauthan organized a dinner for the members of MaratonUSP at the best restaurant in the solar system, Red Spot, on Jupiter!

Upon arriving at the restaurant, the $$$n$$$ members of MaratonUSP sat at a single table with chairs numbered from $$$1$$$ to $$$n$$$. The person in position $$$i$$$ ordered dish number $$$a_i$$$. The renowned chefs Willian Fogaça Mori and Nathália Carosella Tsuno will take care of cooking the dishes for the evening, but the space waiter Thilio will need your help.

Like any other common Jovian, Thilio has $$$k$$$ arms. He can carry as many dishes as needed with each of his arms but with one restriction: all the dishes must be identical. For example, if everyone ordered dish 1, Thilio would be able to serve the entire table with just one arm. However, if someone ordered dish 1 and someone else ordered dish 2, he would need to carry one dish in each arm. According to the restaurant's rules, the waiter must serve a continuous range of people, i.e., choose values $$$\ell$$$ and $$$r$$$ and serve all the customers seated in the interval $$$[\ell, \dots, r]$$$.

As Thilio is a big fan of competitive programming, he would like to serve the maximum number of MaratonUSP members possible. He needs your help to find an interval $$$[\ell, \dots, r]$$$ of maximum length such that all the orders within this interval can be carried with his $$$k$$$ arms.

Input

The input consists of two lines. The first line contains two integers $$$1 \leq n, k \leq 200000$$$, where $$$n$$$ is the number of members in the group and $$$k$$$ is the number of arms of the waiter. The following line contains $$$n$$$ integers $$$1 \leq a_i \leq 200000$$$ which represent the orders of each member.

Output

The output must contain two lines. The first line is the size of a maximum interval $$$[\ell, \dots, r]$$$ with at most $$$k$$$ distinct orders inside this interval. The second line must contain two integers $$$\ell, r$$$ representing the start and the end of the interval. If there are multiple valid answers, any of them will be accepted.

Examples
Input
5 2
1 2 3 2 1
Output
3
2 4
Input
8 3
4 1 2 3 3 2 1 4
Output
6
2 7
Input
10 1
1 2 2 1 2 1 2 2 1 1
Output
2
2 3
Note

In the second test case, the interval [2,7] contains only dishes 1, 2, and 3, and therefore Thilio would be able to carry them. Note that any interval of size 7 or larger would have 4 distinct dishes, and Thilio would not be able to carry them with his 3 arms.

In the third test case, other possible answers would be the interval [7, 8] or the interval [9, 10]. Note that there is no interval of size 3 or more with all dishes of the same type.