UTPC Contest 10-01-21 Div. 2 (Beginner)
A. Oseye Sort
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Oseye, king of hot stuff, is a well-known dictator. Within his heated kingdom, he believes in using his power to maintain a high degree of order.

Avatar Tang and his group of $$$N$$$ friends, The Boomertang Squad, are trying to lay low and fit in by adopting the local customs. Tang's friends are labeled $$$1$$$ through $$$N$$$. At any point in time, this group might end up in the presence of guards. When this happens, they must either line up in ascending or descending order.

Given the number of friends and the desired order, help Tang order his friends properly.

Input

A single integer, $$$1 \leq N \leq 10$$$ and a character $$$x$$$ where $$$x$$$ is 'd' if you want descending order and 'a' if you want ascending order.

Output

Output $$$N$$$ integers, denoting the order of Tang's friends.

Examples
Input
3 a
Output
1 2 3 
Input
4 d
Output
4 3 2 1 

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

Avatar Korma is competing in Republic City's latest pro bending tournament, but isn't sure if she can manage to come out on top. Thankfully, due to her intel, she has accurate ELO level that indicate how strong her team and all other teams competing in the pro bending tournament are. Each team, including Korma's, has a distinct ELO level and a team with a higher ELO level will always defeat a team with a lower ELO level.

The tournament will proceed in a single-elimination format, which will continue until all teams except one are eliminated.

Korma wants to know if she can expect to win the tournament or not, so you need to write a computer program to calculate this for her. Korma will always be able to determine if she will win or lose the tournament given this accurate intel. Print out Easy Win! if Avatar Korma will win the tournament and print out out Difficult Loss otherwise.

Input

The first line will consist of a two integers $$$n$$$ $$$(1 \leq n \leq 10^3)$$$ and $$$k$$$ $$$(1 \leq k \leq 10^5)$$$, which give the number of competing teams (not including Korma's) and Avatar Korma's ELO level, respectively. The next line consists of $$$n$$$ integers where the $$$i$$$th integer $$$e_i$$$ gives the ELO level of the $$$i$$$th team $$$(1 \leq e_i \leq 10^5)$$$.

Output

Print Easy Win! if Avatar Korma will win the tournament and Difficult Loss otherwise.

Examples
Input
3 4
1 2 3
Output
Easy Win!
Input
5 5
1 4 3 8 2
Output
Difficult Loss

C. Cactus Juice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Socka is venturing into the business world of the Earth Empire. He finds a vibrant market for cactus juice but he also realizes that his customers are very picky. They will only leave a tip if he serves $$$x$$$ mL of cactus juice where the number $$$x$$$ has exactly two distinct prime divisors.

So for example, Socka will get tips if he serves glasses with $$$18$$$ or $$$24$$$ mL of cactus juice but his customers won't be happy if they get $$$4$$$ or $$$8$$$ mL of cactus juice. Given that the glasses can hold any amount up to (and including) $$$n$$$ mL and the glasses cannot be empty, help Socka determine how many different sizes of cactus juice that he can serve so that he still gets a tip for every size.

Input

The first and only line of input will contain a single integer $$$n$$$ ($$$1 \leq n \leq 5000$$$) where $$$n$$$ is the maximum mL of cactus juice that still fits in a glass.

Output

A single integer with the number of sizes such that Socka still gets a tip for every size served.

Examples
Input
11
Output
2
Input
20
Output
7
Note

In the first example, Socka can serve glasses with $$$6$$$ mL of cactus juice and $$$10$$$ mL of cactus juice and no other size satisfies our condition.

D. Feeding the Earth Kingdom
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recent turmoil has left the people of the Earth Kingdom more disconnected than ever. The people lack contact with the outside world and are starting to go hungry. No worries, Avatar Korma is here to save the day!

Korma has analyzed the area and realized that the $$$N$$$ villages (numbered $$$1...N$$$) of the Earth Kingdom are left with only $$$M$$$ roads (which are traversable in both directions). Furthermore, the road infrastructure of the kingdom has been so damaged that every pair of villages has either one or no paths between each other. In addition, they don't have any food!

Faced with this issue, Korma has a plan. Korma will airlift food shipments to some of these villages and with the magic of friendship, she knows that the villagers are incredibly generous and will share food with other villages, if they're able to transport it.

Given the existing roads, Help Korma determine the minimal number of food shipments she will need to feed all the villages.

Input

The first line contains two integers, $$$1 \leq N \leq 10^5$$$ and $$$0 \leq M \leq 10^5$$$.

The next M lines contain a pair of integers $$$A$$$ and $$$B$$$, where $$$1 \leq A, B \leq N$$$ and $$$A \neq B$$$, denoting an existing road connecting villages $$$A$$$ and $$$B$$$.

Output

A single integer denoting the minimal number of food shipments needed to feed all villagers.

Example
Input
5 3
4 2
2 1
5 3
Output
2
Note

The provided roads are bidirectional and unique.

E. Air Moped
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A renowned airbender Tang invents a technique he calls the "Air Moped", where he spins up a perfect sphere and can ride on it. The bigger the sphere, the easier it is to ride on it and the faster it can go.

A student of his is geometrically inclined and wants to know how many lattice points (i.e. how many points $$$(x, y, z)$$$ where $$$x$$$, $$$y$$$ and $$$z$$$ are integers) are on the surface of some air moped that is created. Can you help him?

Input

One integer $$$1 \leq R \leq 7500$$$, the radius of the air moped.

Output

One integer $$$N$$$ denoting the number of integer coordinate points on the surface of the air moped.

Examples
Input
1
Output
6
Input
2
Output
6

F. Airship Merger
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Cabbage Corp recently bought two airship routes that were being flown with the exact same set of stations. Wanting to cut costs, Cabbage Corp decides that the two routes can be replaced by one route that service some subset of the stations in the same order that appears in both routes. Still wanting some customer satisfaction, however, they still want to maximize the number of stops kept in this new route. Can you help them find the maximum length of the route they can keep?

Input

First line contains $$$1 \leq N \leq 5 \cdot 10^5$$$, the number of stations serviced. The next two lines each contain $$$N$$$ integers $$$0 \leq a_i \lt N$$$, $$$a_i \neq a_j \forall i \neq j$$$ representing the order of stations serviced by each.

Output

Print one integer that corresponds to the length of the longest route common to both routes.

Examples
Input
5
0 1 2 3 4
4 1 2 3 0
Output
3
Input
5
4 1 0 3 2
2 0 4 3 1
Output
2

G. Circus Mayhem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mei and Kylie are bored at the circus, and decided they wanted to play with fire while Azuko was gone. There are $$$n$$$ flames currently in a line, and each flame has a size $$$s_i$$$. Mei and Kylie want to combine all the flames into 1, but since they aren't fire-benders, it costs a certain amount of energy to merge flames. Given two flames next to each other in line $$$s_i$$$ and $$$s_j$$$, it costs $$$s_i + s_j$$$ to merge the two flames, and then it is replaced with a flame that is $$$s_i + s_j$$$ in size at the same place in line.

Given $$$n$$$ flames and their sizes, determine the minimum cost to merge all the flames!

Input

The first line will contain $$$n$$$ $$$(1 \le n \le 200)$$$, the total number of flames.

The next line will each contain $$$n$$$ integers $$$s_i$$$ $$$(1 \le s_i \le 10^5)$$$, the size of the $$$i^{th}$$$ flame.

Output

A single integer detailing the minimum cost to merge all the flames together into one big flame.

Examples
Input
3
1 4 5
Output
15
Input
2
10 9
Output
19

H. Temple Door
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After journeying far and wide, Tang has finally made it to the legendary Fire Temple where he must speak with an ancient Avatar and learn the fate of the world. There's just one problem—the massive door into the inner sanctuary is sealed shut! Fortunately, it appears that there's a puzzle embedded in the door which, when solved, may trigger the unlocking mechanism.

There are six number dials embedded into the door, grouped into three pairs of digits, all separated by colons. The symbol of an hourglass engraved on a nearby wall indicates that the numbers refer to units of time—specifically, hours, minutes, and seconds, in the format $$$\texttt{hh:mm:ss}$$$.

Tang believes that if he sets the dials to show the time of a significant celestial event, then that will solve the puzzle and open the temple door. He has $$$N$$$ guesses about when that celestial event could be and wants to try them all. However, Tang notices that $$$D$$$ unique digits are missing from the dials, making it impossible to precisely set the dials to some of his guesses. Not to fear though, surely the ancient Fire Sages would have designed the door to accept the closest time setting possible that can be displayed on the dials.

Help Tang enter the inner sanctuary of the Fire Temple! For each time guess $$$g_i$$$ that Tang wants to try on the door, output the closest possible time that he will be able to display, given that some digits are missing from the dials.

Input

The first line of input contains an integer $$$D$$$ ($$$1 \leq D \leq 9$$$) denoting the number of digits absent from the puzzle dials. The next line contains $$$D$$$ space-separated integers, sorted in increasing order, which are the digits not available on the six dials.

Then the third line of input contains an integer $$$N$$$ ($$$1 \leq N \leq 10^4$$$) denoting the number of time guesses Tang wants to make. $$$N$$$ lines follow, each containing a guess index $$$i$$$ followed by one of Tang's time guesses $$$g_i$$$ in the six-digit format $$$\texttt{hh:mm:ss}$$$.

Output

For each of Tang's guesses in order, output one line containing the guess index $$$i$$$ followed by the closest possible time setting to $$$g_i$$$ that Tang will be able to input on the door, printed in the same format $$$\texttt{hh:mm:ss}$$$. In the case of a tie between closest settings, output the smaller time quantity.

Note, the values for hours, minutes, or seconds in Tang's guesses will lie in the range from $$$0$$$ to $$$59$$$, and similarly, no hours, minutes, or seconds value greater than $$$59$$$ may be set by Tang on the dials (the digits available on the individual dials prevent this).

Example
Input
2
8 9
4
0 38:15:51
1 32:06:35
2 23:31:47
3 04:05:47
Output
0 37:57:57
1 32:06:35
2 23:31:47
3 04:05:47