2023 USP Try-outs
A. Metaverse Real Estate
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Most of the properties in the village of Chavo in Mexico belong to Mr. Barriga, who charges high rental values. Kiko, the lover of square balls, is interested in buying a property with equal sides, but not in the real world, but in the metaverse!

Mr. Barriga follows an unconventional procedure to sell properties in the metaverse: First of all, the metaverse could be a $$$k$$$-dimensional universe. For a three-dimensional metaverse, that is, when $$$k$$$ equals 3, the sale is described as follows: Let a simple cube be a cube with faces parallel to the coordinate axes and with vertices of integer coordinates. Mr. Barriga owns a simple cube $$$A$$$ with side $$$n$$$, defined by the vertices at the origin and $$$(n,n,n)$$$. A simple cube $$$B$$$ entirely contained within $$$A$$$ will be chosen randomly for sale. All distinct valid cubes $$$B$$$ have the same probability of being chosen. Two cubes are distinct if they are defined by different vertices. Note that, for example, it is more likely that cube $$$B$$$ has side of 1 rather than 2, as there are more cubes with a side of 1 inside $$$A$$$ than there are with side of 2. The selling procedure can be extrapolated from the 3-dimensional case to the $$$k$$$-dimensional one. The hypercube $$$B$$$ to be sold has the same number of dimensions: $$$k$$$.

Given $$$n$$$, the side of the hypercube $$$A$$$, and $$$k$$$, the number of dimensions of the metaverse, help Kiko to determine the expected hipervolume of the cube $$$B$$$ to be sold. The answer can be represented as an irreducible fraction $$$p/q$$$. Print the fraction modulo $$$10^9+7$$$. Formally print $$$x$$$ such that $$$0 \leq x \lt 10^9+7$$$ and $$$x \cdot q \equiv p \mod (10^9+7)$$$. It is guaranteed that the fraction can be represented in this way. In particular, it is guaranteed that the number of distinct cubes $$$B$$$ is not congruent to $$$10^9+7$$$.

Input

The single line contains two integers $$$n$$$ ($$$1 \leq n \leq 10^9$$$), the side of the hypercube $$$A$$$, and $$$k$$$ ($$$2 \leq k \leq 2 \times 10^5$$$), the number of dimensions of the metaverse.

Output

Print an integer, the expected hipervolume of cube $$$B$$$, modulo $$$10^9+7$$$.

Examples
Input
2 2
Output
200000003
Input
100 5
Output
109325391
Note

For the first input case, the number of dimensions $$$k$$$ is 2. The side of the square $$$A$$$ is 2. There are five distinct simple squares within $$$A$$$. Four of them have an area of 1, and one of them has an area of 4. The expected volume is $$$\frac{8}{5}$$$. The answer is 200000003, since $$$200000003 \times 5 \equiv 8 \mod (10^9+7)$$$.

B. Maracas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The most classic instrument in Mexican music is the maraca, which is made up of a handle and a ball on top containing seeds and it functions as a type of rattle. As everyone knows, the use of pairs of maracas is mandatory!

You have just arrived in Mexico and will participate in a maraca circle with exactly $$$N$$$ people. At the $$$i$$$-th position of the circle, there is a number of maracas $$$m_i$$$. Your task is to redistribute the maracas so that each position has an even number of maracas to be used; after all, there cannot be a maraca without its pair. Since the circle is really big, you can only take maracas from a position and move them to the position immediately to the left or right.

The time it takes to carry a maraca from one position to another is directly proportional to the number of maracas being carried, because the greater the quantity, the heavier the weight. The time to carry a maraca to the left is $$$A$$$ seconds, and to the right is $$$B$$$ seconds. Additionally, if you're not carrying any maracas, you can move very quickly between positions (in zero seconds).

Since everyone wants to start making music as soon as possible, your goal is to determine the minimum time needed to complete this task. If it's not possible to achieve the task, you should print $$$-1$$$.

Input

The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 10^6$$$).

The second line contains $$$N$$$ integers $$$1 \leq m_i \leq 10^9, \, i = 1,\ldots, N$$$. Note that the list of quantities of maracas is circular, that is, position $$$i$$$ is adjacent to $$$i+1$$$ and position $$$N$$$ is adjacent to position 1.

The third line contains two integers $$$A$$$ and $$$B$$$. $$$1 \leq A, B \leq 10^9$$$

Output

Print a single integer: the minimum time if possible or -1.

Examples
Input
11
2 3 4 2 3 3 1 1 9 6 10
1 9
Output
5
Input
6
1 1 1 1 1 3
4 10
Output
12

C. Quasi-Palindrome
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ana, affectionately called Anita, loves palindromes, but unfortunately she is constantly sad because palindromes are rare and she has little to no opportunity to exercise her passion. For example, Mexico, where Ana lives, is known for having no city whose name is a palindrome.

Instead of looking for another hobby, Ana is considering slightly extending her passion to include quasi-palindromes. A word is a quasi-palindrome if there are at most two positions that differ between the word and its reverse.

For example, the word $$$anita$$$ is a quasi-palindrome because $$$anita$$$ differs from $$$atina$$$ in only two positions. However, $$$mexico$$$ is not a quasi-palindrome, as it differs from $$$ocixem$$$ in 6 positions. Note that every palindrome is also a quasi-palindrome.

Ana realized that her life could greatly improve if she makes this decision. She has plans to move to Zapopan near Guadalajara and won't be bothered when her friends call her Anita.

Before making this decision, she needs to be sure that she won't regret it and wants to understand more about the properties of quasi-palindromes. For this, she wants you to write a program that, given a word, calculates how many substrings of that word are quasi-palindromes.

Input

An integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$), the size of the word $$$s$$$. A word $$$s, |s| = n$$$, composed only of lowercase letters ([a-z]).

Output

A number, the number of substrings of $$$s$$$ that are quasi-palindromes.

Examples
Input
5
anita
Output
13
Input
6
mexico
Output
15
Input
7
abacaba
Output
22
Note

In the first test case, out of all 15 substrings of $$$anita$$$, only $$$anit$$$ and $$$nita$$$ are not quasi-palindromes because they differ by 4 positions from their reverses.

In the second case, all and only the substrings of size 3 or less are quasi-palindromes, totaling 15 quasi-palindrome substrings.

D. Supermarket queue
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Tortillas are one of the most characteristic elements of Mexican cuisine. Made with wheat or corn flour, they are used in the preparation of various delicious foods, such as tacos, burritos, and quesadillas. The manager of a famous supermarket in Mexico City went crazy and decided to hold a mega promotion on different types of flour, which attracted many customers to his establishment.

The supermarket has the capacity for $$$k$$$ checkout queues. After finishing their shopping, a customer goes to one of these queues to make the payment. Since people are very stubborn, they never switch queues once they have entered one, even if it's taking too long to move.

A customer becomes sad if, while waiting in a queue, they observe someone entering and leaving another queue.

Considering that $$$n$$$ people are in the supermarket, numbered from 1 to $$$n$$$, you receive a list of $$$2n$$$ events in chronological order indicating the entry or exit of a customer from a queue. Determine which customers will be sad.

Input

The first line of the input contains two integers $$$n$$$ and $$$k$$$, representing the number of people and the number of queues in the supermarket, respectively, such that $$$1 \leq n, k \leq 10^5$$$.

Each of the following $$$2n$$$ lines represents one of the two types of events. For an entry event, the line starts with the number 1, followed by the integers $$$p_i$$$ and $$$f_i$$$, indicating that person $$$p_i$$$ entered queue $$$f_i$$$. For an exit event, the line starts with the number 2, followed by the integer $$$f_i$$$, indicating that the first person in queue $$$f_i$$$ has left. For both cases, the following conditions hold: $$$1 \leq p_i \leq n$$$ and $$$1 \leq f_i \leq k$$$.

Output

Print a line containing an integer $$$m$$$, representing the number of sad people. Then, print another line with $$$m$$$ integers in ascending order, indicating the people who are sad.

Example
Input
4 3
1 1 1
1 2 2
1 3 3
2 2
1 4 1
2 1
2 1
2 3
Output
2
1 3 

E. Long Live Mexico
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On September 15, 1810, Mexico begins its battle for independence. The date is celebrated with grand festivities, music, and fireworks. However, due to the pollution generated by the fireworks' explosions, Mexican citizens have been seeking an alternative to traditional fireworks.

With the popularization of drones, it is now common to use these devices to perform at events, creating complex figures in beautiful light shows. The drones are not real-time controlled. A program is loaded into one of the drones, called the primary drone, while the other drones, the servant drones, receive instructions from this single drone. The organizers of the festivities are concerned about whether the primary drone's battery will be sufficient to complete the entire show.

In this problem, we will represent each drone as a point in three-dimensional space $$$(x, y, z) \in \mathbb{Z}^3$$$. Consider that drone number 0 is the primary drone. Each servant drone is distinct, so each one has a cost $$$w_i$$$ to transmit the signal. The total transmission cost between the primary drone and a servant drone grows quadratically with the Euclidean distance between them, given by:

$$$$$$\operatorname{dist}(i, j) = \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2 + (z_i - z_j)^2}$$$$$$

To maximize the uptime of the primary drone, we want to minimize the total transmission cost, which is given by:

$$$$$$\sum_{j = 1}^{j \leq n}\operatorname{dist}(0, j)^2w_j.$$$$$$

The Latin American ICPC Final will be held in Mexico, and the organizers of the festivities have requested your help to solve this problem. Given the positions of the servant drones and the transmission costs of each one, determine the coordinates of the primary drone that minimizes the total transmission cost. The position of the primary drone must be integral. In case of multiple answers, print the lexicographically smallest one.

Input

The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$, the number of servant drones.

The next $$$n$$$ lines contain four integers separated by spaces $$$x_i, y_i, z_i$$$ and $$$w_i$$$, representing the coordinates of the $$$i$$$-th drone $$$1 \leq x_i, y_i, z_i \leq 2\cdot 10^5$$$ and the transmission cost $$$1 \leq w_i \leq 10^3$$$.

Output

Print in a single line three integers separated by spaces, representing the position of the primary drone that minimizes the transmission cost. In case of multiple answers, print the lexicographically smallest one.

Examples
Input
3
1 1 1 1
2 2 2 1
3 3 3 1
Output
2 2 2 
Input
4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
Output
3 3 3 

F. Goalkeeper of 7 games (or less)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Every Brazilian knows Ryan Ochoa very well, the Mexican goalkeeper who park the bus the goal against Brazil in the 2014 World Cup. More than that, the guy becomes the best goalkeeper in history during any World Cup period and hibernates for the following 4 years. What nobody knows is that in reality, he is training his successor as the best goalkeeper in World Cups: you! Now you need to buy one pair for yourself and one pair for Ochoa. In the store, there are exactly $$$N$$$ gloves on display, arranged in a line. The glove in position $$$i$$$ has size $$$A_i$$$. The size you both wear doesn't matter, as you are the best in the world in your position. However, to not hinder the performance in training, it's crucial to choose the same size $$$X$$$ for both your gloves and the same size $$$Y$$$ for Ochoa's ($$$X$$$ and $$$Y$$$ can be different). Every day, the gloves available for sale can change! They are always defined by an interval $$$[l, r]$$$ that represents the positions of the gloves for sale at that moment. Moreover, the glove at position $$$i$$$ can be replaced by another of a different size. We have $$$Q$$$ changes in total, and they are described as follows:

  • $$$1$$$ $$$\ell \, r$$$: The range of gloves for sale has changed to $$$[l, r]$$$, and at this moment, you must say whether it's possible to buy a pair of gloves for yourself and one for Ochoa;
  • $$$0$$$ $$$i \, x$$$: the glove in position $$$i \in \{1 \ldots N\}$$$ was exchanged for a glove of size $$$1 \leq x \leq 10^9$$$.
Input

The first line contain two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^5$$$).

The second line contains a sequence $$$A_i$$$ of size $$$n$$$ ($$$1 \leq A_i \leq 10^9$$$).

The next $$$q$$$ lines contains the operations described in the statement.

Output

For each operation of type $$$1$$$:

  • If it is possible, print 4 integers that represent the position of the gloves to buy. If there are more than one answear, print any. The order that you print the gloves does not matter.
  • If it is not possible, print $$$-1$$$.
Examples
Input
4 3
1 1000000000 1 1
1 1 4
0 4 1000000000
1 1 4
Output
-1
2 4 1 3
Input
10 8
1 1 2 3 4 5 5 6 7 10
1 1 6
1 1 7
0 4 2
1 1 6
0 1 5
1 1 6
0 4 3
1 1 7
Output
-1
6 7 1 2
3 4 1 2
1 6 3 4
-1

G. Choice hero
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It is a well known strategy for mobile game ads to show the gameplay of a game in which the player is very bad. This makes the viewer want to download the game to prove how easy it is. You are the tester of one such game: Choice hero.

The idea of the game is the following: you start with a hero with power $$$f$$$ and you are going to play $$$n$$$ levels, numbered from 1 to $$$n$$$, one after the other in ascending order. In the $$$i$$$-th level you fight exactly one of two available monsters. The monster from the left has power $$$a_i$$$ and the monster from the right power $$$b_i$$$. If you successfully beat exactly one of the monsters you proceed to the next level $$$i+1$$$, or you win the game in case it was the $$$n$$$-th and last level. The hero can only beat a monster with power smaller than or equal to his own power at the time. If the hero has power $$$x$$$ before the fight with a monster with power $$$y$$$ ($$$y \leq x$$$), the hero gains the power of the defeated monster, that is, his power becomes $$$x+y$$$. Your job as the tester is to report if it is possible to win the game given the list of $$$n$$$ levels.

Input

The first line of the input contains two integers $$$n$$$ and $$$f$$$, the number of levels and the initial power of the hero ($$$1 \leq n \leq 2 \cdot 10^3 , 1 \leq f \leq 10^6$$$). The next $$$n$$$ lines contain 2 integers each: $$$a_i$$$ and $$$b_i$$$, the power of the monster from the left and the power of the monster from the right ($$$1 \leq a_i, b_i \leq 10^6$$$).

Output

Print "S" if it is possible to beat the $$$n$$$ levels in the given order or "N" otherwise.

Examples
Input
3 2
1 2
5 3
4 4
Output
S
Input
3 2
4 4
1 2
5 3
Output
N

H. The infinite festival
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Yan 'the globe-trotter" Soares continues his trips around the world. In a dream, he recalled that an ancestor of his was Latin American champion of a certain programming competition. Intrigued by this dream, he is heading to Mexico to attend one of these competitions.

Yan is a fan of role-playing games, so he is going to take advantage of this trip to attend the largest role-playing festival in the world. It takes place in the city of Guadalajara, and is composed of $$$N$$$ days where various events take place, and after these $$$N$$$ days, the festival repeats itself again. That's why it's called the "infinite festival".

As it is typical of this kind of festivals, each participant receives a level, in total there are $$$M$$$ levels and every participant starts at level $$$1$$$. Yan has two goals: $$$(a)$$$ to attend the $$$N$$$ days of the festival and, $$$(b)$$$ to reach the level $$$M$$$ during this time. As any good traveler, he would like to do this by spending as little money as possible.

Yan knows the cost $$$c_{ij}$$$ of reaching level $$$i + 1$$$, from level $$$i$$$, on day $$$j$$$. Note that he can go several levels up in one day (even all of them). Also, it knows the cost $$$d_{ij}$$$ of accommodation on day $$$j$$$ if he has level $$$i$$$. Note that the cost of accommodation is paid daily at the end of the day, when the events have finished.

Unfortunately, Yan did not inherit his ancestor's skills. Therefore, he asked you to make a program that calculates the minimum cost of attending the festival. Note that Yan can arrive on any of the $$$N$$$ days to the festival. For instance, if we represent the $$$i$$$-th day of the festival by the integer $$$i$$$ and Yan arrives on day $$$x$$$, then the sequence $$$x, x + 1, \ldots, N, 1, 2, \ldots, x - 1$$$ represents the days he attends to the festival. Note that Yan does not pay for the accommodation of the last day (day $$$x - 1$$$ in the previous example).

Input

The first line contains the integers $$$N$$$ and $$$M$$$ $$$(1 \leq N, M \leq 1500)$$$ as described in the statement. Each of the next $$$M - 1$$$ lines represents the costs $$$c_{ij}$$$ $$$(1 \leq c_{ij} \leq 10^9)$$$. The $$$i$$$-th of these lines contains $$$N$$$ integers representing the cost of reaching level $$$i + 1$$$ from level $$$i$$$ on each of the $$$N$$$ days. Finally, each of the next $$$M$$$ lines represent the costs of accommodation $$$d_{ij}$$$ $$$(1 \leq d_{ij} \leq 10^9)$$$. The $$$i$$$-th of these lines contains $$$N$$$ integers that represent the cost of accommodation if Yan has level $$$i$$$ on each of the $$$N$$$ days.

Output

Print an integer, the minimum cost of attending the $$$N$$$ days of the festival and reaching the level $$$M$$$.

Examples
Input
4 4
43 31 15 20
2 42 3 37
22 39 39 1
17 40 19 58
35 20 35 1
53 1 43 66
16 37 63 67
Output
80
Input
3 5
5 24 1
13 16 15
9 13 3
11 2 16
8 12 3
20 12 13
15 5 19
12 13 6
20 16 2
Output
39
Input
5 3
12 14 13 10 14
12 24 20 8 6
8 9 11 22 25
11 11 25 11 10
5 1 18 21 21
Output
49

I. Help the Aztecs
time limit per test
0.6 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Aztecs were a civilization that emerged around 1300 in regions that now belong to Mexico. The Aztec empire had city-states with elaborate urban planning, an expressive cultural production, and influence in different spheres of Mexican modern society, like language and cuisine.

The economy was centered on agriculture, especially corn and beans. Hence, we can consider the empire as being divided into $$$n$$$ plantation fields. Two fields may be connected by a road. We know the empire had $$$m$$$ roads in total.

Imagine now that you became the Aztec emperor, therefore you need to control the empire's economy and your people's happiness. Your counselors told you that if a road has one endpoint at a been field and another at a corn field, the population considers that road as being good because it shows the diversity of the agriculture. During your government $$$q$$$ events will happen, these events can be of two types. Events of type 1 happen when the rain god, Tlaloc, is angry with the empire and flood one of the fields together with all roads that reached the flooded field. After events of type 1 the destroyed field and roads never come back to existence. Events of type 2 happen when Tlaloc is happy and provides good weather for plantations, in this case, you should decide which fields will cultivate corn, and consequently, all others will cultivate beans. For your population to be satisfied is necessary that at least half of the existing empire's roads are good. Now you must play your role as the emperor to guarantee the happiness of your population, and that the empire can keep prospering!

Input

The first line has three integers $$$1 \leq n \leq 2500$$$, $$$0 \leq m \leq 2 \times 10^5 $$$ and $$$1 \leq q \leq 5000$$$, which represent the number of fields in the empire, the total number of roads at the beginning, and the number of events that will happen.

The next $$$m$$$ lines have two integers $$$u$$$ and $$$v$$$, representing that there is a road between fields $$$u$$$ and $$$v$$$. Between any pair of fields, there is at most one road connecting them.

The next $$$q$$$ lines can be of two types, and represent the events that will happen. The line can have the number 1 followed by a field $$$v$$$, this means that an event of type 1 happened at field $$$v$$$. Note that an event of type 1 cannot happen twice in the same fields. In the other case, the line will have only the number 2, indicating that an event of type 2 happened.

Output

For each event of type 2, you should print a line. This line should have an integer $$$k$$$, representing how many fields will cultivate corn, followed by $$$k$$$ integers representing which are those fields. The number of good roads choosing these plantations should be at least half of the remaining roads in the empire. It can be proven that an answer always exists. If there are multiple answers, you can print any of them.

Examples
Input
5 5 3
1 2
2 3
3 4
4 5
1 5
2
1 1
2
Output
2 1 3
2 2 4
Input
6 9 4
4 1
1 5
1 6
4 2
4 3
5 3
5 2
6 3
6 2
1 1
1 4
2
2
Output
1 2
2 2 3
Note

In the first test case, if in the first event, you choose fields 1 and 3 to plant corn, and consequently fields 2, 4, and 5 to plant beans, then 4 out of 5 roads will be good. After field 1 is flooded, if you choose fields 2 and 4 to plant corn, then 3 out of 3 roads will be good.

J. Indiana Jiang and the Temple of Kukulkan
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

In the remote corners of Mexico, hidden among the mystical ruins of the Temple of Kukulkan, lie the most well-guarded secrets of the ancient Mayan programmers. Legend has it that the transcendent knowledge of ancient algorithms is protected by a mysterious Encoded Chamber, access to which is safeguarded by a clever enigma.

The entrance to the Encoded Chamber does not resemble any ordinary door. A sequence of sacred symbols, initially representing the sun, adorns the facade of the passage. In front of it, a set of elaborately carved levers is arranged on a stone panel. Every time a lever is pulled, exactly two of the sacred symbols mysteriously change form: a sun transforms into a moon, and a moon transforms into a sun.

The guardian of this chamber is Indiana Jiang, a renowned archaeologist who, after years of tireless research, has discovered a sequence of symbols that, once obtained, will reveal the path to the ancestral knowledge. Exhausted from his investigations, Jiang requests your help to rescue the Mayan secrets before they fall into the wrong hands. Find a set of levers that, when pulled, will open the door to the Encoded Chamber.

Input

The first line of the input contains two integers $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$), representing the number of levers, and $$$m$$$ ($$$2 \leq m \leq 5 \cdot 10^5$$$), representing the number of symbols on the passage.

Each of the following $$$n$$$ lines contains two integers $$$s_{i, 1}$$$ and $$$s_{i, 2}$$$ ($$$1 \leq s_{1, i}, s_{2, i} \leq m$$$, $$$s_{1, i} \neq s_{2, i}$$$), which are the symbols connected to lever $$$i$$$.

The last line contains a sequence of $$$m$$$ digits representing the symbol sequence that opens the door to the Encoded Chamber. The digit 0 represents the sun, and the digit 1 represents the moon.

Output

Print -1 if there is no solution. If there is a solution, print the number of levers to be pulled and a list of these levers (without repetition). If there is more than one solution, you can print any one of them.

Example
Input
2 3
1 2
2 3
1 0 1
Output
2
1 2 

K. Missing Cyan
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Hi, welcome to Guadalajara! The first Latin American ICPC final is about to begin. After participating as a contestant for years today you will help the organization. You remember the rules, right? Each team has at most 3 people. Each team should have exactly one printed contest.

We have $$$n$$$ contestants subscribed, but we don't know how the teams are organized. Depending on how many teams we have we will need to print more or fewer contests. Even though the contest is in black and white you know how printers always complain about being low on cyan, so you want to know what the minimum number of contests printed you will need among all possible team divisions.

Input

One integer $$$1 \leq n \leq 10^9$$$.

Output

Among all possible team divisions, what is the minimum number of contests that should be printed.

Examples
Input
6
Output
2
Input
8
Output
3
Input
1923022
Output
641008
Note

For the second test case, we could have 8 teams, each one with one participant, and then we would need to print 8 contests. We could have 4 teams, each one with two participants, and we would need 4 printed contests. We could have 3 teams, two teams with three participants and one team with two contestants, in this case, we would need only three printed contests. It is possible to show that the last division is the one that minimizes the number of printed contests.

L. Tourist circuits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In 2024, the city of Guadalajara will host the 1st Latin American Final of the ICPC. For this reason, the city government is interested in promoting tourism. They have collected information about the $$$N$$$ most important tourist attractions in the city. The mayor wants to organize these attractions into tourist circuits. A tourist circuit is a sequence of distinct tourist sites, say $$$\langle p_1, p_2, \ldots, p_\ell \rangle$$$ such that $$$\ell \geq 3$$$. Tourists participating in the circuit, starting at $$$p_1$$$, visit the attractions of the circuit following the sequence until they reach the site $$$p_\ell$$$. After visiting $$$p_\ell$$$, tourists return to $$$p_1$$$ to finish the circuit. Therefore, to form the circuit, there must be a street that connects tourist sites that are consecutive in the sequence (including $$$p_1$$$ and $$$p_\ell$$$).

The city government calculates that maintaining a circuit will have a high cost. Therefore, they want to divide the $$$N$$$ tourist sites into as few circuits as possible. In other words, they want to find a set of circuits such that each tourist site belongs to a unique circuit, and the set is as small as possible. To solve this difficult task, the city government hired Marcel "the optimizer" Saito.

Marcel received information about the city's street network. After an analysis, he realized that the network satisfies the following property. For any four tourist sites $$$A$$$, $$$B$$$, $$$C$$$ and $$$D$$$, $$$$$$ d(A, B) + d(C, D) \leq \max\{ d(A, C) + d(B, D), d(A, D) + d(B, C) \}, $$$$$$ where $$$d(U, V)$$$ is the smallest number of streets we need to travel to get from $$$U$$$ to $$$V$$$.

Marcel is sure that this property is important to solve the problem at hand. Unfortunately, he needs to take care of his newest apprentice Daniel "the dynamic" Ito. Therefore, he has entrusted this task to you, the newest trainee.

Input

The first line contains two integers $$$N$$$ ($$$1 \leq N \leq 10^5$$$) and $$$M$$$ ($$$1 \leq M \leq 10^6$$$), the number of tourist sites and the number of streets connecting these sites, respectively. Each tourist site is identified by a number from $$$1$$$ to $$$N$$$. Each of the next $$$M$$$ lines contains two integers representing the tourist sites connected by that street. Note that $$$(a)$$$ streets can be traveled in both directions, $$$(b)$$$ no two streets connect the same pair of tourist sites, $$$(c)$$$ a street does not connect a tourist site with itself, and $$$(d)$$$ by traveling the streets of the network we can go from one tourist site to any other.

Output

The first line contains an integer $$$K$$$, the smallest number of tourist circuits that satisfy the requirements of the city government. If such a requirement is infeasible, print $$$-1$$$. Otherwise, each of the next $$$K$$$ lines describes a tourist circuit. To represent a circuit, first print an integer $$$\ell$$$, the number of tourist sites that make up the circuit. Then, print a sequence of integers $$$\ell$$$ that represents how we should travel that circuit. If there is more than one solution, any one will be accepted.

Examples
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
1
4 1 4 3 2 
Input
7 6
1 2
1 3
3 4
3 5
2 6
5 7
Output
-1

M. Chavo's Barrel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Chavo lives in a barrel on the street. The street can be seen as a 2D plane and has two streetlights located at points $$$p1$$$ and $$$p2$$$. These streetlights illuminate discs directly beneath them, which means they generate two discs $$$c1$$$ and $$$c2$$$ with centers at $$$p1$$$ and $$$p2$$$ respectively.

Chavo lived with his barrel of radius $$$0$$$ at the point $$$(0, 0)$$$ on the street, where the edge of the discs generated by the two streetlights intersect. In other words, this is where the edge of $$$c1$$$ intersects with the edge of $$$c2$$$.

Chavo is tired of his tiny home and wants to move to a larger barrel, where every point in his barrel is illuminated by both streetlights. However, Chavo is afraid of change, so he doesn't want any point in his barrel to be more than a distance of $$$R$$$ away from his original home.

Help Chavo by figuring out the largest radius of a barrel that can be illuminated by both streetlights and still remain entirely within a distance of $$$R$$$ from his original home.

Input

$$$0 \leq R \leq 10^6$$$, the maximum allowed distance from $$$(0, 0)$$$ to any point in the new barrel.

$$$-10^6 \leq p1.X, p1.Y \leq 10^6$$$, the coordinates of streetlight 1, $$$p1$$$.

$$$-10^6 \leq p2.X, p2.Y \leq 10^6$$$, the coordinates of streetlight 2, $$$p2$$$.

The radii of the discs $$$c1$$$ and $$$c2$$$ generated by the streetlights are such that the origin $$$(0, 0)$$$ lies on the edge of both discs.

Output

A single number, the radius of the largest barrel that can be illuminated by the two streetlights and still remain entirely within a distance of $$$R$$$ from the origin.

The relative and absolute error must be less than $$$10^{-6}$$$.

Examples
Input
6
3 0
0 3
Output
0.8786797
Input
2
3 4
4 -3
Output
0.7759225
Note

The following image represents the second test case. The circle with the dashed border has a radius of $$$R$$$, so the barrel needs to be entirely within it, as well as within the discs generated by $$$p1$$$ and $$$p2$$$.

Note that the discs $$$c1$$$ and $$$c2$$$ intersect at the origin.

Second testcase