CodeRams Practice Problem Archive
001. Square The Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A number squared is defined as the number multiplied by itself. In this problem, given a number n, print the number $$$n^{2}$$$.

Input

The only line of input contains a positive integer n.

Output

Print the number $$$n^{2}$$$: n multiplied by itself.

Example
Input
6
Output
36

002. Triple Product
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Basic math operations are very important in programming applications. In this problem, your task is to calculate the product of two integers, multiplied by three.

Input

The first line of input contains a positive integer a no greater than 2000. The second line of input contains a positive integer b no greater than 2000.

Output

Print a single positive integer c: the product of a and b multiplied by 3.

Example
Input
3
5
Output
45

003. Triangle Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Triangles are one of the simplest geometric shapes. Equilateral triangles have the special property of all three of their sides being equal to each other. In this problem, you will be given a list of side lengths of equilateral triangles. You should find the sum of the perimeters of the triangles, given that the triangles are all equilateral.

Input

The first line of the input will contain a positive integer n indicating the number of triangles. Each of the next n lines will contain an integer t, indicating the side length of each triangle.

Output

Print one number, the calculated sum of the perimeters of the triangles.

Example
Input
3
3
4
6
Output
39
Note

In the example, the first triangle has a side length of 3, so it has a perimeter of 9. The second triangle has a perimeter of 12, and the third triangle has a perimeter of 18.

004. Polygons
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The sum of the angles in a triangle is 180, and the sum of the angles in a square is 360. In fact, the sum of angles in any polygon increases by 180 with each side added to the polygon. In this problem, you must figure out the sum of angles of a polygon, given its number of sides.

Input

The first line of the input contains a positive integer T indicating the number of test cases in the problem. The next T lines each contain a positive integer n (1 <= n <= 100): the number of sides of each polygon.

Output

Output T integers: the sum of the angles in each polygon.

Example
Input
4
3
4
5
6
Output
180
360
540
720

005. Fizz Buzz
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Take in a number from 1 through 1000, print Fizz if the number is divisible by 3, print Buzz if the number is divisible by 5, or FizzBuzz if the number is divisible by both. If none of these conditions are true, print nothing

Input

The only line of input contains a single positive integer N between 1 and 1000 inclusively

Output

Fizz, Buzz, FizzBuzz, or nothing

Examples
Input
1
Output

Input
3
Output
Fizz
Input
5
Output
Buzz
Input
15
Output
FizzBuzz

006. Distance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Find the distance between two 2D points. Remember that the distance formula is

$$$d = \sqrt{(x_{2} - x_{1})^2 + (y_{2}-y_{1})^2}$$$

math.sqrt will calculate the square root of a number. Also, you also have to add the line import math at the top of the program.

Input

The first two lines contain the X and Y coordinates of the first point respectively. The second two lines contain the X and Y coordinates of the second point respectively. Each coordinate will have an integer value between -1000 and 1000, inclusive.

Output

A double N representing the distance between the two points

Examples
Input
1
1
2
2
Output
1.4142135623730951
Input
1
1
1
1
Output
0.0

007. Clock Seconds
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a clock that tells time in the usual way: hours, minutes, and seconds. When you wake up in the morning, you want to figure out how many seconds you slept for. Conveniently, you fell asleep the night before at exactly 12:00 AM. Remember that there are 60 seconds in a minute and 60 minutes in an hour.

Input

The first line of input contains a positive integer h indicating the current number of hours displayed on the clock (1 <= h <= 11). The second line of input contains a positive integer m indicating the current number of minutes displayed on the clock (0 <= m <= 59) The third line of input contains a positive integer s indicating the current number of seconds displayed on the clock (0 <= s <= 59) The fourth line of input contains a string a indicating whether it is currently the morning or the afternoon. a will be either AM or PM. You are guaranteed to have slept for less than 24 hours. Also, note that h will never equal 12.

Output

Print a single positive integer t: the number of seconds of sleep that you got.

Example
Input
6
50
34
AM
Output
24634

008. N-Dimensional Distance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula.

The n-dimensional distance formula can be expressed as

$$$d(p,q) = \sqrt{(q_{1}-p_{1})^2 + (q_{2}-p_{2})^2 + ... + (q_{n}-p_{n})^2}$$$

or in other terms:

$$$\sqrt{\sum_{i=1}^{n} (q_{i}-p_{i})^2} = d$$$

Remember that math.sqrt will calculate the square root of a number (you also have to add the line import math at the top of the program).

Input

The first line contains the dimension D between 2 and 500. Then, D test cases will follow.

Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.

Each of these values is an integer between -5000 and 5000, inclusive.

Output

A decimal number N representing the distance between the two points. Do not round your answer.

Examples
Input
2
1
1
1
2
Output
1.0
Input
3
7
4
3
17
6
2
Output
14.866068747318506
Input
4
-2367
-2873
-4279
-2321
-1302
-1341
-2893
651
Output
4080.5951771769764

009. Hello CodeRams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A hello world program is an essential starting point for all coders. In this problem, write a program to print out "Hello CodeRams".

In Python, you can print text using the print command. So, for this problem, type print("Hello CodeRams").

You can download Python here.

Output

Output "Hello CodeRams"

Example
Input
there is no input for this problem
Output
Hello CodeRams

010. Points per Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your favorite basketball player is the leading scorer in the country, and you want to know exactly how good they are. Points per game is measured as points divided by games played, and is used to rank leading scorers in basketball.

Input

The first line of input contains a positive integer p indicating the total points scored by the player so far during the season. The second line of input contains a positive integer g indicating the total games played by the player so far during the season.

Output

Output one decimal number ppg, the player's current points per game. This value can be calculated as p / g

Examples
Input
78
7
Output
11.142857142857142
Input
89
15
Output
5.933333333333334

011. Ski Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your favorite ski resort has a certain number of easy trails, more difficult trails, most difficult trails, and expert-only trails. Given these values, find how many trails there are at the ski resort. Note that the same trail will never be two different difficulties.

Input

The only line of input contains 4 space-separated integers, each representing the number of easy trails, more difficult trails, most difficult trails, and expert-only trails, respectively.

Output

Print one positive integer: the total number of ski trails at the mountain.

Example
Input
20 16 13 6
Output
55

012. Easy Exponentials
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the last contest, you were asked to find the last digit of a very large number. This time, you are asked to find the entirety of a much smaller number: your task is to find the first number taken to the power of second number. A brute force approach does work here.

Input

The only line of input contains two space-separated integers n and k, 1 <= n, k <= 10.

Output

Output a single integer: the number $$$n^{k}$$$.

Example
Input
3 5
Output
243

013. Resistors in Parallel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When two resistors with resistances a and b are parallel in an electronic circuit, their equivalent resistance is calculated as (a * b) / (a + b). Given the resistances of two resistors, calculate their equivalent resistance.

Input

The first line of input contains a single positive integer a: the resistance of the first resistor. The second line of input contains a single positive integer b: the resistance of the second resistor.

Output

Output a single positive decimal number r: the equivalent resistance of the two resistors, calculated using the above formula.

Examples
Input
60
40
Output
24.0
Input
80
70
Output
37.333333333333336

014. Labyrinth
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You find yourself stuck in a labyrinth and don't know your way out! There are several dangerous traps placed throughout the labyrinth. You need to find a way out, but first you need to know how many traps there are in the labyrinth.

Input

You will be 2D grid with dimensions n by m. x denotes a trap, and . denotes no trap. The first line of input will contain two space-separated integers n and m, representing the dimensions of the grid. The next n lines will each contain m characters representing a row of the labyrinth.

Output

Output a single integer t: the total number of traps in the labyrinth.

Example
Input
4 5
x....
.x.x.
x..x.
x.xx.
Output
8
Note

Hint: use a 2D array!

015. Subway System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're going to a large city with a complex subway system. You need to find out how many subway lines you will take from the airport to your hotel. Given a list of stations that each subway line stops at, print the minimum number of lines you need to take to get from the airport to your hotel.

Input

The first lines contains one integer n, representing the number of different lines in the subway. The next n lines contain an arbitrary number of space-separated strings, each representing the various stations that the subway lines stop at. The airport's station will be Airport in the station list, and the hotel's station will be Hotel. There will not be more than 1000 distinct station names.

Output

Output one positive integer l: the minimal number of different subway lines that you should take to reach the hotel station from the airport station.

Examples
Input
4
Airport CityCenter WestStation
CityCenter Library EastStation
WestStation Countryside
Countryside Library Hotel
Output
3
Input
5
Airport TownHall
TownHall Courthouse
Courthouse WestStation
WestStation NorthStation
TownHall Hotel
Output
2
Note

A note from the creator of the problem (Xavier): This problem is really hard. I created the problem and it took me over an hour to come up with a valid solution. Please only attempt this problem if you know what you're doing.

016. Gravity Vehicle Testing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While testing your gravity vehicle for Science Olympiad, you have decided to test the vehicle both on Earth, and on Mars. You want to know the gravitational constant of the planet that you are currently testing the vehicle on. You are given that the gravitational constant on Earth is 9.807 m/s^2 and the gravitational constant on Mars is 3.711 m/s^2.

Input

The only line of input contains a single string s: either "EARTH" or "MARS", which indicates the planet that you are currently testing the gravity vehicle on.

Output

Output a single decimal number: the gravitational constant of the planet that you are testing the vehicle on.

Examples
Input
EARTH
Output
9.807
Input
MARS
Output
3.711

017. Chem Lab: Cross the Charges
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While preparing for Chemistry Lab in Science Olympiad, you are taught to "cross your charges" when calculating the molecular coefficients given the charges: using the charges of two bonded ions, you swap the two values to obtain the molecular coefficients. For example, a molecule made of two ions with charges of 4 and 3 would have coefficients of 3 and 4, respectively.

Input

The only line of input contains two space-separated integers a and b representing the charges of a and b, respectively.

Output

Output two space-separated integers c and d: the coefficients of each ion given their charges. These can be calculated by swapping a and b (crossing the charges).

Example
Input
2 3
Output
3 2

018. Machines
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In mechanical engineering, the primary tool used to measure the energy amplified into a simple machine or a compound machine is called a concept known as the Mechanical Advantage, which signifies the ratio of the energy put into a machine, and the amount of force it outputs.

In one type of simple machine, the lever, mechanical advantage will be calculated by the lengths of the two sides, with the position of the fulcrum determining the length of the two sides. A diagram and a simplified formula of this process has been given below:

where A is the length of the side where Force 1 is being applied, and B is its respective counterpart.
Input

Your objective is to find the mechanical advantage of a lever, given side A and side B. The first positive integer n is the amount of inputs that will follow.

Example
Input
4
10 5
2 3
7 5
18 7
Output
2.0
0.6666666666666666
1.4
2.5714285714285716

019. Boomilever
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are working on your Boomilevers for Science Olympiad, an event that requires the breaking of various "boomilevers". For this problem, you are given a list of numbers representing the force you applied to each boomilever in pounds. You know a certain number of pounds that will always break any boomilever. Given these values, calculate how many of your boomilevers have broken so far.

Input

The first line of input contains two space-separated integers n and m representing the number of boomilevers, and the force required to break a boomilever, respectively. The next line contains n space-separated integers representing the force applied to each boomilever.

Output

Output a single positive integer b: the number of boomilevers that have broken so far.

Example
Input
5 30
20 25 30 35 40
Output
3

020. Codebusters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Encryption has been an essential tool throughout history and the modern world. Essentially, encryption is the practice of encoding messages, for the purposes of securing the message's confidentiality from other parties.

Input

Your Job is to create a basic encryption method, where if we cast characters of a word to an integer, the odds will be swapped with its following even character, where the first positive integer n are the number of cases following it.

Example
Input
4
ABCDEFG
GAME
RAMBOOK
EHLLO
Output
BADCFEG
AGEM
ARBMOOK
HELLO
Note

(If the word is of an odd length, the last character should be the same)

021. Hovercraft
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While testing your hovercraft for Science Olympiad, the hovercraft flew over a pile of boxes in your basement and traveled a total distance of n feet. Given that the boxes are in a rectangular shape, and that the hovercraft took off and landed at opposite corners of the pile of boxes, calculate how far you will have to walk to pick up the hovercraft. You are also given the length of one side of the pile of boxes.

Input

The first line of input contains a single positive integer n: how far the hovercraft traveled in feet. The second line of input contains a single positive integer m: the length of one side of the file of boxes.

Output

Output a single positive integer w: how far you will have to walk to retrieve the hovercraft.

Examples
Input
10
6
Output
14.0
Input
14
13
Output
18.196152422706632

022. Detector Building
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Uh oh! You are working on building an analog thermometer using nonlinear components, so how can you calibrate your temperature sensor with test data? You can use a form of nonlinear regression in the form of the Steinhart-Hart equation, an equation designed to explain the relation between the electrical resistance of a solid and its temperature. While this task may sound difficult, it is actually quite simple using the equation. The Steinhart-Hart equation itself has three calculated constants(A,B, and C), and takes in a value R, which is the resistance of the metal.

The equation is represented as:

$$$\frac1T = A + B(lnR) + C(lnR)^3$$$

This equation is useful for the process of actual temperature determination, but we still need to calculate the constants A, B, and C before we can use it. To find these values, we must first find three resistance to temperature data points, which are usually discovered through experimentation. For this problem, these data points will be provided and you will be required to find the A, B, and C constants. The process of finding these values involves calculating a series of equations. These equations are as follows:

$$$L_1 = lnR_1$$$

$$$L_2 = lnR_2$$$

$$$L_3 = lnR_3$$$

$$$Y_1 = \frac{1}{T_1}$$$

$$$Y_2 = \frac{1}{T_2}$$$

$$$Y_3 = \frac{1}{T_3}$$$

$$$\gamma_2 = (Y_2-Y_1)/(L_2-L_1)$$$

$$$\gamma_3 = (Y_3-Y_1)/(L_3-L_1)$$$

$$$C = ((\gamma_3-\gamma_2)/(L_3-L_2))*(L1+L2+L3)^{-1}$$$

$$$B = \gamma_2-C(L_1^2+L_1L_2+L_2^2)$$$

$$$A = Y_1 - L_1(B+L_1^2C)$$$

For this problem, you will be given R1, R2, R3, T1, T2, and T3. You are tasked with then calculating the value for A, you will not have to return B and C considering that a valid number for A will imply correct values for B and C.

Input

The double values T1, T2, T3, R1, R2, and R3 will be each provided sequentially on a separate line.

Output

A double representing the value of A

Example
Input
1
50
100
50000
25000
15000
Output
72.6660018932261
Note

Do not worry about precision or rounding, as there is some tolerance in the solution checking. Also, remember that you can calculate the natural log of a number using math.log in Python or Math.log in Java. In addition, some of the provided equations require variables from previous equations, so you will need to solve them in order.

023. Ping Pong Parachute
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are currently working on Ping Pong Parachute for Science Olympiad and you want to test how high your rocket is going. The only problem is that your dog ate your altimeter, so now you can no longer use it to measure the rocket's height. Luckily you happen to have a PhD in physics and you can just calculate how high the rocket will go. Not only do you have a PhD, but you also have a speedometer, so you can see the speed of the rocket when it takes off(Initial velocity). The equation $$$V_f^2 = V_i^2 + 2ad$$$ to represent the height of the rocket.

$$$V_i$$$ = initial velocity

$$$V_f$$$ = speed of the rocket at its highest point (Hint: Its not moving)

a = acceleration due to gravity (-9.8 $$$m/s^2$$$)

d = height of the rocket

Input

A double representing the initial velocity of the rocket

Output

The predicted height of the rocket

Example
Input
7.78
Output
3.0881836734693877

024. Missed Basketball Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While you were at science olympiad, you missed your favorite basketball team's biggest game of the year. You don't know the score, but you know the number of baskets, three-pointers, and free throws made by each team. Your task is to figure out which team won the game based on the given information. Recall that a three-pointer is worth 3 points, a regular basket is worth 2 points, and a free throw is worth one point. The number of baskets made includes three-pointers and two-pointers, but not free throws.

Input

The first line of input contains two space-separated strings: the names of the two teams that played in the basketball game. The second line of input contain two space-separated integers representing the number of baskets made by each team, respectively. The third line of input contain two space-separated integers representing the number of three-pointers made by each team, respectively. The fourth line of input contain two space-separated integers representing the number of free throws made by each team, respectively.

Output

Output a single string: the team that won the game. It is guaranteed that there is a winner, i.e. the score at the end of the game is not a tie.

Example
Input
Syracuse Duke
35 31
11 9
14 20
Output
Syracuse
Note

In the example, Syracuse scored 95 points, and Duke scored 91 points. This game occurred on January 14, 2019.

025. Write It, Do It
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are the "do-er" for the Science Olympiad event "Write it, Do it", which means that you have to interpret your event partner's written description of an object and replicate the object based on the description. Unfortunately, your partner is bad at spelling and misspelled a critical word in the description. Your task is to figure out which word your partner most likely meant to write.

Input

The first line of input contains a string s: the word misspelled by your partner. Assume that your partner did not add or remove any letters; they only replaced letters with incorrect ones. The next line contains a single positive integer n indicating the number of possible valid words that your partner could have meant to write. Each of the next n lines contains each of these words. There is guaranteed to be at least one word of the same length as the misspelled word.

Output

Output a single word w: the word in the dictionary of possible words closest to the misspelled word. "Closeness" is defined as the minimum number of different characters. If there is a tie, choose the word that comes first in the given dictionary of words.

Example
Input
deat
6
fate
feet
beat
meat
deer
dean
Output
beat

026. Competition Rules
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Making the rules for a competition is an important part of an online competition. For this problem, you will read the rules in the input, and print them out to the screen.

To take in input, you can use the input() command. To print out exactly what is inputted, you would do print(input()).

For this problem, you'll need to print "Competition Rules:", AND the input, on two separate lines. You should use two separate print statements.

Input

The input consists of a single line: the rules for the competition

Output

Output two lines. The first line should contain the string "Competition Rules:" (no quotes) The second line should re-print the rules from the input.

Example
Input
This is a competition rule
Output
Competition Rules:
This is a competition rule

027. Money Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have made $$$n$$$ payments in the past year, and you would like to figure out how much money you have spent in total, in cents.

Input

The first line of input contains a positive integer $$$n$$$, indicating the number of payments that you have made. The next $$$n$$$ lines each contain a positive integer $$$m$$$, indicating the amount that you paid in cents.

Output

Output a single positive integer $$$s$$$: the amount of money that you have spent in total, in cents.

Example
Input
5
7
11
18
27
20
Output
83

028. Funny Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You consider a number to be funny if it is divisible by both 5 and 7. Given a number, figure out whether or not it is a funny number.

Input

The only line of input contains a single positive integer n: the number

Output

Output "YES" if the number is funny, otherwise "NO". (no quotes)

Examples
Input
21
Output
NO
Input
35
Output
YES

029. Goooooooooal!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your favorite soccer announcer will always say "gooooal" for a very long time after a team scores. You have a "speech to text" tool that transcribed the announcer's words. Given his written down goal reaction, figure out exactly how many "o" letters are in it.

Input

The only line of input contains a single string $$$s$$$: the announcer's reaction to a team's goal.

Output

Output a single integer $$$n$$$: the number of "o" letters in the given string.

Example
Input
goooooooooal
Output
9

030. World Cup (Easier Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While watching the world cup, you wonder how many points your team has in the group stage. Recall that during the group stage teams are awarded three points for a win, one point for a tie, and zero points for a loss. For this problem, figure out how many group stage points your team has based on their record (wins, losses, and ties).

Input

The only line of input contains three integers separated by hyphens (-). Each of these values represents how many wins, losses, and ties your team has had so far during the group stage, respectively.

Output

Output a single integer p: the number of group stage points that your team currently has.

Example
Input
5-3-2
Output
17

031. 2001: A Space Odyssey
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While listening to an orchestra fail to play the music from 2001: A Space Odyssey, you wonder what the lowest positive number (other than one) that divides 2001 is. It turns out to be 3 (2001 = 3 * 667). Write a program to find this value for any composite number $$$n$$$.

Input

The only line of input contains a single positive composite (not prime) integer $$$n$$$, greater than one: the number used in your calculations.

Output

Output a single positive integer k: the smallest positive number (other than one) that divides $$$n$$$.

Example
Input
2001
Output
3

032. Prison Break
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Unfortunately, you have been sent to prison because you solved too many problems at CodeQuest 2021. Now, you're trying to break out. Your cell has a combination lock with $$$n$$$ dials. You're planning to try all of the possible combinations of the lock, and you want to know how many possible combinations the lock has.

Input

The first line of input contains a positive integer $$$n$$$: the number of dials on the lock. The next $$$n$$$ lines each contain two space-separated integers: the lower and upper limits of each lock dial. For example, if the lower and upper limits were $$$3$$$ and $$$7$$$, respectively, then the lock dial could turn to 3, 4, 5, 6, or 7.

Output

Output a single integer $$$c$$$: the total number of possible lock combinations.

Examples
Input
4
2 10
3 9
11 16
5 8
Output
1512
Input
3
1 2
1 3
11 12
Output
12

033. Free Throws
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While watching a basketball game, you wonder what your team's total free throw percentage is. You are given how many free throws each player on your team has made and attempted. Given these values, calculate your team's free throw percentage.

Input

The first line of input consists of a positive integer $$$n$$$: the number of players on your team. The next $$$n$$$ lines consist of two space-separated integers: how many free throws each player has made and attempted, respectively.

Output

Output a single decimal number, representing your team's free throw percentage during the game. Round your answer to two decimal places.

Example
Input
4
1 5
3 4
7 7
6 8
Output
70.83

034. Broken Ladder
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a broken ladder. Your ladder would normally have $$$n$$$ rungs numbered from 1 to $$$n$$$, but unfortunately some of the rungs have broken off. You can only climb up the ladder if the minimum gap between rungs is less than or equal to some value $$$k$$$. For example, if $$$k$$$ = 1, if the ladder was broken at all, you would not be able to climb the ladder.

Input

The first line of input contains two space-separated positive integers n and k: the number of rungs remaining on the ladder, and the largest gap in rungs that you can climb over, respectively. The second line of input contains a sorted list of $$$n$$$ integers greater than or equal to 1: the positions of the rungs of the ladder. You can assume that the first and last rungs of the ladder are not broken.

Output

Output "YES" if you can still climb the broken ladder, otherwise "NO". (no quotes)

Examples
Input
6 2
1 2 3 5 6 8
Output
YES
Input
5 3
1 3 8 12 13
Output
NO

035. Distinct Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a list of numbers. You want to figure out how many distinct (different) numbers are in the list. For example, the list [1, 2, 3, 4, 4, 5, 5] has 5 distinct numbers.

Input

The first line of input contains a single positive integer $$$n$$$: the number of items in the list. The next line contains $$$n$$$ space-separated integers: the list.

Output

Output a single positive integer $$$d$$$: the number of distinct numbers in the list.

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

036. Speed Limits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are going on a long road trip, and want to know what the maximum speed limit is in each state that you are traveling through.

Input

The first line of input contains a positive integer S, indicating the number of states that are in the database. The next S lines each contain a string representing the name of the state, a space, and an integer representing the maximum speed limit in that state. Names of states will not contain spaces. The next line of input contains a positive integer T indicating the number of test cases that follow. Each test case will consist of a state name.

Output

For each of the T test cases, output a single integer: the maximum speed limit in the given state, from the database.

Example
Input
6
NewYork 65
Texas 85
Pennsylvania 70
Massachussets 65
Washington 75
Hawaii 60
5
NewYork
Pennsylvania
NewYork
Texas
Hawaii
Output
65
70
65
85
60

037. Practice Katanas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You've just bought a set of practice katanas, which have an item number of 1101-1816. While staring at this item number, you wonder what the LCM (Least Common Multiple) of 1101 and 1816 is.

To calculate the LCM of two numbers, you can multiply the two numbers together, and divide this result by the GCD (Greatest Common Divisor) of the two numbers. For example, let's take the numbers 60 and 72. Their GCD is 12 (12 is the greatest number that divides both numbers), their product (60 x 72) is 4320, and their GCD is 4320 / 12 = 360. To calculate the GCD of two numbers, you can use this recursive formula:

gcd(a, b) = a, if b = 0

otherwise, gcd(a, b) = gcd(b, a mod b)

Input

The only line of input contains two positive integers $$$a$$$ and $$$b$$$.

Output

Output a single positive integer $$$n$$$: the LCM (Least Common Multiple) of $$$a$$$ and $$$b$$$.

Examples
Input
2 4
Output
4
Input
1101 1816
Output
1999416

038. Unshuffle the Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a shuffled deck of cards, and your task is to return them to sorted order. Sorted order involves the cards being sorted first by their numbers, and if their numbers are equal, being sorted by their suit. In the sorting, clubs comes before diamonds, which comes before hearts, which comes before spades. The deck may not be complete, i.e. some cards may be missing. Assume that aces are always the highest possible card for this problem.

Input

The first line of input contains a single integer $$$n$$$ (1 < $$$n$$$ <= 52): the number of cards in the deck. The next line contains $$$n$$$ space-separated blocks, each representing a card. Each block will contain one character representing the value of the card, and a second character representing the suit of the card. No "10" cards will be given in the input.

Output

Output $$$n$$$ space-separated blocks: the deck, after sorting is complete.

Example
Input
10
8C 7D QH QD QC KD 2H AD 3D 7H
Output
2H 3D 7D 7H 8C QC QD QH KD AD

039. Number Code (Easier Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are using a code where letters in words map to digits in the following way:

0 = o

1 = i

3 = e

4 = a

5 = s

7 = t

(the other digits will not be used in this problem)

You've found a sequence of numbers, and you want to find which words the numbers correspond to using the code described above. For this problem, assume that the only letters in each word are the ones that map to numbers.

Input

The first line of input contains a positive integer T indicating the number of test cases that follow. Each of the next T lines contains a sequence of space-separated numbers consisting of the digits 0, 1, 3, 4, 5, and 7.

Output

Output T lines, with each line consisting of the decoded sequence of words using the code described above.

Example
Input
4
50 50
45 15
1 473 4 74573
17 15 70 517
Output
so so
as is
i ate a taste
it is to sit

040. Valid Sudoku
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sudoku is a popular number puzzle involving placing digits (1-9) in a 9 by 9 grid. A sudoku is considered valid if all of the following are true:

-All digits are integers from 1 to 9

-No number occurs in the same row twice

-No number occurs in the same column twice

-No number occurs in the same 3 by 3 box twice.

Given a sudoku board, print whether or not it is valid.

Input

The input consists of nine lines, each containing nine space-separated integers ranging from 1 to 9.

Output

If the sudoku is valid, output VALID, otherwise output INVALID.

Examples
Input
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 1 5 6 4 8 9 7
5 6 4 8 9 7 2 3 1
8 9 7 2 3 1 5 6 4
3 1 2 6 4 5 9 7 8
6 4 5 9 7 8 3 1 2
9 7 8 3 1 2 6 4 5
Output
VALID
Input
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
Output
INVALID

041. World Cup (Harder Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While watching the world cup, you wonder how many points each team has in the group stage. Recall that during the group stage teams are awarded three points for a win, one point for a tie, and zero points for a loss. For this problem, you're given a history of the games between all of the teams, and you must figure out how many group stage points each team has.

Input

The first line of input contains a single integer $$$n$$$: the number of games played. The next $$$n$$$ lines of input consist of two space-separated integers representing the two teams that played. After the integers on each line, one character will follow (after a space) indicating the result of the game. If the character is "W", the first team beat the second team. If the character is "T", the teams tied. (the character will never be "L", i.e. the first team will never lose)

Output

Output $$$m$$$ lines. On each line, print each team's name, and a single integer $$$p$$$: the number of group stage points that the team has. The teams should be sorted in order of their scores; if there is a tie, the tied teams should be sorted alphabetically.

Example
Input
6
Germany Portugal W
UnitedStates Ghana W
Germany Ghana T
UnitedStates Portugal T
Germany UnitedStates W
Portugal Ghana W
Output
Germany 7
Portugal 4
UnitedStates 4
Ghana 1

042. Number Code (Harder Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Note: this is a harder version of a previous problem in the contest.

You are using a code where letters in words map to digits in the following way:

0 = o

1 = i

3 = e

4 = a

5 = s

7 = t

(the other digits will not be used in this problem)

You've found a sequence of numbers, and you want to find how many words the numbers correspond to using the code described above.

Additionally, for this problem, assume that any letters in the original word that did not map to a letter in the code were simply encoded as blanks. Thus, a number sequence can potentially map to multiple words. Thus, you are given a dictionary of words, and you are tasked with figuring out which words in the dictionary map to the given number sequence.

Input

The first line of input contains a positive integer D: the number of words in the dictionary. The next D lines each contain a single word: each dictionary entry. The words will be sorted alphabetically. The next line of input contains a positive integer T indicating the number of test cases that follow. The next T lines each contain a single number sequence (not separated by spaces).

Output

For each test case, first print a positive integer K: the number of single words in the dictionary that map to the number sequence using the code described above. Then, print K lines: each word, printing the words in alphabetical order (remember that the given dictionary already is in alphabetical order).

Example
Input
8
fantastic
funtastuc
hasty
taste
tasted
tastes
tasty
untasty
3
457
7457
74573
Output
1
hasty
3
funtastuc
tasty
untasty
2
taste
tasted

043. Low-Budget Flight Paths
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your team qualified for the national finals of CodeQuest 2021*, and you need to figure out which flights you need to take to get to the location of the finals. However, you have a limited budget for the whole trip. Figure out the best route for your team to go to the specified location of the competition, given the possible flights and their times. If multiple routes are possible, choose the one that has the lowest price. Assume there are no layovers in airports, i.e. all of the time spent on a journey is spent on the airplanes. Your starting location is always "Syracuse"

Input

The first line of input contains a string $$$s$$$: the location of the CodeQuest competition. The next line contains two space-separated integers $$$n$$$ and $$$b$$$: the number of flights, and your total budget, respectively. The next $$$n$$$ lines each describe one flight. Each line contains three space-separated items: two strings, representing the start and end cities of the flight, and one integer, representing the price. There will always be at least one flight departing from "Syracuse", and at least one flight arriving in "Syracuse".

Output

If it is impossible to go to the CodeQuest finals and back with your budget, output "IMPOSSIBLE" (without the quotes). Otherwise, output two space-separated integers $$$n$$$ and $$$t$$$: the number of flights that you need, and the total price, respectively. Then, output $$$n$$$ lines, each containing the start and end cities of each flight that you are going to take, separated by an arrow (->).

Examples
Input
SanFrancisco
9 120
Syracuse NewYork 5
Syracuse Detroit 5
Syracuse Atlanta 20
Atlanta Dallas 50
Dallas SanFrancisco 30
Detroit Chicago 1
Chicago SanFrancisco 30
SanFrancisco NewYork 10
NewYork Syracuse 10
Output
5 56
Syracuse -> Detroit
Detroit -> Chicago
Chicago -> SanFrancisco
SanFrancisco -> NewYork
NewYork -> Syracuse
Input
NewYork
3 10
Syracuse Detroit 9
Detroit NewYork 1
NewYork Syracuse 2
Output
IMPOSSIBLE
Input
SanFrancisco
8 1000
Syracuse SanFrancisco 100
NewYork StLouis 5
StLouis Portland 5
Syracuse NewYork 5
Portland LosAngeles 5
LasVegas SanFrancisco 5
LosAngeles LasVegas 5
SanFrancisco Syracuse 1
Output
7 31
Syracuse -> NewYork
NewYork -> StLouis
StLouis -> Portland
Portland -> LosAngeles
LosAngeles -> LasVegas
LasVegas -> SanFrancisco
SanFrancisco -> Syracuse
Note

*CodeQuest does not actually have national finals

044. Yoda Translator
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Yoda tends to confuse people with his irregular syntax. Write a program that takes in a string and switches the first half of the words with the second half.

Input

A line will contain a string.

Output

For the input, your program must print that string with the first and second half of the words switched.

Example
Input
reverse this sentence you have to
Output
you have to reverse this sentence
Note

Assume the input will always have an even number of words.

045. Planet Omicron Persei VIII
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are on planet Omicron Persei VIII and you find that the force due to gravity on you is Fg newtons, you also know that you have a mass of M. Using this information you want to know how long it will take for an object to fall (time T in seconds) a distance D starting from rest (Vi speed when the object is initially released). Using the following equations Fg = MG and D = ViT+½GT^2.

Input

The first line will be the force due to gravity of you (Fg), the second line is your mass (M) and the third is the distance the object is going to fall (D).

Output

Print the time that it will take for the object to fall d meters in the following format: "It will take the object T seconds to fall D meters". Your answer should also be rounded to the nearest tenth.

Example
Input
500
70
10
Output
It will take the object 1.7 seconds to fall 10.0 meters
Note

If you are getting confused by the Vi part here is a hint. When an object is at rest, meaning not moving, what is its speed.

046. Binary Math
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given two strings that represent binary numbers, return the sum of the 2 numbers in binary.

Input

The first line will contain the first binary number and the second line will contain the second binary number.

Output

Print the sum of the two numbers in binary.

Example
Input
101
11
Output
1000
Note

If you need help understanding how to read numbers in binary, you can check out the following link: https://medium.com/@LindaVivah/learn-how-to-read-binary-in-5-minutes-dac1feb991e

047. Who will win
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Two runners are racing against each other in the 400 meter dash and you want to know who will win. The current distance covered by each runner(meters) and the speed (meters per second) will be given for each runner. Return whether the first or the second runner will end up winning the race assuming they travel at the speed throughout the remainder of the race.

Input

The first line will contain a sentence describing the first runner and the second will describe the second. The following format will be used: "runner X is traveling at Y meters per second and has already covered Z meters"

Output

Print which runner will win the race in the following format: "Runner X wins"

Example
Input
runner 1 is traveling at 10.5 meters per second and has already covered 100.0 meters
runner 2 is traveling at 9.3 meters per second and has already covered 300 meters
Output
Runner 2 wins

048. Basic Math
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your 5 year old cousin needs your help with some basic math. Write a program for him to do addition and subtraction.

Input

The one and only line that you will be given is a math equation that uses addition and subtraction.

Output

Print the following "(original equation) = (answer)".

Example
Input
1 + 5 + 7 - 2 =
Output
1 + 5 + 7 - 2 = 11

049. Decryption
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A monoalphabetic cipher is a type of encryption where each letter in the alphabet correlates to another letter in the alphabet. For this question you need to decrypt a piece of text given the key used to encrypt it and the encrypted message.

Input

The first line will be the key needed to decrypted the text and the second line will be the encrypted message. For the key that is given, the first letter of the key correlates to A, the second letter in the the key goes to B, then C and so on.

Output

Print the following: "Decrypted text: (Decrypted text)"

Example
Input
azertyuiopqsdfghjklmwxcvbn
miol ligwsr zt ktarazst mtvm
Output
Decrypted text: this should be readable text

050. The Array Checker-inator!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given two arrays of integers, check if they are equal... But, if the arrays can be made equal through the removal of duplicates or sorting, they are equal.

Input

The first line will represent the elements, n, in the first array. Then, you will be given n integers inputted on their own lines. After that, another integer will be inputted, which represents the elements, m, in the second array. Then m integers will follow, all being inputted on separate lines.

Output

Print "YES" (without the quotes) if you these arrays are equal (or if they are equal after removing duplicates and sorting them), or "NO" (without the quotes) if the arrays cannot be made equal.

Examples
Input
3
1
2
3
5
1
1
2
2
3
Output
YES
Input
4
1
2
3
4
3
1
2
7
Output
NO

051. The Convergence of Two Tetra-sided Polygons, Known as Rectangles
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You will be given two opposite corners of two separate rectangles and you must determine whether they intersect or not.

Input

The first line will contain 4 integers separated by spaces, which respectively represent the x-coordinate and y-coordinate of a corner of the rectangle and the x-coordinate and y-coordinate of the opposite corner. The second line will contain another 4 integers that represent the same coordinates but for the second rectangle.

Output

Print "YES" (without the quotes) if the rectangles intersect or "NO" (without the quotes) if the rectangles do not intersect.

Example
Input
-5 -5 5 5
4 4 8 8
Output
YES
Note

The first rectangle has one corner located at (-5,-5) and the opposite corner at (5,5). The second rectangle has one corner located at (4,4) and the opposite corner at (8,8). These rectangles intersect, thus "YES" is printed

Also, if the rectangles lie on top of one another, they are intersecting. If one is inside the other and their perimeters do not touch, then they are not intersecting.

052. Passing Notes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You and your friend are passing notes in class, but to secure the safety of your notes you both decide to scramble the words. Your friend is going to pass you the first note, so that you can figure out the type of scramble that was used. Use the example test case below to figure out how the words where scrambled and write a program that will scramble words in the same way.

Input

The only line that you will be given will the plain unscrambled note that you want to send.

Output

Print the scrambled version of the note, so that you can send a message to your friend safely.

Example
Input
good luck trying to figure out how this was scrambled :)
Output
): delbmarcs saw siht woh tuo erugif ot gniyrt kcul doog

053. Tic-Tac-Toe
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a tic-tac-toe board, return if you can win the game in one move or not.

Input

The first line will be the side that you are on, X or O. The next three lines are the are the current board.

Output

If you can win print "Yes you can.", otherwise print "No you can't."

Example
Input
X
XOX|
XO |
O X|
Output
Yes you can.

054. When is my meeting?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a meeting on a specific date. Given the current date and the date of the meeting, return how many days there are until the meeting.

Input

The first line will contain the first date and the second line will contain the second date. They will be given in the following format: "month day, year"

Output

If the meeting is on that date print "It is today", if it has passed print "Sorry you are X days late", otherwise print "There are X days until your meeting".

Example
Input
July 5, 2019
March 10, 2020
Output
The meeting will occur in 248 days.
Note

You do not need to account for leap years.

055. Train-ficiency
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A train station needs your help to maximize its efficiency. The train station can only have 100 train carts parked on a track at once, and it is imperative that the tracks are fully filled as to maximize profit. Given a list of trains and their lengths (number of train carts) print the pairs of trains that will most effectively fill the station.

Input

You will be given 4 integers separated by spaces. Each of these integers represents the number of cars on a train.

Output

Print the pairs of trains.

Examples
Input
25 50 50 75
Output
Train 1 and Train 4
Train 2 and Train 3
Input
35 24 65 76
Output
Train 1 and Train 3
Train 2 and Train 4
Note

In the first case, Train 1 must be combined with Train 4, as 25 cars plus 75 cars adds up to 100 cars. Train 3 must be combined with Train 4, as 50 cars plus 50 cars equals 100 cars.

Also, assume that there is always a way to fill each track with 100 trains. Make sure the output format puts the trains in ascending order (i.e. Train 1 and Train 3, not Train 3 and Train 1).

056. Stopwatch issues
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You like to use your stopwatch all the time, but there is one major problem with it. The stopwatch only displays seconds, so when it says 472 seconds have passed you have no idea what that means. Given a time in seconds display the years, days, hours, minutes and seconds that have passed.

Input

The first line is number of seconds that have gone by.

Output

Print the time that has passed in the following format. "X years, X days, X hours, X minutes and X seconds". If the value for any time is 0, do not include it. Also be sure to watch out for plurals and using "and". If the time is 0, say "now" .

Examples
Input
1
Output
1 second
Input
98753213
Output
3 years, 47 days, 23 hours, 26 minutes and 53 seconds

057. Minecraft Prank
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are currently playing minecraft with your friends when you get a brilliant idea for a prank, you want to fill his entire house with sand. Given some information that represents the dimensions of your friend's house return the number of blocks of sand needed to fill it up.

Input

The first line will contain a number that is the height of the house. The next line will be the number of lines that will be used to display the foundation of the house. The following lines will be X's that represent the foundation of the house

Output

Print an integer that is the number of blocks needed to fill the house.

Example
Input
5
7
XXXX
XXXX
XXXX
XXX
XXXX
XXXX
XXXX
Output
21
Note

The ceiling, floor, and walls are included within the dimensions of the house so be mindful of that. You can also assume the ceiling is flat.

058. Switch Case
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Take a single string S as input, then make all capital characters lowercase and all lowercase characters capital.

Input

A single string S containing the string to switch.

Output

The string S after being switched.

Example
Input
HeLlO
Output
hElLo
Note

The string will not contain spaces or non-alphabetic characters.

059. Multiply Characters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Take a single String as input, and output the same string after repeating certain characters by a certain number. The character 'h' should be repeated 5 times, the character 'c' should be repeated 2 times, and the character 'z' should be repeated 12 times.

Input

A single string S containing the string to be modified.

Output

A single string S after being modified.

Example
Input
schizophrenia
Output
scchhhhhizzzzzzzzzzzzophhhhhrenia
Note

All test cases will be completely lowercase.

060. Maximum Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Find the largest possible number that can be stored with N bits. Assume that the number is a signed integer value. Remember that the maximum value possible with a certain number of bits can be calculated with the formula $$$2^{N-1}-1$$$. When solving this problem, keep in mind that if the input is greater than 32, your programming language may not have large enough integers, so you will need to use larger variable types or arbitrary precision arithmetic. Arbitrary-precision arithmetic comes with most programming languages, for example the BigInteger class in Java.

Input

An Integer N ranging from 1 to 64.

Output

An Integer representing the largest possible number within the given bit size.

Example
Input
32
Output
2147483647
Note

Be careful of floating point precision errors, and be sure that your output does not print output by a power of ten, e.g. 9.77E13.

061. Half Winds
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A compass has many divisions of cardinal directions, most commonly the four cardinal directions of North, East, South, and West are used, though smaller subdivisions called half winds are available. The half winds can be seen on a 16-wind compass rose, and are north-northeast(NNE), east-northeast(ENE), east-southeast(ESE), south-southeast(SSE), south-southwest(SSW), west-southwest(WSW), west-northwest(WNW) and north-northwest(NNW). For this problem, decode the acronym into the full name of the half wind direction.

Input

A single 3 character string containing the acronym to translate.

Output

A single string that represents the full direction name.

Examples
Input
ESE
Output
east-southeast
Input
NNE
Output
north-northeast
Note

All inputs will be capitalized, and all outputs should be lower case with a hyphen included.

062. Delete Characters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a string S and a list of characters C, print string S after removing all of the characters given in list C.

Input

The first line is the string S to be modified. The second line contains integer N, which is the number of different characters to be deleted. The following N lines contain the characters to be deleted.

Output

A single string S after deleting all of the characters that are given to be deleted.

Example
Input
howdy
2
w
y
Output
hod

063. Schwarzschild Radius
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The event horizon of a black hole, also known as the Schwarzschild radius, is the radius from a black hole at which even light can no longer escape. The formula to calculate the Schwarzschild radius of a given mass is $$$r_s=\frac{2GM}{c^2}$$$. The value $$$G$$$ is the universal gravitational constant, which you should consider to be $$$6.67*10^{-1}$$$ for this problem. $$$G$$$ is being given such a high value under the assumption that the masses being input will be incredibly large. The value of $$$M$$$ will be provided, and the value of $$$c$$$ is the speed of light, which you should consider to be $$$3*10^{4}$$$ for this problem. The value of $$$c$$$ is being decreased due to the incredibly low values that it normally produces.

Input

A single floating point value M that represents the mass of the object. The value of M will be between 0 and 1000000000.

Output

A single floating point value that represents the Schwarzschild radius of the object.

Example
Input
1000000
Output
0.0014822222222222222
Note

Make sure to use the shortened values for $$$G$$$ and $$$c$$$ provided in the question, and not the more precise actual values. The reason that the values for $$$G$$$ and $$$c$$$ have been changed is that the use of their actual values causes such low floating point values that errors can occur, and handling such errors is not the goal of this problem. When actually calculating the event horizon, the real values of $$$G$$$ and $$$c$$$ should be used.

064. Gas Cost
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When using an automobile, one often seeks to understand what they will be expected to pay for the usage of gas resources. The cost of driving a certain distance can be calculated based on the miles per gallon(mpg) of the car, the distance traveled, and the cost per gallon currently. Taking in these three values as input, determine the total cost of the trip.

Input

The first line contains three space-separated floating point values that represent the miles per gallon, distance, and cost per gallon respectively.

Output

Output a single floating point value that represents the dollar cost of the designated trip.

Example
Input
10 100 3.5
Output
35.0

065. Intersection of Two Lines
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When performing calculations on linear equations, finding the intersection point of two lines is a very common task. Write a program that takes two linear equations in the form of $$$y=mx+b$$$ and outputs the $$$x$$$ coordinate at which the two lines intersect.

Input

The first line contains two floating point values representing the $$$m$$$ and $$$b$$$ values of the first linear equation respectively. The second line contains the two variables corresponding to the $$$m$$$ and $$$b$$$ variables of the second linear equation.

Output

A single floating point value that represents the $$$x$$$ coordinate at which the two lines intersect.

Example
Input
5 3
-6 -20
Output
-2.090909090909091
Note

Assume that all test cases contain lines that do intersect.

066. Neural Network Weight Count
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As computers have become more and more powerful, the use of artificial intelligence has become ever more prominent in modern computing. As a result, a mechanism called a neural network has become a very commonly used tool for replicating the basic biological processes that result in the function of the brain. Neural Networks are composed of a series of "layers" of nodes, where each node of layer $$$i$$$ will connect with every node of layer $$$i+1$$$.

The structure of the network is not very important for the problem, and you do not need to know any more specifics about neural networks or their usage. Instead, you will need to calculate the total number of weights(connections between two nodes) in a given network. Weights can be seen in the image as the crossing lines between nodes. The input will provide the number of layers(including the input and output layers), as well as the number of nodes in each layer respectively.
Input

The first line contains a single integer $$$N$$$ that represents the number of layers. The next line contains $$$N$$$ space-separated integers that represent the number of nodes in each layer respectively.

Output

A single integer that represents the total number of weights in the network.

Example
Input
3
5 10 5
Output
100

067. Tangential Velocity
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When an object is rotating around a central point in circular motion, a force called centripetal force exists. Centripetal force is the force that pulls the object towards the center, preventing it from flying off in a straight line. An equation exists to relate the centripetal force $$$F_c$$$, the mass of the object $$$m$$$, the tangential velocity $$$v$$$, and the radius of the circle $$$r$$$. This equation is represented as follows: $$$F_c = \frac{mv^{2}}{r}$$$. To solve this problem, you will be given the centripetal force, the mass of the object, and the radius of the rotation. With this information, determine the tangential velocity of the moving object.

Input

The first line contains three space-separated floating point values that represent the centripetal force, the mass of the object, and the radius of the rotation respectively.

Output

Output a single floating point value that represents the tangential velocity of the movement.

Example
Input
100 10 5
Output
7.0710678118654755

068. Relative Strength Index
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When trading securities such as stocks and crypto-currencies in the markets, many traders look at mathematical tools called indicators. There are hundreds of different indicators for all sorts of purposes, but one of the most commonly used indicators is called the relative strength index, or RSI for short. The RSI provides an estimate of how the price of a security is likely to move, with a high RSI value(above 70) suggesting the item is overpriced and will decrease in value, while a lower value(below 30) suggests the opposite. The RSI is calculated with a simple formula that is based on the past prices of a security. This formula is given as: $$$100-(100/(RS+1))$$$ where $$$RS = aveUP/aveDOWN$$$. $$$aveUP$$$ is the average value among all of the times the price of the security increased between two measurements, and $$$aveDOWN$$$ is the average value among all of the times the price of the security decreased between two measurements. For this problem, take in the past $$$N$$$ prices of an asset, then determine the value of the RSI indicator. It is important to note that aveDOWN should be composed of the absolute value of each price decrease between two measurements, and therefore should have a positive value.

Input

The first line contains an integer $$$N$$$ representing the number of prices that will follow. The next line contains $$$N$$$ space-separated floating point values that correspond to each measurement of the price, with the first measurement being the first value provided.

Output

A single floating point value that represents the value of the RSI indicator for the given price history.

Example
Input
4
6500.0 6510.0 6300.0 6200.0
Output
6.060606060606062
Note

Note that in real market RSI calculations, an exponential moving average(EMA) is used to process faster moving data, but you should use a simple moving average(SMA) to find the aveUP and aveDOWN values. A simple moving average is the same as finding the average value of a number set as you usually would. It is also very important to note that aveDOWN should include the absolute value of each decrease, and should therefore have a positive value. You can also assume that there will always be at least one price increase and at least one price decrease in the given data

069. Word Rotation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob is attempting to encrypt information so that only those he trusts with the secret code can decode his secret information. Instead of using a highly secure encryption method, bob uses a method called rotation, where he shifts each letter of his phrase a certain number of characters up or down. This shift works by moving the character up and down the alphabet, so the character 'a' shifted by 5 would become 'f'. A shift also wraps around the alphabet, so if you were to shift 'a' by -5, it would become 'v'. In addition, a character can be shifted by values greater than 26, so for example 'a' shifted by 30 would become 'e', wrapping all the way back around the alphabet. To solve this problem, you will be given a single lowercase string and a series of rotations, with each rotation corresponding to the character in the string with the same index. Perform each rotation on each character and determine what the resulting string would be.

Input

The first line contains a single lowercase string of length $$$N$$$ with no spaces that represents the text to be rotated. The next line contains $$$N$$$ space-separated integers that represent the shift performed on the corresponding character of the original string.

Output

A single lowercase string that represents the original string after performing the shifts.

Example
Input
agjnp
7 -2 54 -80 25
Output
hello

070. Mersenne Primes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As you may know, large prime numbers are in very high demand currently, and there are many large scale searches for even larger primes. Some of the largest prime numbers discovered fit a number called a Mersenne Prime, which is essentially any prime number than can be represented by the equation $$$2^{p}-1$$$. Mersenne Primes are especially interesting as they can be tested for primality with a special test called the Lucas-Lehmer test. Although you could technically solve Mersenne Primes using typical prime-number algorithms, the Lucas-Lehmer test will almost always be faster. The pseudocode for conducting the Lucas-Lehmer test for as found on Wikipedia is as follows:

This code will test $$$p$$$ as $$$p$$$ is found in the equation $$$2^{p}-1$$$. As a result, Mersenne Primes are often referred to with this value of $$$p$$$ that is present in the power of two. Your task is to implement the Lucas-Lehmer test so that you can determine if given values of $$$p$$$ are valid Mersenne Primes. Some of the values of $$$p$$$ might cause the values in the Lucas-Lehmer test to be greater than 32 or 64 bits, so arbitrary precision might be required(BigInteger class in Java).
Input

A single integer $$$p$$$ that represents the power of 2 in the equation $$$2^{p}-1$$$ to be tested.

Output

The phrase "true" should be printed if the value calculated with $$$p$$$ is a Mersenne Prime, and the phrase "false" should be printed otherwise.

Examples
Input
7
Output
true
Input
15
Output
false
Note

More information regarding the Lucas-Lehmer test and Mersenne Primes can be found here: https://en.wikipedia.org/wiki/Lucas-Lehmer_primality_test, https://en.wikipedia.org/wiki/Mersenne_prime.

071. Days between two Dates
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a previous contest, a question was asked about determining how many days apart two dates were, ignoring leap years. This question is essentially the same, except it includes leap years. In addition, this question only asks for the count of days from $$$date 1$$$ to $$$date 2$$$, and $$$date 2$$$ will always be after $$$date 1$$$. Take in two dates in the form of month-name day-number, year. Then print out the number of days from the first date to the second one, and make sure that your calculation includes the addition of days added by leap years.

Input

The first line contains the first date in the form of month day, year. The month is provided as a capitalized name, and not a number. The second line contains the second date in the same form.

Output

A single integer representing the number of days from the first date to the second.

Example
Input
June 21, 2019
June 21, 2020
Output
366
Note

The second date will always be after the first. Make sure to consider leap years. If you have difficulty with the input, be sure to carefully follow the formatting.

072. Tri-Angle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given the three points that represent the corners of an isosceles triangle, determine the angle that the triangle is pointing. The angle can be calculated based on the vector created along the line of symmetry of the triangle that exits through the point of the triangle. The angle should be represented in degrees and should be determined relative to the vector (1,0). The following image shows a triangle with points at (-1,0), (0,1), and (-2,2), and has an angle of 135 degrees.

To add to the difficulty, the order of the points is not predetermined, so you will need to determine which points fall away from and on the line of symmetry. Your answer should always be positive, between 0 and 360, and should be represented in degree form. Remember you can convert from radians to degrees with the formula $$$deg=rad*\frac{180}{π}$$$
Input

Each line contains two space-separated floating point values that represent the $$$x$$$ and $$$y$$$ values of each point of the triangle. They are randomly ordered.

Output

A single floating point value that represents the degree measure of the angle created from the positive x-axis to the direction of the triangle.

Example
Input
-2 2
0 1
-1 0
Output
135.0
Note

Make sure answers are provided in degrees and fall within the range of 0 to 360.

073. It's A Me!...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Welcome to the CodeRams Coding Competition!

For the first problem, we'll keep it simple to make sure you understand how this format works.

Input

Finish the given sentence by adding the string Mario! to the end of the statement.

Output

Return the completed sentence.

Example
Input
It's a me,
Output
It's a me, Mario!

074. Infinity Gauntlet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have acquired the Infinity Gauntlet from Thanos from the Marvel Universe. For those who are unfamiliar with the Infinity Gauntlet, it contains immense power with the ability to many things, but most notably, to reduce numbers into half.

Input

The first line will contain integer $$$n$$$ that will denote the amount of test cases that will follow, and each line after the first will contain an integer that is to be divided in half.

Output

Output a series of line-separated floating-point values which divides the inputs in half.

Example
Input
5
10
32
12
35
52
Output
5.0
16.0
6.0
17.5
26.0

075. Shopping Spree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You've been selected to be the recipient of Wegman's shopping spree program! The only caveat is that you have to be continuously moving through the building at all times, through the different sections in a circular pattern, so you will only have time to grab one item from each section. It will also take some time for you to move to the different locations of the store, and luckily, this Wegmans only has 3 sections, as the architect designing this location was lazy with his design.

Produce –> Meat Meat –> Dry Goods Dry Goods –> Produce

You want to know how many loops it will take you to get a certain amount of different types of items.

Input

The first line will contain an integer $$$n$$$, which denotes the amount of test cases that will follow. These test cases will each contain 3 different, space-separated integers denoting the amount of different items you will need to complete the shopping list.

The first line will always be Produce $$$p$$$, the second will be Meat $$$m$$$, and the third will be dry goods $$$d$$$.

Output

Return the amount of loops it will take for you to complete your shopping list.

Example
Input
3
2 6 1
3 2 1
1 5 7
Output
6
3
7

076. Jar of Candies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Getting back from the grocery store, you bought a whole bag of candies just for you to eat. You put the candy in a jar, and hide it in your room. Unfortunately, you notice that the number of candies in the jar are going down each day, but you do not know by how much.

You want to know how much the thief has stolen every day.

Input

The first line $$$n$$$ will denote how much candy you had initially, and the second line will always contain a series of descending space-separated integers which indicate the amount of candy remaining each day, starting from the day the first candies were stolen.

Output

Output a set of line-separated integers which answers the amount of candy stolen from the candy jar each day.

Example
Input
100
97 92 85 80 72 65
Output
3
5
7
5
8
7
Note

(It turns out that you caught your siblings stealing from your jar while you were absent from your room. Those rascals!)

077. That Hertz!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are an event organizer, tasked with planning an event in a very large, outdoors area. However, you only have two very powerful speakers, which are placed on both ends of the stage.

You assume that there will be crowds spanning large lengths at this meeting, and need to figure out how long it takes for the sound from the stage to reach the furthest attendees of the event.

However, an engineer helping to organize the event reminds you that the speed of sound is varied, depending on the temperature. As you are planning the event in Syracuse, this is a serious problem, as the temperatures are very unpredictable.

The approximate formula for the speed of sound (assuming there is no humidity in the air, is):

$$$V = (331.3 + .606∙\vartheta)$$$

Where $$$V$$$ is the speed of sound in meters per second, and $$$\vartheta$$$ is the temperature of the air, in degrees Celsius.

Input

The first line of the input will denote integer $$$n$$$, the number of test cases following the line. The lines following will contain two values each, the first being the integer temperature $$$\vartheta$$$, and second being the distance between the stage and the furthest edges of the crowd, measured in km.

Output

Output the time it takes for the sound from the stage to reach the furthest edges of the crowd in seconds, rounded to the nearest hundred.

Example
Input
5
7 3.6
24 1.1
17 4.4
-1 1.2
8 5.9
Output
10.73
3.18
12.88
3.63
17.55

078. Flatten The Curve
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Throughout this global pandemic, many health experts and doctors are steadfast on the effort to "flatten the curve", or to decrease the maximum amount of people who are getting infected by the virus, using the method of social distancing, one of the reasons why we are in quarantine at this very moment.

The daily rate of infection, if left unchecked, can look a lot like this logistic function, where $$$\Delta N$$$ is the total number of cases, $$$\Delta t$$$ is the time period for new infections, (which, in this case, would be one day.)

$$$\frac{\Delta N}{\Delta t} = a(1-\frac{N}{N_{max}})N$$$

$$$a$$$ is the infection rate, which, for COVID-19, would be .394 (with social distancing, the number is able to go down). Finally, $$$N_{max}$$$ is the total amount of infections we can expect for the curve to flatten. In this simulation, we will calculate the total number of days $$$t$$$ the virus will take in order for it to infect the entire population of America dependant on its infection rate, which will be about 320 million people.

Input

The first line will contain the integer $$$n$$$, which denotes the amount of test cases that will follow. Each line below the first line will contain a floating point value $$$a$$$, which is the infection rate for that test case.

Output

Let $$${N_{max}}$$$ be equal to around 328.2 million people, which is the entire population of the US, however, you should output the number of days it takes for the virus to infect 320 million people, which is a vast majority.

Example
Input
4
.394
.212
.107
.059
Output
67
118
226
403
Note

($$$N$$$ will also have an initial value of 1)

079. Over The Rainbow
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A color wheel is a tool used to determine the relationships of different colors, often by the distance between two colors on the wheel.

Using the given simple color wheel above, your task is to determine the shortest numerical distance between two colors.

Input

The first line will contain an integer $$$n$$$, the number of test cases that will follow. The next lines will contain two strings in each individual line, which will be the two colors that will taken under measurement. (All colors will have the same name as the colors of the image above)

Output

Return the int value of the distance between the two colors, including the last color, but excluding the first.

Example
Input
3
green red
purple orange
blue blue-green
Output
3
2
1
Note

(All inputs will be in lowercase)

080. 1337 5p34k
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Leet, (also known as 1337 sp34k or Elite Speak), was a prominent use of letter swapping during early internet culture.

Set types of letters would be able to be substituted for different numbers which would have similarities to the letters they were replacing. For this basic translator, only these conversions are needed:

a = 4 b = 8 e = 3 i = 1 l = 1 o = 0 s = 5 t = 7 z = 2

Input

Will contain a single string to be translated

Output

Return a leet translated piece of string

Example
Input
this is a test input
Output
7h15 15 4 7357 1npu7

081. It's a Mess!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in alphabetical order!

To fix this problem, you decide to create a program that is able to divide the books into different genre groups, with the authors of the genres listed in alphabetical order.

Input

The first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space.

Output

Output a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: <genre>: <aauthor1>, <bauthor>, <cauthor>

Example
Input
7
Bradbruy scifi
Asimov scifi
Kafka dystopian
Huxley dystopian
Tolkien fantasy
Collins dystopian
Herbert scifi
Output
dystopian: Collins, Huxley, Kafka
fantasy: Tolkien
scifi: Asimov, Bradbruy, Herbert
Note

(For the order of the genres, please make sure that they are also in alphabetical order.)

(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)

082. Patterns 1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The FBI has been working hard to find the location of a criminal organization by analyzing their use of repeating patterns in sections of their internal communications. So far, this process has been entirely manual and is therefore slow, so you are tasked with creating a program to automate this pattern finding. Determine whether or not a section of text repeats a single string multiple times. The problem is that you don't know what string it is that is being repeated, though you do know that the pattern will always begin immediately. A pattern will always appear as the same string being repeated at least twice. It is also important to note that there can be unimportant text that follows the repetition that is not a part of the pattern. All of this following text should be ignored. It is also important to note that the repeated string must be at least two characters.

Input

A single string that represents the string to analyze.

Output

A single statement of "True" or "False" that states whether or not there is a pattern.

Example
Input
hellohelloasd
Output
True

083. The Numbers Mason!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Octal Numeral system is a Base-8 number system, with the same concept and algorithm as other number systems, such as binary and hexadecimal. The advantages of using the base 8 system, is that all of its components are made of numbers, unlike the hexadecimal system, and is shorter than the binary system.

Input

The input will be composed of different integer values depicting octal values, separated by spaces, which represent a certain Unicode value once converted into a decimal.

Output

Output the translated string.

Example
Input
164 150 151 163 40 151 163 40 141 40 160 162 157 160 145 162 40 157 165 164 160 165 164
Output
this is a proper output

084. Fine Tuned
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On a regular acoustic guitar, the open (regular) strings are tuned with these notes, starting from lowest to highest:

E-A-D-G-B-E

You can change these values into different notes using the tuning pegs on the top of the guitar, twisting it forwards or backwards to change the pitch of the strings. One full rotation of the peg would be equivalent changing the pitch by one semitone, or a half step in pitch. For instance, using the piano keys up above, F would move up to F#, or if moved down a semitone, would be moved down to an E.

When given certain note values, your job is to tune the song based on how many semitones you are given. This is known as transposing.

Input

The first line will contain an integer n which will denote the semitone value you are to transpose the piece to. The second line will contain a space-separated line of strings ranging from the notes A-G#.

Output

Output a new line of the transposed piece, with each note being space-separated.

Examples
Input
-3
E A D G B E
Output
C# F# B E G# C#
Input
3
E A D G B E
Output
G C F A# D G

085. Pattern Two
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Though you may have completed the previous task to analyze and find patterns in sections of text, the FBI has realized that it needs a more powerful program that is able to find more complex patterns and with more constraints. Your new program should be able to identify if a repetition pattern exists within a string regardless of where it starts. You will also be supplied with a number that represents how many repeats there should be. Your program should only output "True" if the number of repetitions precisely matches the number provided.

Input

The first line contains the string to be analyzed. The second line contains a single integer that represents the number of repetitions to look for.

Output

A single statement of "True" or "False" that indicates whether or not a repetition pattern exists with the repeat number provided.

Example
Input
uyboubawlefjbasdHELLOHELLOHELLOHELLOsygvfubklkj
4
Output
True
Note

There can be unneeded text before and after the repetition, and this should be ignored.

086. Symmetry
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob has an array of integers, and Bob is curious whether or not his array is symmetrical on two axis of symmetry. Write a program that takes in an array of integers and outputs whether or not the array is symmetrical. The two axis of symmetry are the horizontal and the vertical. It is important to note that if an odd number of columns or rows is present, the middle row and/or column(s) should be considered the axis and should be completely ignored in the symmetry analysis. Integers are considered symmetrical if they are the same value across an axis of symmetry. Your program should only output "True" if the array is symmetrical on both the horizontal and vertical axis of symmetry.

Input

The first line contains two space separated integers, $$$R$$$ and $$$C$$$, respectively. These represent the number of rows and columns that are in the array. The next $$$R$$$ lines will each contain $$$C$$$ space-separated integers that represent the individual elements of the array.

Output

A single statement of "True" or "False" that indicated whether or not the array is symmetrical.

Examples
Input
5 5
1 0 1 0 1
0 1 0 1 0
1 1 1 0 1
0 1 1 1 0
1 0 1 0 1
Output
True
Input
3 3
1 1 1
0 1 0
1 0 1
Output
True

087. The Robots
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Welcome to the CodeRams Contest #8, and thanks for participating!

We like to make contests with themes that tie together all of the problems. For this contest, the problems are all based on songs by the German band Kraftwerk. We'll provide links to each of the songs in each corresponding problem. We recommend that you listen to each song while you are solving each problem. (You're allowed to view the provided links, despite them requiring use of the internet.)

The Robots (the song corresponding to this problem)

For this first problem, you want to train your robot army to print out a given string of text three times.

Input

The only line contains a single line of input, consisting of any ascii characters.

Output

Print the line of text given in the input three times, with each one separated by a new line.

Example
Input
We Are The Robots
Output
We Are The Robots
We Are The Robots
We Are The Robots

088. Radioactivity
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Radioactivity

You're trying to determine how many neutrons are in a certain radioactive isotope. You know how many protons are in the isotope, and you know the isotope's mass number. The mass number of an isotope is defined as the number of protons plus the number of neutrons. Given the number of protons and the mass number, figure out how many neutrons are in the radioactive isotope.

Input

The only line of input contains two space-separated integers $$$p$$$ and $$$m$$$ ($$$p$$$ <= $$$m$$$), representing the number of protons in the isotope, and the mass number of the isotope, respectively.

Output

Output a single positive integer $$$n$$$: the number of neutrons in the radioactive isotope.

Examples
Input
92 238
Output
146
Input
36 85
Output
49

089. The Model
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Model

You are making a model airplane, which will be powered by rubber bands. Luckily, to speed up the process of winding the rubber bands, you have a crank winder, which has a certain ratio (e.g. 15:1), representing how many winds of the rubber band one turn of the winder will result in. Given this value, and how many winds you ultimately want the airplane's rubber band to have, figure out how many times you need to turn the winder.

Input

The first line of input contains a single positive integer $$$n$$$, representing the number of winds you want the plane to have. The second line of input contains a single positive integer $$$m$$$, representing how many winds of the rubber band one turn of the winder corresponds to.

Output

Output a single positive integer $$$w$$$: how many times you need to spin the winder. This value is guaranteed to be an integer.

Examples
Input
2250
15
Output
150
Input
64
4
Output
16
Note

For the first example, $$$150.0$$$ would also be judged as a correct answer.

090. Computer World
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Computer World

You just bought a new computer, and you wonder if it has a large, medium, or small amount of storage on its hard drive. The storage of your computer's hard drive will be given in gigabytes (GB).

If your computer's storage space is less than or equal to 200 GB, you consider it SMALL.

Otherwise, if your computer's storage space is less than or equal to 500 GB, you consider it MEDIUM.

Otherwise, you consider it LARGE.

Given these storage space bounds, figure out whether or not your computer's storage is SMALL, MEDIUM, or LARGE, and print the answer accordingly.

Input

The only line of input contains a string indicating how much storage space your computer has, with a "GB" on the end. For example, if your computer had 300 gigabytes of storage, this would be read as "300GB" (no quotes) in the input.

Output

Output a single string: SMALL, MEDIUM, or LARGE (all caps), classifying your computer's storage space as described above.

Examples
Input
800GB
Output
LARGE
Input
200GB
Output
SMALL
Input
450GB
Output
MEDIUM

091. Spacelab
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Spacelab

With the CodeRams club, you've created a lab in space to study solar power. You created your lab on a planet in our solar system. Unfortunately, a rival CodeQuest team also created a spacelab on a different planet. You need to figure out which spacelab is closer to the sun.

For reference, the order of the planets in our solar system from closest to farthest away from the sun is "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" (you can copy this into a list/array if you want).

Input

The first line of input contains a single string, representing the planet that your spacelab is located on. The second line of input contains a single string, representing the planet that the rival team's spacelab is located on. The planets given are guaranteed to be in our solar system, and no TNOs, dwarf planets, or asteroids will be given in the input.

Output

If your spacelab is closer to the sun than your rival's, output "CLOSER" (no quotes)

If your spacelab is farther away from the sun than your rival's, output "FARTHER AWAY" (no quotes)

If your spacelab is on the same planet as your rival's, output "THE SAME" (no quotes)

Examples
Input
Mars
Jupiter
Output
CLOSER
Input
Uranus
Mercury
Output
FARTHER AWAY
Input
Neptune
Neptune
Output
THE SAME

092. The Telephone Call
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Telephone Call

You want to call Lockheed Martin to register your team for CodeQuest 2021, but you don't know their phone number. However, you know some of the digits of the phone number. You're going to try to call all possible phone numbers, given the digits that you know, and you want to know how many numbers you're going to have to call. For this problem, assume that all area codes are valid.

Input

The only line of input contains a string of length 10, with each position in the string containing a digit from 0-9, if you know the digit at that position in the phone number, and an "x" if you don't know the digit.

Output

Output a single positive integer $$$n$$$: how many possible phone numbers there are, given that you already know the digits listed in the input.

Examples
Input
315xxxx8x9
Output
100000
Input
1234567890
Output
1
Input
xxxxxxxxxx
Output
10000000000
Note

Note that the answer does not necessarily fit inside of a 32-bit integer type, in tests like the third example. The answer will fit inside of a "long" in Java. (You don't need to worry about this in Python)

093. Music Non Stop
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Music Non Stop

You're trying to find the longest possible piece of music, so that you can play music non-stop. Given a list of songs and their durations (in MM:SS, with leading zeros), figure out which song is the longest.

Input

The first line of input contains a positive integer $$$n$$$: the number of songs. The next $$$n$$$ lines contain a string, representing the song title, a space, and the song's duration, in MM:SS format with leading zeroes. (For example, a song that was 7 minutes and 9 seconds long would be written as 07:09).

Output

Output a single string: the name of the longest song given in the input. If two songs have the same length, output the one that comes first in the input.

Examples
Input
6
TheRobots 06:13
Spacelab 05:57
Metropolis 06:01
TheModel 03:41
NeonLights 08:53
TheManMachine 05:32
Output
NeonLights
Input
4
ReallyShortSong 01:30
ReallyLongSong 18:16
AnotherReallyLongSong 18:16
NotAsLongSong 11:01
Output
ReallyLongSong

094. Computer Love
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Computer Love

You love your computer, and you want to give it a present: a large integer. However, your computer especially loves powers of two. Given two numbers $$$x$$$ and $$$y$$$, find the largest power of two between $$$x$$$ and $$$y$$$, i.e. find the largest number $$$n$$$ such that $$$x$$$ <= $$$n$$$ <= $$$y$$$, and $$$n$$$ is a power of two.

Input

The only line of input contains two space-separated integers $$$x$$$ and $$$y$$$: the lower and upper bounds of the range described in the problems statement. The values are inclusive, i.e. $$$x$$$ and $$$y$$$ could potentially be valid answers if they were powers of two.

Output

Output a single integer $$$n$$$: the largest power of two such that $$$x$$$ <= $$$n$$$ <= $$$y$$$. If there aren't any powers of two between $$$x$$$ and $$$y$$$, output $$$-1$$$. The answer is guaranteed to be within the bounds of 32-bit signed integers.

Examples
Input
6 18
Output
16
Input
35 55
Output
-1
Input
86 375
Output
256

095. Techno Pop
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Techno Pop

After listening to the Kraftwerk song Techno Pop, you decide that you want to pop a balloon. You have a spherical balloon that will pop when it reaches a volume of $$$v1$$$ in^3, and you blow up the balloon inside of a cube-shaped box with a volume of $$$v2$$$ in^3.

Given these values, figure out whether or not it is possible to pop the balloon in the cube-shaped box that you have.

Recall that the formula for the volume of a sphere is $$$\frac{4}{3}\pi{}r^3$$$, where $$$r$$$ represents the radius of the sphere, and the formula for the volume of a cube (or a cube-shaped box) is $$$s^3$$$, where $$$s$$$ represents the side length of the cube.

Input

The only line of input contains two space-separated integers: $$$v1$$$ and $$$v2$$$, representing the volume that the spherical balloon needs to be greater than or equal to in order to pop, and the volume of the cube-shaped box, respectively. Both values are given in $$$in^3$$$.

Output

Output "YES" (no quotes) if the balloon can pop inside of the box, and "NO" (no quotes) otherwise.

Examples
Input
10 27
Output
YES
Input
10 8
Output
NO
Note

In the first example case, the balloon has room to inflate to at most 14.1 $$$in^3$$$, so the balloon can inflate to 10 $$$in^3$$$ and pop.

In the second example case, the balloon only has room to inflate to 4.2 $$$in^3$$$, so the balloon cannot pop inside of the cube-shaped box.

096. Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Numbers

You're working with large numbers, and you want to calculate the totient function of a certain one. The totient function of a number $$$n$$$ is defined as the number of positive integers less than or equal $$$n$$$ that are relatively prime with $$$n$$$, i.e. the number of integers $$$k$$$ such that $$$k$$$ <= $$$n$$$ and $$$gcd(k, n) = 1$$$.

For example, the totient of $$$15$$$ is $$$8$$$, because 1, 2, 4, 7, 8, 11, 13, and 14 are relatively prime with $$$15$$$, while 3, 5, 6, 9, 10, 12, and 15 are not. 4 is relatively prime with 15, because there aren't any common factors of 4 and 15. 4 has factors {2}, and 15 has factors {3, 5}. On the other hand, 10 is not relatively prime with 15, because 10 and 15 both have a common factor of 5.

Given an integer $$$n$$$, figure out the value of $$$φ(n)$$$, where $$$φ$$$ represents the totient function as described above.

Input

The only line of input contains a single positive integer $$$n$$$ less than 1000.

Output

Output a single positive integer $$$p$$$: the value of $$$φ(n)$$$ as described above.

Examples
Input
15
Output
8
Input
60
Output
16
Input
7
Output
6

097. Neon Lights
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Neon Lights

You are trying to find strings of text to put on neon lights. You want to fully test the extent of the neon lights' writing style for letters, so you want to pick the string of text that has the highest number of distinct (different) letters from a selection of possible strings of text.

Input

The first line of input contains a positive integer $$$n$$$ indicating the number of strings of text that you are considering putting on neon lights. The next $$$n$$$ lines each contain each string of text, consisting of only lowercase letters and spaces.

Output

Output the string of text from the possibilities which has the highest number of distinct letters. If two strings of text contain the same number of distinct letters, choose the one that comes first in the input file.

Examples
Input
6
coderams club
neon lights
kraftwerk
this is a long string of text
abababababababababcabababab
short
Output
this is a long string of text
Input
3
the quick brown fox jumps over the lazy dog
abcdefghijklmnopqrstuvwxy
hello world
Output
the quick brown fox jumps over the lazy dog
Input
3
abcde
abc
edcba
Output
abcde

098. It's More Fun To Compute
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's More Fun To Compute

You are trying to discover that it's more fun to compute, and you're doing so by evaluating long strings of text. You define the fun-ness of a string to be the amount of characters in the string that are equal to "f", "u", and "n". You can perform cyclic shifts on the string an infinite number of times. When you cyclically shift the string, each character changes into the one after it, so any "a" characters become "b", "b" becomes "c", etc. "z" characters turn into "a" in a cyclic shift.

Given that you can perform an infinite number of cyclic shifts on the input string, find the maximum fun-ness of the string.

Input

The only line of input contains a single string $$$s$$$, consisting of only lowercase a-z characters and spaces. (When you perform a cyclic shift on the string, nothing happens to the spaces).

Output

Output a single positive integer $$$n$$$: the maximum possible fun-ness of the string, as described above.

Examples
Input
hello world
Output
5
Input
coderams contest number eight
Output
9

099. Autobahn
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Autobahn

You are about to drive on the Autobahn. You have several different cars, and you're trying to decide which one to take on the Autobahn. The different cars have differing fuel efficiencies, measured in miles per gallon (MPG), and the cars have different top speeds. You calculate a car's score as its fuel efficiency (MPG) multiplied by its top speed.

Given the list of possible cars, your task is to sort them by their score.

Input

The first line of input contains a single positive integer $$$n$$$: the number of cars. The next $$$n$$$ lines each contain the data for a car: the name of the car, its fuel efficiency in MPG, and its top speed.

Output

Output $$$n$$$ lines, each consisting of a car, sorted by their score as described above. Each line should be in the same format as its corresponding line in the input file. The car with the lowest score should appear first, and the car with the highest score should appear last. If two or more cars have equal scores, sort them alphabetically by the names of each car.

Example
Input
5
Porsche 8 200
Ferrari 7 250
Lamborghini 6 220
BMW 5 230
MercedesBenz 10 160
Output
BMW 5 230
Lamborghini 6 220
MercedesBenz 10 160
Porsche 8 200
Ferrari 7 250

100. Ohm Sweet Ohm
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ohm Sweet Ohm

You have a circuit consisting of many resistors in parallel, and you want to calculate their equivalent resistance, in ohms.

If you competed in our Contest #2 back in January, you might remember that the formula for calculating the equivalent resistance of two resistors in parallel with resistances $$$a$$$ and $$$b$$$ is $$$(a * b) / (a + b)$$$.

To calculate the equivalent resistance of three parallel resistors, first calculate the equivalent resistance of the first two using the formula described above. Then, use the formula again to calculate the equivalent resistance of the third resistor and the value you just calculated, the equivalent resistance of the first two resistors. Calculating the equivalent resistance of more than three resistors works in a similar way.

Formally, the equivalent resistance of $$$n$$$ resistors can be calculated by plugging in the equivalent resistance of the first $$$n - 1$$$ resistors, and the resistance of the $$$n$$$th resistor, into the above formula.

Input

The first line of input contains a positive integer $$$n$$$ greater than one, indicating the number of resistors in the circuit. Assume that all of the resistors are in parallel with each other. The next line contains $$$n$$$ space-separated positive integers, each representing the resistance of a resistor in the circuit.

Output

Output a single positive decimal number: the equivalent resistance of the circuit. You don't need to (and you shouldn't) round your answer.

Examples
Input
9
37 23 56 85 41 99 33 22 11
Output
3.319115819885067
Input
2
11 19
Output
6.966666666666667

101. Metropolis
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Metropolis

You're driving through a metropolis. The metropolis can be represented as a 2D grid of buildings, each with a height value between $$$0$$$ and $$$9$$$. You consider a building to be a skyscraper if it has a greater height than all of the buildings directly adjacent to it (including diagonally). Given this 2D grid of building heights, figure out which buildings are skyscrapers, and which ones aren't.

Input

The first line of input contains a positive integer $$$n$$$: the height and width of the metropolis. The height and width are always equal, so the metropolis is always a square. The next $$$n$$$ lines each contain strings of $$$n$$$ characters, each character being a digit from $$$0$$$ to $$$9$$$ representing the height of each building.

Output

Output $$$n$$$ lines. Each line should consist of a string of $$$n$$$ characters, with each character being $$$Y$$$, if the building at that position is a skyscraper, and $$$N$$$ if it is not.

Examples
Input
5
35689
85723
39109
00004
39580
Output
NNNNY
NNNNN
NYNNY
NNNNN
NYNYN
Input
3
999
999
999
Output
NNN
NNN
NNN

102. Pocket Calculator
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pocket Calculator

You have a pocket calculator. Unfortunately, it is broken, so you need to calculate large math operations yourself. For this problem, you need to write a computer program to calculate the answer to a long math operation, with multiplication (denoted by an asterisk *), division (denoted by a slash / ), addition, and subtraction. There will not be parentheses or exponents. Recall order of operations: multiplication and division (with equal weight) from left to right first, followed by addition and subtraction (with equal weight) from left to right. Using eval() or similar commands for this problem is not allowed.

Input

The only line of input contains a line of text representing a math operation to calculate. The math operation will consist of one-digit numbers and the four operations described above, with exactly one space between each one. The input line will start and end with a number, and there will not be an equals sign at the end of the operation.

Output

Output a single integer: the answer to the math operation. The answer is guaranteed to fit inside of a 32-bit signed integer type. The answer is also guaranteed to be an integer.

Examples
Input
7 + 5
Output
12
Input
3 - 6 * 3
Output
-15
Input
3 + 4 * 3 - 6 / 3 * 3
Output
9
Note

In the third sample, $$$9.0$$$ would also be judged as correct.

103. Home Computer
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Home Computer

You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function.

The derivative of a "power function" $$$x^n$$$ is defined as $$$nx^{n-1}$$$. For example, the derivative of $$$x^5$$$ would be $$$5x^4$$$.

The derivative of a constant multiple of a power function $$$kx^n$$$ is defined as $$$knx^{n-1}$$$. For example, the derivative of $$$3x^4$$$ would be $$$12x^3$$$.

When taking the derivative of several terms added or subtracted to each other, you take the derivative of each term individually. For example, the derivative of $$$3x^5 - 5x^4$$$ would be $$$15x^4 - 20x^3$$$.

The "power rule" described above works intuitively if all terms have at least a degree of two (the number that $$$x$$$ is taken to the power of). For terms with a degree of one, such as $$$7x$$$, the derivative is just the constant multiple in front of $$$x$$$, which is $$$7$$$ for this example. For constant terms (with a degree of zero), the derivative is zero, and can be cancelled out.

Using this knowledge, your task is to write a program to determine the derivative of a given polynomial function.

Input

The only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant.

Output

Output a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function.

Examples
Input
5x^5 + 3x^4 + 2x^3 + 8x^2 + 9x + 10
Output
25x^4 + 12x^3 + 6x^2 + 16x + 9
Input
x + 10 + 3x + 5 + 8x + 16x^7 + 8x^30 + 300x^200
Output
1 + 3 + 8 + 112x^6 + 240x^29 + 60000x^199
Note

If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar.

104. Trans Europe Express
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Trans Europe Express

You're traveling on the Trans Europe Express, which consists of many train lines between cities. You want to know how many cities you can reach from a given start city, traveling only on the Trans Europe Express.

For example, if you started in City A, and the Trans Europe Express had train lines between City A and City B, City B and City C, and City D and City E, you could travel to City B or City C, but not to City D or City E.

For problems like these, you can use the graph theory algorithm Breath-First Search (BFS). The algorithm is described below in pseudocode:

1. Define an empty list of cities. Add the start city to the list.

2. Select the first city in the list of cities, and remove it from the list.

3. Mark the selected city as visited

4. For any edges that connect the selected city to another city, add the other city to the list of cities, if the city has not been visited yet

5. If the list of cities is not empty, repeat steps 2-4.

Then, the answer would be the number of cities that have been visited.

Input

The first line of input contains two space-separated positive integers $$$n$$$ and $$$m$$$: the number of cities, and the number of train lines on the Trans Europe Express. The next line of input contains a single string $$$s$$$, representing the start city. The next $$$m$$$ lines contain one of the train lines of the Trans-Europe Express: two space-separated strings: the cities that the train lines connect. The train lines can be traveled in both directions.

Output

Output a single integer $$$c$$$: the number of cities that you can visit by traveling only on the Trans Europe Express train lines.

Examples
Input
8 7
Dusseldorf
Dusseldorf Frankfurt
Frankfurt Berlin
Berlin Hamburg
Berlin Prague
Vienna Salzburg
Salzburg Zurich
Zurich Vienna
Output
5
Input
3 2
Syracuse
Syracuse Utica
Syracuse Rochester
Output
3
Note

Given that the pseudocode of the algorithm treats the cities as numbers rather than names, you should first map each city name to a number, before running the BFS algorithm.

105. Planet of Visions
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Planet of Visions

You are trying to test your vision using an eye test chart, and you want to see if you have 20/20 vision or not. You attempt read the text on the chart, and you unfortunately get some of them wrong. Now, you're curious how close you were to correctly reading the text.

You consider some pairs of letters similar. For example, "D" and "P" look relatively similar from far away. Given the letter pairs that you consider to be similar to each other, your task is to figure out how many of the letters you got right, how many you were close on (the letters were similar), and how many you got completely wrong (the letters were not similar). Note that letters are also similar to letters that its similar letters are similar to. For example, if "D" and "P" are similar, and "D" and "G" are similar, "P" and "G" are by definition similar as well.

Input

The first line of input contains a single string $$$s$$$, consisting of only capital letters: the correct text on the eye chart. The next line of input contains a single string $$$t$$$, consisting of only capital letters: your incorrect interpretation of the text on the eye chart. $$$s$$$ and $$$t$$$ are guaranteed to be the same length. The second line of input contains a single positive integer $$$n$$$: the number of letter pairs that you consider to be similar. The next $$$n$$$ lines contain two space-separated capital letters: a letter pair where the first letter is similar to the second, and the second letter is similar to the first.

Output

Output three space separated integers $$$a$$$, $$$b$$$, and $$$c$$$: the number of characters you got right, the number of characters you were close on, and the number of characters you got completely wrong, respectively, according to the definitions above.

Examples
Input
DEFPOTEC
PEFDOTED
3
D P
C D
A Z
Output
5 3 0
Input
DEFPOTEC
ABCDEFGH
7
A H
D H
B Z
Z Y
Y E
F C
C T
Output
0 4 4

106. Geiger Counter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Geiger Counter

You're in a large maze, and unfortunately the maze is filled with differing amounts of uranium ore, which could potentially expose you to dangerous amounts of radioactivity. Luckily, you have brought your trusty Geiger Counter with you, so you can measure the radioactivity of any given part of the maze in counts per minute (CPM).

You start at the top left corner of the maze, and you are trying to travel to the bottom of the maze. For any path through the maze, its radioactivity value is defined as the maximum CPM across all cell in the maze that you travel through on the path. Your task is to find the path through the maze with the lowest radioactivity value, in other words, find the highest CPM you have to expose yourself to if you travel on the optimal path.

You're allowed to move in any direction (except diagonally), and you can visit the same cell twice (although it is never necessary to).

Note that since the constraints on the size of the maze are fairly large, a brute force (complete search) solution that tries all possible paths,will not work.

Input

The first line of input contains two space-separated positive integers $$$n$$$ and $$$m$$$: the number of rows and columns in the maze, respectively. $$$n$$$ and $$$m$$$ will be less than 100. The next $$$n$$$ lines each contain a string containing $$$m$$$ digits (between 0 and 9), representing the radioactivity of each space in the maze in CPM.

Output

Output a single positive integer: the maximum amount of radioactivity that you have to expose yourself to, if you travel optimally through the maze and minimize this value.

Examples
Input
6 8
13567657
24903578
83107213
98829363
25511282
39108443
Output
4
Input
6 5
89888
88898
99998
88888
89999
88888
Output
8
Note

If you aren't sure where to start, try thinking of the maze as a graph.

Also, you should add these two lines to the top of your code if you're going to use recursion in your solution and you're coding in Python:

import sys

sys.setrecursionlimit(20000)

107. The Man Machine
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Man Machine

You played against a Man Machine in chess, and because it is a superhuman being, you lost every game. Now, you're trying to practice chess so that you can beat the Man Machine.

To practice, you want to figure out how many different ways there are to place $$$N$$$ queens on an $$$N$$$ by $$$N$$$ chessboard, such that no two queens attack each other (queens can attack any number of spaces directly diagonal, left, right, up, or down). This is called the $$$N$$$-queens problem, and is a standard computer science problem involving recursion and backtracking. Your task is to implement this solution on chessboards where $$$N$$$ can be up to 9.

Input

The only line of input contains a single positive integer $$$N$$$: the size of the chessboard.

Output

Output a single positive integer $$$c$$$: the number of ways to place $$$N$$$ queens on the chessboard, such that no two queens attack each other.

Examples
Input
8
Output
92
Input
1
Output
1
Note

If your program consists only of a lookup table with the correct values, your submission will be judged as incorrect and you may be disqualified from the contest.

108. The Hall Of Mirrors
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Hall Of Mirrors

You are in a hall of mirrors, and you shine a laser beam in a certain direction. Given the position of several diagonal mirrors, figure out the path of the laser beam.

You shine your laser beam from the back of the hall of mirrors (on a computer screen, this will look like the "bottom" of the image).

Input

The first line of input contains two space-separated integers $$$n$$$, $$$m$$$, and $$$x$$$. $$$n$$$ and $$$m$$$ represent the number of rows and columns, respectively, and the number $$$x$$$ represents the index on the bottom row that you start shining the laser pointer at (with 0-based indices). The next $$$n$$$ lines contain $$$m$$$ characters representing the hall of mirrors. If a position does not contain a mirror, it will be pictured as a single dot. If it does have a mirror, it will be represented with either a forward slash ("/") or a backslash, which represents the direction that it reflects light in. See the example cases if you are confused on this.

Output

Output the given input matrix, however, replace any positions without a mirror that the laser pointer shines through horizontally with a hyphen, and replace any positions without a mirror that the laser pointer shines through vertically with a pipe ("|"), above the ENTER key on a keyboard. If the laser pointer travels through a space in both directions, replace the dot in that position with a plus symbol ("+").

Examples
Input
10 10 5
..........
..........
/....\....
..........
..........
..........
..........
\.........
..........
..........
Output
..........
..........
/----\....
|....|....
|....|....
|....|....
|....|....
\----+----
.....|....
.....|....
Input
10 10 3
/.\.......
./....\...
..........
..........
.\.\......
..........
..\.../...
..........
..........
\.........
Output
/-\.......
|/+---\...
|||...|...
|||...|...
|\+\..|...
|.||..|...
|.\+--/...
|..|......
|..|......
\--+------

109. H.
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Drawn an H. You will be given a number the represents the length of the legs and middle portion of the H.

Input

One number representing the dimensions of the H.

Output

Print the H.

Example
Input
3
Output
H   H
H   H
H   H
HHHHH
H   H
H   H
H   H

110. Pyramid
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Much like the previous question, you are going to be making some ASCII art. In this question your job is to make a pyramid given a number that represents the base of the pyramid. Each layer going up from the base should be 2 less in length than the previous layer. The pyramid is complete when the length of the top layer is either 1 or 2.

Input

A single number representing the base of the pyramid.

Output

Print the pyramid using "X"'s

Example
Input
7
Output
   X
  XXX
 XXXXX
XXXXXXX

Note

Don't forget to add spacing on the left side so that it doesn't end up looking like a right triangle.

111. Word Subsitution
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In this question you must encrypt or decrypt a message by replacing a key letter with a word or a key word with a letter. If the message contains the key word then you should be decrypting and replacing the key word with the key letter. If the message given does not contain the key word then you should be encrypting and should be replacing the key letter with the key word. The key letter will not be within the key word.

Input

The first line will be the text you are encrypting or decrypting. The second line will be the key letter and the third line will be the key word.

Output

Print the encrypted or decrypted text

Examples
Input
hello world
l
bruh
Output
hebruhbruho worbruhd
Input
hebruhbruho worbruhd
l
bruh
Output
hello world

112. Unit Conversions
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Converting from one unit of measurement to another is very useful. Make a program that can convert between, feet, inches, meters, centimeters, miles, and kilometers. Use the following conversions to get the correct answer: .08333 feet in 1 inch, 3.28084 feet in 1 meter, 0.0328084 feet in one centimeter, 5280 feet in 1 mile, and 3280.84 feet in 1 kilometer.

Input

One line describing a conversion: Ex: "The road is 1.5 miles, how many kilometers is it."

Output

Print the value of the conversion and the unit.

Example
Input
I am 1.5 meters, how many feet am I
Output
4.92126 feet
Note

The first number and unit will always be right before the ",". after the "," it will always "how many" then the unit you are converting to.

113. Airplane!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're flying an airplane, but you forgot to forgot to refill the fuel tank before you trip. Therefore, you must decide which airport to land at based on a number of factors: proximity, available runway space, and direction. If an airport has no available spaces, you cannot go there. If an airport is too far away, you cannot go there.

Input

You will receive 3 lines of input, the first being n number of airports, the second being how many miles you can fly, and the third being the direction of the wind (N,S,W,E,NW,NE,SW,SE). Then you will receive n lines of input consisting of 3 variables separated by spaces: the number of available runway spaces, the distance to the airport in miles, and the direction you must fly to get to the airport.

Output

You will output a number that represents which airport you should fly to.

Example
Input
2
20
S
1 20 S
1 20 N
Output
1
Note

If you are flying with the wind direction, the amount of fuel you need to use is halved. If you are flying against the wind direction, it takes two times as much fuel to get to the airport.

114. Viginere Cipher
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

So I think the title explains it. Encrypt a given phrase using the vigenere cipher with a key that will be provided. The vigenere cipher is actually quite easy to use, just look at the image below. The left side is where the plain text characters go and the top is where the key letters go. The first letter of the plain text goes with the first letter of the key and all you do is draw a line across for the plain letter and a line down for the key letter. Where the two lines intersect is the new encrypted letter. Then you pair the second letter of the plain text with the second letter of the key and so on. Once you have reach the last letter of the key, you just go to the start of the key again. Also don't encrypt spaces, so just skip over them.

Input

The first line will be the plain text and the second line will be the key.

Output

Print the newly encrypted text.

Example
Input
Here is an example test case
fish
Output
Mmjl na su jfstutw ajal jfaw

115. Pseudocode Compiler
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In this question your goal is to make a program that will simulate running some pretty basic pseudocode. Here is the syntax that will be used:

Defining a variable: -"var variableName = value" -value can be any integer -value can be a simple math equations ex: "3 + 5" -value can be a simple math equation that includes a variable "testVar + 2"

Manipulating a variable: -"variableName = value" -same rules applied to what the value can be as the one above -Ex: "test1 = test1 + 2 - test2"

Printing: -"print (hello word )+exampleVariable+" -text that is being printed will be surrounded in parentheses -variables being printed will be surrounded in addition signs

Input

The first line will be the number of lines of code. The next X number of lines will be the code that you need to simulate.

Output

Print whatever the program prints.

Example
Input
6
print (hello world)
var a = 5
a = a - 1
var b = a + 3
var c = a + b
print +a+( + )+b+( = )+c+
Output
hello world
4 + 7 = 11

116. Diverse String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You consider a string to be a diverse string if every pair of adjacent characters are different. For example coderams is a diverse string, while hello is not.

Given a string, figure out whether or not it is a diverse string.

Input

The only line of input contains a single string, not containing spaces.

Output

If the string is a diverse string, output "YES" (no quotes). Otherwise, output "NO" (no quotes).

Examples
Input
coderamsclub
Output
YES
Input
helloworld
Output
NO

117. Books
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

You have a list of $$$n$$$ books. You want to read one complete book, but you want to read as few pages as possible. You're given the list of how many pages each book has. Figure out the minimum number of pages that you have to read, reading at least one complete book.

Input

The first line of input contains a positive integer $$$n$$$: the number of books. The next line contains $$$n$$$ space-separated integers: the number of pages of each book.

Output

Output a single positive integer $$$p$$$: the minimum number of pages that you have to read, if you read at least one complete book.

Examples
Input
5
179 173 275 865 180
Output
173
Input
5
500 450 300 299 100
Output
100

118. Colors
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

In computer graphics, colors are often given as three integers $$$R$$$, $$$G$$$, and $$$B$$$, each ranging from 0 to 255, inclusive.

When displaying a bright red color, $$$R$$$ = 255, $$$G$$$ = 0, and $$$B$$$ = 0.

When displaying a bright green color, $$$R$$$ = 0, $$$G$$$ = 255, and $$$B$$$ = 0.

When displaying a bright blue color, $$$R$$$ = 0, $$$G$$$ = 0, and $$$B$$$ = 255.

When displaying a bright yellow color, $$$R$$$ = 255, $$$G$$$ = 255, and $$$B$$$ = 0.

Given this information, figure out which color corresponds to a RGB-format color given in the input.

Input

The only line of input contains three space-separated integers $$$R$$$, $$$G$$$, and $$$B$$$: the values of $$$R$$$, $$$G$$$, and $$$B$$$ as described above.

Output

Output a single string: the color that the input values would display when drawn on a computer screen.

If the color is red, output "RED" (no quotes)

If the color is green, output "GREEN" (no quotes)

If the color is blue, output "BLUE" (no quotes)

If the color is yellow, output "YELLOW" (no quotes)

Examples
Input
255 0 0
Output
RED
Input
255 255 0
Output
YELLOW

119. Division One
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

You recently performed well in an online Codeforces contest, and you became part of "Division 1" on Codeforces. However, you're not sure that it will last. If you have a rating of 1900 or higher you're considered Division 1, otherwise, you're considered Division 2.

In each contest after you became Division 1, you didn't perform very well. Thus, your rating will decrease by 50 in each contest. Given your start rating, figure out how many contests it will take for you to become Division 2.

For example, if your start rating was $$$1970$$$, your rating would be $$$1920$$$ after the first contest, and after the second contest your rating would be $$$1870$$$, and you would become Division 2.

Input

The only line of input contains a single positive integer $$$n$$$: your rating after the recent good contest.

Output

Output a single positive integer $$$c$$$: the number of contests that you can still do before you become Division 2.

Examples
Input
1970
Output
2
Input
2035
Output
3
Input
3549
Output
33

120. What the Frac (Easier Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

Your 5-year-old cousin from the CodeRams Contest #5 (Problem 4) is now in 4th grade, and he is learning how to simplify fractions. Unfortunately, he doesn't really understand them, and he needs your help in simplifying fractions.

For this problem, you must write a program to convert a fraction $$$a$$$/$$$b$$$ to simplest form. For example, if the fraction was $$$6$$$/$$$8$$$, you can factor out a $$$2$$$, and the fraction simplifies to $$$3$$$/$$$4$$$, which is in simplest form.

Input

The only line of input contains a single fraction $$$a$$$/$$$b$$$: the fraction you need simplify. $$$a$$$/$$$b$$$ can be greater than one, but $$$a$$$ will not be a multiple of $$$b$$$. So $$$3$$$/$$$2$$$ would be a valid input, but $$$6$$$/$$$2$$$ would not.

Output

Output a single fraction $$$c$$$/$$$d$$$ in the same format as the input: the input fraction, in simplest form, as described above.

Examples
Input
6/8
Output
3/4
Input
72/48
Output
3/2
Input
37/73
Output
37/73
Note

In this problem, the input will be small enough for a brute force solution that tries all factors to run efficiently.

121. Space Invaders
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're traveling through space in your spaceship, when your ship's radar detects several hostile aliens near the ship. You need to figure out how close each alien is to your ship.

In three dimensions, the distance between two points, each with an X, Y, and Z coordinate, is defined as follows:

$$$D$$$ = $$$\sqrt{(X2-X1)^2 + (Y2-Y1)^2 +(Z2-Z1)^2}$$$

Given the coordinates of your ship, in 3D space, figure out how far away each alien is from your ship, using the formula described above.

Input

The first line of input contains three space-separated integers $$$X$$$, $$$Y$$$, and $$$Z$$$: the coordinates of your ship in 3D space. The next line of input contains a positive integer $$$n$$$ indicating the number of aliens that have been detected by the ship's radar. The next $$$n$$$ lines each contain three space-separated integers, each representing the coordinates of an alien.

Output

Output $$$n$$$ lines. On each line, output a single decimal number: the distance between your ship and each alien, in the order given in the input. You don't need to round your answers.

Examples
Input
7 3 8
6
2 1 5
3 7 6
4 2 1
9 8 4
7 3 8
5 11 16
Output
6.164414002968976
6.0
7.681145747868608
6.708203932499369
0.0
11.489125293076057
Input
2 4 6
3
-2 -4 -6
2 -4 -6
-2 4 6
Output
14.966629547095765
14.422205101855956
4.0

122. Autocorrect
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 20 points.

You're phone has incorrectly autocorrected some of your recent texts, and you're trying to make a more effective autocorrect system.

You're given an incorrectly spelled word. The similarity index of two words $$$s$$$ and $$$t$$$ is calculated as follows:

1. Define two variables: $$$tot$$$, representing the total pairs checked, and $$$mat$$$, representing the matches found.

2. Iterate through all pairs of letters in $$$s$$$ and $$$t$$$.

3. Increment $$$tot$$$ by one, and if the letters are equal, increment $$$mat$$$ by one as well.

The similarity index is calculated as mat / tot.

Given several words, your autocorrect system will choose the word which is the most similar to the original word, using the algorithm described above.

Input

The first line of input contains a single word $$$w$$$: the incorrectly spelled word, consisting only of lowercase characters. The next line contains a single positive integer $$$n$$$: the number of correctly spelled words in the dictionary. The next $$$n$$$ lines each contain a correctly spelled word $$$s$$$: a dictionary entry, consisting of only lowercase characters.

Output

Output $$$n$$$ lines. Each line should contain a word from the dictionary, and its similarity index, rounded to two decimal places. The words should be sorted from highest to lowest by their similarity index. If two words have the same similarity index, sort them alphabetically in reverse order.

Examples
Input
hello
5
helo
helllo
yello
hellow
helpo
Output
helllo 0.30
helo 0.25
yello 0.24
hellow 0.23
helpo 0.20
Input
coderams
8
cauliflower
coders
codered
classroom
codeforces
contest
code
coding
Output
coders 0.12
codered 0.12
code 0.12
codeforces 0.11
classroom 0.11
contest 0.07
coding 0.06
cauliflower 0.06

123. Affine Cipher
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 25 points.

You're trying to come up with a good Codeforces username. You want to use something similar to your real name, but not exactly your real name, to not release too much info about yourself online. Thus, you decide to encode your username using an Affine cipher.

An affine cipher uses a key of two values: $$$a$$$ and $$$b$$$. Given a letter $$$l$$$, you first convert it into it's "character code", for example, "a" would become $$$0$$$, "b" would become $$$1$$$, etc. We'll call this $$$x$$$. Then, you calculate the value of $$$a$$$$$$x$$$ + $$$b$$$ mod $$$26$$$, and reverse the character code mapping that you used previously, to convert the answer back into a letter. The affine cipher runs this process on all letters (not spaces) in a given string.

For example, let's use the letter $$$c$$$, and a key of $$$a$$$ = $$$15$$$, and $$$b$$$ = $$$5$$$. $$$c$$$ has a character code of $$$2$$$. Then, the encoded character has a character code of $$$15$$$*$$$2$$$ + $$$5$$$ mod $$$26$$$ = $$$35$$$ mod $$$26$$$ = $$$9$$$. Thus, the encoded character is $$$j$$$.

Input

The first line of input contains two space-separated integers $$$a$$$ and $$$b$$$: the affine cipher's key, as described above. The second line of input consists of a string consisting only of lowercase characters and spaces.

Output

Output the input string, encoded using the affine cipher as described above.

Examples
Input
7 5
xavier
Output
kfwjhu
Input
11 1
coderams club
Output
xzitgbdr xsnm

124. Tour De France
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 30 points.

You attended the final stage of the Tour De France, and after the event has ended, you want to know the final results. However, all you know is how long it took each biker to reach your position, and how fast they were traveling when they passed you.

Given your constant position during the race, the position of the finish line, and the information described above, you must figure out the final standings of the race. You can assume that after each biker passed you, they maintained a constant speed.

Input

The first line of input contains three space-separated integers $$$n$$$, $$$m$$$, and $$$k$$$, representing the number of bikers in the race, your position, in miles, and the position of the finish line, in miles, respectively. The next $$$n$$$ lines each contain a string representing each biker's name, and a space, followed by two space-separated decimal numbers, representing the time that the biker passed by you, in seconds, and the biker's speed, in miles per hour, respectively.

Output

Output $$$n$$$ integers: each biker's name, sorted by their overall place in the race. The biker that finished first should be first in the list, and the biker that finished last should be last in the list.

Example
Input
5 10 25
CadelEvans 20 30
BradleyWiggins 21 29
ChrisFroome 22 31
VincenzoNibali 25 80
GeraintThomas 5 17
EganBernal 8 21
Output
GeraintThomas
CadelEvans
BradleyWiggins
ChrisFroome
VincenzoNibali
Note

This problem was originally made for the contest where all of the problems were based on Kraftwerk songs. It was removed from the contest beforehand for various reasons.

125. Chord Identification
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You're listening to music, and you hear a major chord of three notes. You want to figure out which chord you just heard.

In music, the notes in a single octave, from lowest to highest, are as follows: C, C#, D, D#, E, F, F#, G, G#, A, A#, and B. Any two adjacent notes in this list are a "half step" apart. For example, C and D differ by 2 half steps, and A and D differ by 5 half steps.

Additionally, notes can be represented as both sharps and flats. For example, C# and D ♭ (D flat) are the same note, and D# and E ♭ are the same note. A flat note will be represented with a lowercase f in the input, such as "Df" for D flat.

A major chord has a $$$root$$$, a $$$third$$$ note, and a $$$fifth$$$ note. The root and the third note must differ by exactly four half steps, and the third and fifth note must differ by exactly three half steps. Correspondingly, the root and the fifth note must differ by exactly seven half steps.

Given this information, and a major chord, figure out what the root of the chord is. The notes of the chord can be given in any order, i.e. the root doesn't necessarily come first.

Input

The only line of input contain three space-separated notes. It is guaranteed that the notes form a major chord with the root being one of the three notes.

Output

Output a single note: the root of the chord.

Examples
Input
E G C
Output
C
Input
Bf Ef G
Output
Ef
Input
C F A
Output
F
Input
C# F Af
Output
C#

126. Subway System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You're going to a city that has a large subway system. The subway system has $$$n$$$ lines, and each line has a certain number of stations. However, some stations are "transfer stations": multiple lines go through them.

Given a list of the stations that each subway line goes through, your task is to figure out how many transfer stations exist throughout the subway system.

Note that "loop lines" that start and end at the same station may appear in the input, and stations that are the start and end of the loop but have no other lines going through them do not count as transfer stations. For a station to be a transfer station, it has to have multiple distinct lines going through it.

Input

The first line of input contains a single positive integer $$$n$$$: the number of lines in the subway system.

The next $$$n$$$ test cases each consist of two lines of input.

The first line consists of a single positive integer $$$m$$$: the number of stations in the given subway line

The next line contains $$$m$$$ space-separated station names, representing the route of the given subway line. The subway line might be a loop line.

Output

Output a single positive integer $$$s$$$: the number of transfer stations in the subway system. Then, output $$$s$$$ station names: the name of each transfer station in the subway system, in alphabetical order.

Examples
Input
6
7
Vienna EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory NewCarrolton
7
WiehleRestonEast EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter
8
FranconiaSpringfield KingStOldTown Pentagon Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter
5
BranchAvenue LenfantPlaza GalleryPlace FortTotten Greenbelt
6
Huntington KinStOldTown Pentagon LenfantPlaza GalleryPlace FortTotten
5
ShadyGrove MetroCenter GalleryPlace FortTotten Glenmont
Output
EastFallsChurch
FortTotten
GalleryPlace
LargoTownCenter
LenfantPlaza
MetroCenter
Pentagon
Rosslyn
StadiumArmory
Input
3
5
EastStation NorthStation WestStation SouthStation EastStation
2
WestStation CenterStation
2
NorthStation CenterStation
Output
CenterStation
NorthStation
WestStation
Note

Can you figure out which city has the subway system described in the first test case?

127. Latin Squares
time limit per test
8 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A latin square is defined as a 4 by 4 grid of numbers, where all of the numbers in each row and column are distinct, i.e. no two pairs of elements in each row and column are equal.

You're given a partially filled in latin square. Figure out how many valid latin squares can be formed by filling in the empty digits of the latin square.

Input

The input consists of 4 lines, each consisting of 4 integers: the digits in the latin square. For each digit, if it has already been filled in, it will be represented with a digit from 1 to 4, and if it hasn't been filled in yet, it will be represented with a "0".

Output

Output a single positive integer $$$n$$$: the number of ways to fill in the latin square as described above.

Examples
Input
0000
0000
0000
0000
Output
576
Input
1234
2341
3412
0000
Output
1
Input
1234
2341
3412
4311
Output
0

128. What the Frac (Harder Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 40 points.

Your 5-year-old cousin from the CodeRams Contest #5 (Problem 4) is now in 4th grade, and he is learning how to add fractions. Unfortunately, he doesn't really understand them, and he needs your help in adding two or more fractions together.

For this problem, you must write a program to add several positive fractions together.

Since the test cases can be large, you will need to use an efficient method to solve it.

When adding two fractions together, you first change the denominators into their LCM (least common multiple).

The LCM of two numbers $$$a$$$ and $$$b$$$ can be calculated using the following formula:

LCM($$$a$$$, $$$b$$$) = $$$\frac{a * b}{GCD(a, b)}$$$, where GCD represents the greatest common divisor of $$$a$$$ and $$$b$$$.

You can find the greatest common divisor (GCD) or $$$a$$$ and $$$b$$$ efficiently using the following recursive algorithm:

1. If $$$a$$$ is less than $$$b$$$, swap $$$a$$$ and $$$b$$$

2. If $$$b$$$ is equal to $$$0$$$, return $$$a$$$

3. Otherwise, return GCD($$$b$$$, $$$a$$$ mod $$$b$$$)

Input

The only line of input consists of a mathematical operation involving at least two fractions, each in the form $$$a$$$/$$$b$$$, and addition operations only

Output

If the answer simplifies to a whole number, print the number. Otherwise, output a single fraction $$$c$$$/$$$d$$$: the result of the addition of fractions described in the input, in simplest form. The answer will not be less than or equal to 0.

Examples
Input
3/4 + 2/3 + 7/9
Output
79/36
Input
8/7 + 8/9 + 17/11 + 33/53 + 89/77 + 65/59
Output
13993216/2167011
Input
2/3 + 7/3
Output
3
Note

If your code passes the second example case in under a second, it is efficient enough. Also, all input and output numbers are guaranteed to fit inside of an "int" data type in Java, if you code your solution efficiently.

129. Conway's Game of Life
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 45 points.

You're play a modified version of Conway's Game of Life on a 2D grid. Each cell on the grid can be represented as three states:

An asterisk, representing a cell that is "alive"

A period, representing a cell that is "dead"

An uppercase X, representing a "barrier".

On each turn, cells change their state depending on the following rules:

1. If the cell is not a barrier and is adjacent to any dead cells, the cell becomes a dead cell

2. If the cell is a barrier, is adjacent to only barriers, and is not on the edge of the board, it becomes a dead cell

Note that in these definitions, "adjacent to" refers to all 8 of the spaces next to a cell, including diagonally. Also note that all of the changes to cells take effect after the current turn, so the order that you apply the operations in doesn't matter.

It can be shown that if played infinitely many times, this (simplified) version of Conway's Game of Life will eventually converge on a single board state, i.e. the board will eventually never change between turns. Given a starting board, figure out the final state of the board if played infinitely many times.

Input

The first line of input contains two positive integers $$$n$$$ and $$$m$$$: the number of rows and columns, respectively. The next $$$n$$$ lines each contain $$$m$$$ characters, each representing a cell of the board, according to the rules above.

Output

Output a $$$n$$$ by $$$m$$$ board in the same format as the input: the final state of the board, after running the algorithm infinitely many times.

Examples
Input
6 6
*****X
****XX
**XXX.
**XXX.
**XXX.
XXX..*
Output
*****X
****XX
**XXX.
**X.X.
**XXX.
XXX...
Input
6 6
*****X
*.**XX
**XXX.
**XXX.
**XX..
XXX...
Output
.....X
....XX
..XXX.
..XXX.
..XX..
XXX...
Input
3 4
XXXX
XXXX
XXXX
Output
XXXX
X..X
XXXX

130. Minecraft Biome Finder
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 45 points.

You're playing Minecraft, and having fun exploring your world in Creative mode. Your world consists of Desert, Forest, and Taiga biomes.

You've explored some of the world, but not all of it. Thus, for some places, you know their biome, and for others, you don't. The world is given as a 2D top-down view, with some spaces ("chunks") unknown, and others with a known biome.

You especially like Taiga biomes. You've already explored at least one space that is a taiga biome, and you know that your world has exactly one taiga biome. Given this information, your task is to figure out the maximum amount of spaces (chunks) on the 2D world map that can be part of a taiga biome, and which spaces could potentially be part of the taiga biome.

Two spaces are considered part of the same biome if you can travel on the 2D grid from one space to the other, traveling on only spaces of the given biome. For example, if two spaces are both in Taiga biomes, but to travel from one to the other you are forced to cross a desert, they are not part of the same biome.

Input

The input consists of 20 lines, each containing 20 characters: the 20 by 20 world map.

If a given space is part of a Taiga biome, it will be represented by a "T" in the input file.

If a given space is part of a Desert biome, it will be represented by a "D" in the input file.

If a given space is part of a Forest biome, it will be represented by an "F" in the input file.

If you haven't explored a certain space, it will be representing as a single dot (".") in the input file.

Output

Output 20 lines: the given input, except if any unexplored spaces (chunks) could potentially be part of a Taiga biome, change their character to a "T".

Examples
Input
....................
....................
....................
.........T..........
....................
....................
....................
....................
....................
FFFFFF.F............
......F.F....FFFFFFF
.........F..........
..........FF........
.....DDDD....DDDD...
........DDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................
Output
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
FFFFFFTFTTTTTTTTTTTT
TTTTTTFTFTTTTFFFFFFF
TTTTTTTTTFTTTTTTTTTT
TTTTTTTTTTFFTTTTTTTT
TTTTTDDDDTTTTDDDDTTT
TTTTTTTTDDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................
Input
....................
....................
....................
.........T..........
....................
....................
....................
....................
....................
FFFFFF.F............
......F.F....FFFFFFF
.........F..F.......
..........FF........
.....DDDD....DDDD...
........DDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................
Output
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
FFFFFFTFTTTTTTTTTTTT
......F.FTTTTFFFFFFF
.........FTTF.......
..........FF........
.....DDDD....DDDD...
........DDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................
Input
....................
....................
.........DDDD.......
........DTD...D.....
........DDDDD.......
....................
....................
....................
....................
FFFFFF.F............
......F.F....FFFFFFF
.........F..........
..........FF........
.....DDDD....DDDD...
........DDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................
Output
....................
....................
.........DDDD.......
........DTD...D.....
........DDDDD.......
....................
....................
....................
....................
FFFFFF.F............
......F.F....FFFFFFF
.........F..........
..........FF........
.....DDDD....DDDD...
........DDDDDD...DDD
DDDDDDDD............
....................
....................
....................
....................

131. The Mirrors Strike Back
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 55 points.

If you competed in the CodeRams Contest #8, you might remember a problem involving mirrors and light. This is a more difficult and updated version of that problem.

You are in a hall of mirrors, and you shine a laser beam in a certain direction. Given the position of several diagonal mirrors, figure out the path of the laser beam.

You shine your laser beam from the back of the hall of mirrors (on a computer screen, this will look like the "bottom" of the image).

This problem also adds "star blocks", which shine light in all directions when light passes through them.

Input

The first line of input contains two space-separated integers $$$n$$$, $$$m$$$, and $$$x$$$. $$$n$$$ and $$$m$$$ represent the number of rows and columns, respectively, and the number $$$x$$$ represents the index on the bottom row that you start shining the laser pointer at (with 0-based indices). The next $$$n$$$ lines contain $$$m$$$ characters representing the hall of mirrors. If a position does not contain a mirror, it will be pictured as a single dot. If it does have a mirror, it will be represented with either a forward slash ("/") or a backslash, which represents the direction that it reflects light in. See the example cases if you are confused on this. Additionally, if the position contains a star block, it will be pictured as an asterisk ("*"). Star blocks redirect light in all four immediate directions (up, down, left, and right).

Output

Output the given input matrix, however, replace any positions without a mirror or star block that the laser pointer shines through horizontally with a hyphen, and replace any positions without a mirror or star block that the laser pointer shines through vertically with a pipe ("|"), above the ENTER key on a keyboard. If the laser pointer travels through a space in both directions, replace the dot in that position with a plus symbol ("+").

Examples
Input
10 10 5
......./..
..........
/....\....
..........
..........
..........
..........
\......*..
..........
..........
Output
......./--
.......|..
/----\.|..
|....|.|..
|....|.|..
|....|.|..
|....|.|..
\----+-*--
.....|.|..
.....|.|..
Input
10 10 2
../....\..
..........
/.*..\....
..........
..........
..........
..........
\......*..
..........
..........
Output
../----\..
..|....|..
/-*--\.|..
|.|..|.|..
|.|..|.|..
|.|..|.|..
|.|..|.|..
\-+--+-*--
..|..|.|..
..|..|.|..

132. Code RAMs
time limit per test
10 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 80 points.

You have a function $$$f(x)$$$, and you want to figure out how the area under $$$f(x)$$$ from 0 to $$$C$$$.

In calculus, this value is called the $$$integral$$$ of $$$f(x)$$$. For some functions, taking its integral is relatively easy and uses a few simple rules. However, for many functions, it is impossible to find their integral exactly. However, you can make an approximation of the integral, and since you're writing a computer program, you can make a close approximation.

One way to approximate the integral of a function is to use the Rectangular Approximation Method, or RAM. This method approximates the function $$$f(x)$$$ as $$$n$$$ rectangles, each having an equal width, and having varying $$$y$$$-values depending on the value of $$$f(x)$$$ at that point.

As you can see, the example with $$$n$$$=4 ($$$f(x)$$$ was divided into four rectangles) was not perfect. However, as $$$n$$$ gets larger and larger, the approximations get more and more accurate.

Formally, define the LRAM (Left Rectangular Approximation Method) approximation of the area under a function $$$f(x)$$$ from $$$0$$$ to $$$C$$$, using $$$n$$$ rectangles, as A, and the area of each rectangle as A1, A2 ... AN, as the following:

A = $$$\frac{A1 * C}{N}$$$ + $$$\frac{A2 * C}{N}$$$ + $$$\frac{A3 * C}{N} $$$+ ... + $$$\frac{AN * C}{N}$$$.

The area of each rectangle can be calculated using the standard formula A = $$$l$$$ x $$$w$$$. The width of each subrectangle is equal to $$$\frac{C}{n}$$$ (because there are $$$n$$$ rectangles with a total width of $$$C$$$). The length of each subrectangle is equal to $$$f(\frac{k * c}{n})$$$, where $$$k$$$ represents the index of the rectangle, ranging from $$$0$$$ to $$$n - 1$$$, inclusive.

Since your answer must be a relatively close approximation, but your program should fit inside of the 10 second time limit (longer than usual for this problem), you should set $$$N$$$ equal to 50000.

Input

The only line of input contains a calculus equation. The equation will consist of the variable $$$x$$$, exponents, parentheses, and multiplication, division, addition, and subtraction operations. For example, $$$\frac{x^2 - 3}{x^3 - x + 5}$$$ would be a valid input, but $$$cos(x)$$$ would be not.

Output

Output a single decimal number: the area under $$$f(x)$$$ from $$$x$$$=$$$0$$$ to $$$x$$$=$$$C$$$. Your number should be close to the actual answer, but it doesn't have to be exact. Using eval() or similar commands in your program is not allowed.

Examples
Input
x^3 + x^2
2
Output
6.666426668800027
Input
(x^2 + x + 3) / (x^3 + x^2 + 5x)
7
Output
0.9806709605550483
Input
x^2
5
Output
41.66541667500017
Note

In the first sample case, $$$6.663$$$ would be judged as correct, but $$$7$$$ would be judged as incorrect.

133. Question-able Difficulty
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You consider a string to be a question if its last character is a question mark. Given a string, figure out whether or not it is a question.

Input

The only line of input contains a single string $$$s$$$.

Output

If the given string is a question (if it has a question mark on the end), output "YES" (no quotes). Otherwise, output "NO" (no quotes).

Examples
Input
Welcome to the CodeRams contest?
Output
YES
Input
We hope you like the problems!
Output
NO
Input
Good luck today
Output
NO

134. Alarming String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You define a string to be an alarming string if it contains exactly three "a" characters. Given a string, possibly containing spaces, figure out whether or not it is an alarming string.

Input

The only line of input contains a single string $$$s$$$, consisting of only lowercase characters.

Output

Output "YES" (no quotes) if the given string is an alarming string, as described above, and "NO" (no quotes) otherwise.

Examples
Input
coderams competition number eleven
Output
NO
Input
aardvark
Output
YES
Input
an apple actually appeared
Output
NO

135. Anti-sort
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You're given a list of $$$n$$$ words. You've discovered that when a rival CodeQuest team finds a list of words, they sort it in alphabetical order. To distinguish yourself from your rival CodeQuest team, you decide to sort the list of words in reverse order.

Input

The first line of input contains a single positive integer $$$n$$$: the number of words.

The next $$$n$$$ lines each contain a single word, consisting only of lowercase letters

Output

Output $$$n$$$ lines: the list of words, sorted in reverse alphabetical order.

Examples
Input
2
coderams
club
Output
coderams
club
Input
11
hello
world
we
hope
you
enjoy
the
contest
today
good
luck
Output
you
world
we
today
the
luck
hope
hello
good
enjoy
contest

136. Math Team
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You're competing in a large individual math team contest. In the contest, you're given several sets of problems, and for each one of them you get a certain number of them correct. Given this information, you want to figure out your total score in the competition.

For example, if you scored a 2 out of 3 on the first problem set, and a 3 out of 5 on the second problem set, your total score would be 5 out of 8.

Input

The first line of input contains a single positive integer $$$n$$$: the number of problem sets.

The next $$$n$$$ lines contain two integers separated by a slash "/": the number of questions you got right in the problem set, and the total number of questions in the problem set.

Output

Output two slash-separated integers: the total number of questions you got right, and the total number of question you got wrong, respectively.

Examples
Input
5
2/5
4/6
8/11
3/8
1/9
Output
18/39
Input
5
6/6
5/6
3/6
0/6
5/8
Output
19/32

137. Cheesy Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You consider a number to be cheesy if it is divisible by the sum of its digits. For example, the sum of the digits of 360 is 9, and 360 is divisible by 9, so 360 is a cheesy number. On the other hand, the sum of digits of 87 is 15, and 87 is not divisible by 15, so 87 is not a cheesy number.

Given a number $$$n$$$, figure out whether or not it is a cheesy number.

Input

The only line of input contains a single integer $$$n$$$: the number to test. $$$n$$$ is guaranteed to fit inside of an "int" data type in Java.

Output

If $$$n$$$ is a cheesy number as described above, output "YES" (no quotes). Otherwise, output "NO" (no quotes).

Examples
Input
360
Output
YES
Input
87
Output
NO
Input
72
Output
YES

138. Perfect Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 15 points.

A number is considered a perfect number if and only if the sum of its divisors, except for the number itself, is equal to the original number. For example, 28 is a perfect number because its divisors are $$$1$$$, $$$2$$$, $$$4$$$, $$$7$$$, and $$$14$$$, and $$$1$$$ + $$$2$$$ + $$$4$$$ + $$$7$$$ + $$$14$$$ = $$$28$$$.

Given an integer $$$n$$$, figure out whether or not it is a perfect number, and what the sum of its divisors (except for $$$n$$$) is.

Input

The only line of input consists of a single integer $$$n$$$.

Output

Output two lines.

On the first line, output "PERFECT NUMBER" (no quotes) if the number is a perfect number, and "NOT A PERFECT NUMBER" (no quotes) if the number is not a perfect number. On the second line, output the sum of divisors of the number.

Examples
Input
28
Output
PERFECT NUMBER
28
Input
48
Output
NOT A PERFECT NUMBER
76
Note

All numbers used in calculations are guaranteed to fit inside of a Java "int" data type.

139. Dynamic Sorting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 20 points.

Your computer outputs $$$n$$$ integers randomly. You think it might be a secret code, so you decide to make a list of the numbers, but maintain the list in sorted order as you add each number.

For example, if the computer output was $$$3$$$ $$$4$$$ $$$2$$$ $$$8$$$ $$$7$$$, you would first add $$$3$$$ to the list, making the list [3].

Then, you would add $$$4$$$ to the list, making the list [3, 4].

Then, you add $$$2$$$, putting it first in the list to maintain the list's sorted order. The list becomes [2, 3, 4]

The process proceeds until the list is [2, 3, 4, 7, 8] after the final step.

Input

The first line of input contains a positive integer $$$n$$$: the amount of numbers your computer has printed out.

The next $$$n$$$ lines contain $$$n$$$ integers: the numbers that your computer printed out.

Output

Output $$$n$$$ lines. On the $$$k$$$th line, output $$$k$$$ integers: the sorted list after adding the $$$k$$$th number from the computer's output to the list.

Example
Input
5
3
4
2
8
7
Output
3
3 4
2 3 4
2 3 4 8
2 3 4 7 8

140. Continental Breakfast
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 20 points.

You're eating at a continental breakfast in a hotel, and there are two menu options. Each menu option consists of several food items. You want to find how many food items are contained in both menus.

Input

The first line of input consists of a single positive integer $$$n1$$$: the number of food items on the first menu. The second line of input consists of $$$n1$$$ space-separated strings: the food items on the first menu.

The third line of input consists of a single positive integer $$$n2$$$: the number of food items on the second menu. The fourth line of input consists of $$$n2$$$ space-separated strings: the food items on the second menu.

Output

Output a single positive integer $$$n$$$: the number of food items that are contained on both menus. Then, output $$$n$$$ lines: each food item which is contained on both menus, in alphabetical order.

Examples
Input
3
Pastries Waffles Eggs
4
Waffles FrenchToast Eggs Cereal
Output
2
Eggs
Waffles
Input
3
Eggs Waffles Pastries
2
FrenchToast Cereal
Output
0

141. Majestic Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 30 points.

You define a string to be a majestic string if each successive character in the string comes one character later in the alphabet than the one before it. For example, bcdef is a majestic string, and so is xyz, but acd is not a majestic string. The characters also wrap from z to a, so yzab is a majestic string.

Given a string $$$s$$$, figure out whether or not it is a majestic string, using the rule described above.

Input

The only line of input contains a single string $$$s$$$.

Output

If $$$s$$$ is a majestic string, output "YES" (no quotes). Otherwise, output "NO".

Examples
Input
cdefghij
Output
YES
Input
tuvwxyzab
Output
YES
Input
hellllo
Output
NO

142. Hydra Tree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You have a tree that is growing very fast. At first, the tree has one branch. On each successive day, the tree grows a certain number of branches. On each day, the number of new branches is calculated as $$$n$$$ times $$$b$$$, where $$$b$$$ represents how many branches were on the tree on the previous day, and $$$n$$$ is a variable you have to calculate. $$$n$$$ will always be greater than one.

At an unknown number of days, the tree has $$$x$$$ branches. Given this value, figure out the minimum possible value of $$$n$$$ used in the formula, given that the tree started out with exactly one branch.

Input

The only line of input contains a single positive integer $$$x$$$. $$$x$$$ will be less than 10000.

Output

Output a single positive integer $$$n$$$: the minimum possible value of $$$n$$$, greater than one, such that the tree could have $$$x$$$ branches at some point. $$$n$$$ has to stay the same throughout the entire process of growing the tree, i.e. it cannot change between days.

Examples
Input
36
Output
5
Input
66
Output
65

143. Zoom Meeting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You're attending an international Zoom call during the Coronavirus quarantine, where the attendees represent many different countries. The zoom call is really long, and to pass the time, you tally how many people are from each country.

Given the list of people and their countries, print the countries, and how many meeting attendees are from each country. Sort the countries first by their number of attendees, and if two countries have an equal number of attendees, sort them alphabetically by the name of the country.

Input

The first line of input contains a single positive integer $$$n$$$: the number of meeting attendees.

The next $$$n$$$ lines each contain a single country name $$$c$$$.

Output

If there are less than five lines of input, output $$$n$$$ lines: each country, and it's number of meeting attendees, separated by a space.

Otherwise, output 5 lines: each of the top 5 countries using the sorting method described above, and it's number of meeting attendees, separated by a space.

Examples
Input
11
USA
Sweden
Argentina
Cameroon
Egypt
Australia
England
France
Russia
Mongolia
India
Output
Argentina 1
Australia 1
Cameroon 1
Egypt 1
England 1
Input
4
USA
USA
Mexico
Mexico
Output
Mexico 2
USA 2
Input
9
USA
Germany
Brazil
China
USA
China
China
USA
USA
Output
USA 4
China 3
Brazil 1
Germany 1

144. Triangulation Rocks the Nation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You have a triangle with three points given in coordinates. Given this information, figure out the triangle's area. The points can be given in any order.

To calculate the area of a triangle, you can use Heron's Formula, which is described below:

Define $$$A$$$, $$$B$$$, and $$$C$$$ to be the lengths of the three sides of the triangle.

Define $$$S$$$ to be equal to $$$\frac{A + B + C}{2}$$$.

Then, the area of the triangle is calculated as $$$\sqrt{S(S - A)(S - B)(S - C)}$$$.

Input

The input consists of three lines, each consisting of two space-separated integers $$$x$$$ and $$$y$$$: the coordinates of each point of the triangle.

Output

Output a single decimal number $$$a$$$: the area of the triangle, using Heron's Formula as described above. Do not round your answer.

Examples
Input
1 1
5 4
2 8
Output
12.5
Input
0 0
8 0
4 8
Output
32.0
Input
-1 -3
2 7
9 -11
Output
62.0
Note

This triangle corresponds to the first example case:

145. Star Wars
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 40 points.

You've traveled across a galaxy far, far away, and you land on a planet with two different alien species. Each alien species counts numbers in a different base. Aliens of the first species count numbers using base $$$a$$$, and aliens of the second species count numbers using base $$$b$$$. The base used by most humans is decimal, base 10.

The two alien species are about to start a war, because they cannot properly communicate in numbers. Your task is to convert a number from the first alien species, in base $$$a$$$, into base $$$b$$$, in order to avert the impending alien war.

Input

The first line of input contains two integers $$$a$$$ and $$$b$$$ less than or equal to 10: the number base used by the first alien species, and the number base used by the second alien species, respectively.

The second line of input contains a single integer $$$n$$$ in base $$$a$$$.

Output

Output $$$m$$$: the given integer, converted from base $$$a$$$ to base $$$b$$$.

Examples
Input
7 9
63642
Output
23550
Input
10 3
8790971
Output
121112121221112
Input
5 6
3124
Output
1530

146. Gold Miner
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 40 points.

You're standing in a large 2D grid. The grid consists of several gold blocks. The gold is highly sought after , so for each position in the grid you want to calculate how many steps it would take to walk to the nearest gold block. You can walk left, right, up, or down, but not diagonally.

Input

The first line of input contains a single integer $$$n$$$: the size of the square grid.

The next $$$n$$$ lines each contain $$$n$$$ characters, representing the status of each position in the grid. If the position contains a gold block, it will be represented with an "X". If the position doesn't contain a gold block, it will be represented with a single dot ".".

Output

Output $$$n$$$ lines: the board, after making a few modifications:

Positions with gold blocks should remain an "X".

Positions without gold blocks that are under 10 blocks away from the nearest gold block in walking distance should be represented by their walking distance to the nearest gold block.

Otherwise, positions without gold blocks that are at least 10 blocks away from the nearest gold block in walking distance should remain a single dot ".".

Examples
Input
10
..........
....X.....
..........
..X....X..
..........
..........
..X.......
..........
..........
..........
Output
5432123345
4321X12234
3212122123
21X1221X12
3212332123
3212343234
21X1234345
3212345456
4323456567
5434567678
Input
10
..........
..........
..........
..........
..........
..........
..........
..........
..........
.........X
Output
.........9
........98
.......987
......9876
.....98765
....987654
...9876543
..98765432
.987654321
987654321X

147. Triangulation Rocks the Nation Again
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 60 points.

This is a sigificantly harder version of a previous problem in the contest. We recommend you solve the earlier problem first.

You're given the coordinates of an $$$n$$$-sided polygon. The polygon is not necessarily a regular polygon (the sides and angles are not necessarily equal), but the polygon is guaranteed to be convex (the polygon will not contain any angles greater than or equal to 180 degrees).

Given this information, figure out the area of the given polygon.

Input

The first line of input consists of a positive integer $$$n$$$ greater than three: the number of sides of the polygon.

The next $$$n$$$ lines each contain two space-separated integers: the $$$x$$$ and $$$y$$$ coordinates of each point of the polygon.

None of the sides of the polygon will be completely vertical.

Output

Output a single decimal number $$$a$$$: the area of the given $$$n$$$-sided polygon. Remember, the polygon is guaranteed to be a convex polygon.

Examples
Input
4
0 5
5 0
0 -5
-5 0
Output
50.0
Input
5
6 6
4 3
2 1
1 5
3 7
Output
15.5
Input
4
1 1
2 3
3 6
4 9
Output
1.0
Note

It might help to use your code from the easier version

148. Internet Anagram Server
time limit per test
15 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a string, consisting of at most seven characters, not including spaces. You want to find all of the anagrams of the string. A string $$$t$$$ is defined as an anagram of a string $$$s$$$ if an only if the characters of $$$s$$$, in sorted order, not including spaces, are equal to the characters of $$$t$$$, in sorted order, not including spaces.

You're also given a dictionary of $$$n$$$ words.

An anagram is considered a valid anagram if it consists of only space-separated words that are in the dictionary. For example, if the dictionary was the English dictionary, hello and hello world would be valid anagrams, but he llo and helloworld would not be valid anagrams.

Given the string, and the dictionary, print all of the valid anagrams of the string, in alphabetical order.

Input

The first line of input contains a single string $$$s$$$, possibly containing spaces. $$$s$$$ will have less than or equal to seven characters, not including spaces.

The next line of input consists of a single positive integer $$$n$$$, indicating how many words are in the dictionary.

The next $$$n$$$ lines each contain a word not containing spaces: each dictionary entry.

Output

Output all of the words or phrases that are valid anagrams of the given string, in alphabetical order. Make sure not to repeat words, i.e. all of the answers should be distinct.

Examples
Input
coderam
12
arm
codes
dore
smac
do
res
mac
armcodes
blahblah
coderam
rams
code
Output
arm code
code arm
coderam
dore mac
mac dore
Input
hello
5
he
ll
o
hel
lo
Output
he ll o
he o ll
hel lo
ll he o
ll o he
lo hel
o he ll
o ll he

149. Pythagorean Theorem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For this problem, you will be given two side lengths of a triangle and will be required to determine the length of the other side. You can assume that all input will be provided for a valid right triangle. The two side lengths you will be given correspond to the common variables $$$A$$$ and $$$C$$$, meaning one side and the hypotenuse. You should then output the length of side $$$B$$$.

Input

Two space-separated integer values that represent $$$A$$$ and $$$C$$$ respectively.

Output

A single floating point value that represents the length of side $$$B$$$.

Example
Input
9 10
Output
4.358898943540674
Note

Make sure that you are finding the length of side $$$B$$$ and not $$$C$$$(the hypotenuse).

150. Valid Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your task for this problem is to take the three side lengths of a triangle and to determine if these side lengths could create a "valid" triangle. A triangle is considered valid if the addition of any two side lengths is less than the length of the other side, in other words, the following must evaluate to true: a+b>c, a+c>b, b+c>a.

Input

The first line contains three space separated integers that correspond to the lengths of sides a, b, and c respectively.

Output

Output either "VALID" or "INVALID" depending on if the provided side lengths create a valid or invalid triangle.

Examples
Input
1 5 1
Output
INVALID
Input
4 5 6
Output
VALID

151. Triangle Trigonometry
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For this problem, you will be asked to solve specified trigonometry problems. You will be given individual problems that contain sin,cosine,tangent,cosecant,secant, and cotangent. Each test case will specify which operation should be used, using the following keywords: "sin,cos,tan,cosec,sec,cotan". Each test case will also provide the value that should be input into the various trigonometry functions. Your program should output the result of each computation.

Input

The first line contains a keyword of the format "sin,cos,tan,cosec,sec,cotan" that signifies which operation should be computed. The second line contains a floating point value that acts as the input to the trigonometry equation.

Output

A single floating point value that represents the computation of the input with the given trigonometry equation.

Example
Input
sin
2
Output
0.9092974268256817

152. Unit Circle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Unit Circle is a very commonly used geometric representation of all possible right triangles with a hypotenuse length of one. If you have not yet encountered the unit circle in math class, the coordinates of each point on the circumference of the circle can be found simply by finding the sin and cosine of the angle created between the point and (0,0). The x value can be found as the cosine of the angle while the y value can be found as the sin of the angle. For this problem, you will be given the angle(from 0 to 359), and you should output the x value.

Input

A single integer ranging from 0 to 359 that corresponds to the angle of the point on the unit circle.

Output

A single floating point value that represents the x value of the point created on the unit circle by the given angle.

Example
Input
30
Output
0.8660254037844387

153. Parity Checker
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Though digital communications are highly accurate, errors can occur from time to time. To deal with such communications errors, methods to detect and fix errors have been invented. One very common and simple method for this is known as a parity bit. When a message is being sent digitally in the form of bytes of 8 bits, a ninth parity bit can be added that is either 1 if the message has an even number of 1s(in binary), or 0 if the message has an odd number of 1s. While this method clearly will only work if there are an odd number of errors, it is a useful heuristic for detecting many errors without the need for more computation intensive methods. Your task for this problem is to write a program to determine if a nine bit sequence of binary is valid according to a parity check. The first bit on the left represents the parity bit, and the following 8 bits correspond to the one byte message that is to evaluated for parity.

Input

Exactly 9 consecutive binary bits will be provided as input in the form of a one-line string with no spaces. The first bit on the left represents the even-parity bit, and the next eight bits represent the message being communicated.

Output

Output either "NO ERROR" if the parity check is valid or "TRANSMISSION ERROR" if the parity check fails.

Example
Input
100110101
Output
NO ERROR

154. BCD Conversion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Binary Coded Decimal(BCD) is a method of representing a value with binary notation while using the same digit places as base 10(decimal). For example, the value 783 in decimal translates to 1100001111 in standard binary, though it would instead translate to 011110000011 in binary converted decimal. This BCD converted value is composed of three chunks of 4 bits each, where each 4-bit chunk corresponds to a different digit from 783. While BCD is not used as commonly in software development, it is critical in 7-segment display systems. These circuits display a multi-digit number by splitting it into its individual digits, then sending each individual digit to a different display, creating the image of an entire number with multiple digits. Your task for this problem will be to take a base-ten decimal and to convert it into a BCD value. Each base-10 digit should be represented by four binary digits, and the individual chunks should be concatenated together to produce the final output.

Input

A single integer value that represents the value to be converted to BCD.

Output

A single binary value that represents the inputted value after being converted to BCD.

Example
Input
7193
Output
0111000110010011

155. Array Statistics
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For this task, you will be required to find a set of simple statistics based on a given set of data. Data will be provided as an array of integers, and you will be tasked with finding the mean, median, mode, and range of the data.

Input

The first line will contain $$$n$$$, the number of values in the array. The second line will contain space-separated integers that correspond to the array of input values.

Output

The output should print the mean, median, mode, and range of the provided data in order and separated by lines(ie. the first line has the mean, the second line has the median, etc).

Example
Input
5
2 2 8 1 5
Output
3.6
2.0
2
7

156. Closest Houses
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For this problem, you will be tasked with sorting a series of houses by how close they are to a given house. The rules for house distances are as follows: houses on the same street will have have a distance of the difference between their house numbers, and houses on different streets will experience a distance equal to the difference between their house numbers times the difference between their street numbers. Houses will be each provided with a unique name, such as "h1", and will also have a street number that represents which street they live on as well as a house number that represents their position on the street. For this problem, you will be given a series of houses and their respective values and you will need to determine which house is the closest to a specified house. For example, you may be given h1,h2,h3,h4,h5, then asked to find the closest house to h3.

Input

The first line of input contains a single integer $$$n$$$ that represents the number of houses that are contained in the set. The next $$$n$$$ lines each contain information about a different house in the format: "name streetnum housenum". After $$$n$$$ lines, there will be one line that lists the name of the house that should be used in the nearest house computation.

Output

A single string that represents the house that is closest to the given house name.

Example
Input
5
h1 1 100
h2 1 2
h3 2 15
h4 5 3
h5 3 7
h5
Output
h3

157. Computing Sin
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While the equation of sin is highly stressed in high school math class, the methods for computing the sin of any input algebraically is usually not explained. There are various methods that can be used by computers or by hand, though the Taylor Approximation and CORDIC methods are most common. Calculators use CORDIC for its high speed and accuracy, though this problem will cover the Taylor Approximation method. If you have not yet had experience with calculus or the Taylor series, a Taylor Approximation is essentially a way to represent a function as a series of polynomial expressions. The use or details of this concept is not relevant to the question, though it is important to not that a Taylor Series will approximation its original function. In the case of the sin operation, the Taylor Approximation can be found as $$$x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!}...$$$ The pattern can be repeated continuously to increase the accuracy of the approximation, and the approximation will only work on smaller radian values of input. In addition, if you have not seen the $$$!$$$ operator before, it is known as the factorial. The factorial of a number can be computed as the number multiplied by each integer below it, so $$$3! = 3*2*1 = 6$$$. For this problem, you will be provided with number of terms to use for the Taylor Approximation along with a radian angle value for input into the equation. You should then output the approximation for sin of this input value using the given number of terms of the Taylor Approximation.

Input

The first line will contain a single integer that represents the number of terms of the Taylor Approximation to use. The second line will have a single radian value that is to be input into the equation.

Output

A single floating point value that represents the approximation of sin with the given number of equation terms and the given input value.

Example
Input
5
1
Output
0.8414710097001764

158. Dot Product
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For this problem, you will be tasked with finding the dot product of two given matrices. Dot products are a very common matrix operation, and find uses in many fields of math, computer science, and physics. If you haven't had any experience with a matrix in the past, think of matrices as a "table" of values, similar to a multi-dimensional array. Matrices can be of any dimension, yet this problem will only focus on two dimensional matrices. The result of a dot product operation on two matrices m1 and m2 in the form m1*m2 will result in a matrix with the same number of rows as m1, and the same number of columns as m2. It is difficult to explain the computation of the dot product in text, so here is an image representing it:

While there are many other aspects and components of the dot product operation, this is a simple and usable form of it. Your program should take two matrices m1 and m2, then compute the dot product of these as m3.
Input

The first line contains four space separated integers, representing the width of m1, the height of m1, the width of m2, and the height of m2 respectively. The next lines will contain each row of m1 followed by each row of m2. Each row will include space separated integers that correspond to the values in that row of the matrix.

Output

A single matrix that represents the result of computing the dot product of m1 and m2.

Example
Input
2 2 2 2
1 2
3 4
5 6
7 8
Output
19 22 
43 50 

159. Maximum Value in Pascal's Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pascal's Triangle is a famous concept in mathematics, and it has proven to have incredible relevance in many fields of mathematics even hundreds of years after its creation. The triangle is very simple to construct, starting out with just the number one centered on the first line of a sheet of paper. On the second line, write two ones centered just to the left and right of the one above. For any given line on the triangle, a value is found by adding the value to the upper right and upper left of the specified point, even if the upper right or upper left doesn't exist(meaning the specified point is on the edge of the triangle). Values on the edge of the triangle will always be 1. Your task for this problem is to find the maximum value on a given line of pascal's triangle(with the top line being 0).

Input

A single integer that represents the line of pascal's triangle(with the top line being 0) to have the maximum found for.

Output

A single integer that represents the maximum value on the given line of Pascal's Triangle.

Example
Input
5
Output
10
Note

If you are struggling with figuring this task out, take a look at binomial coefficients.

160. Ken Ken Book
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.

You're solving Ken Ken puzzles from a puzzle book. Each puzzle is an $$$n$$$ by $$$n$$$ grid, and you have to fill in all of the spaces in the grid.

There are also $$$k$$$ "freebie" spaces, which have already been filled in.

Given $$$n$$$, the size of the grid, figure out how many total spaces you have to fill in. For example, to solve a 4 by 4 puzzle with two freebies, you would have to fill in 14 spaces.

Input

The first line of input consists of a single positive integer $$$n$$$: the size of the puzzle, indicating that the puzzle is an $$$n$$$ by $$$n$$$ grid.

The second line of input consists of a single positive integer $$$k$$$: the number of freebie spaces in the grid that have already been filled in.

Output

Output a single integer $$$k$$$: the number of spaces in the puzzle that you have to fill in.

Examples
Input
4
2
Output
14
Input
6
3
Output
33
Note

If you like Ken Ken, you should look at the hardest problem in this contest, which asks you to write a program to solve a Ken Ken puzzle.

161. Haircut
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

After the end of hair salon restrictions of quarantine, many clients come to get their hair cut. Naturally, after months of uncut hair, your client's hairdos can be quite long! Your clients all have a preference of how long their hair needs to be after it is cut, and you can measure how long their hair is once you start cutting their hair.

You must determine how much hair you have to cut in order to reach the specified length of hair the client requested.

Input

The first line will contain an integer $$$n$$$ which denotes the amount of test cases that will follow. Each line succeeding this value will contain two space separated integers representing the length in hair (in inches), the first one being the length of hair your client has at the beginning of the haircut, and the second being the length of hair your client wishes to have at the end of the haircut.

Output

For each test case, print the amount of hair you must cut in order to fit the client's requirements.

Example
Input
3
14 8
12 5
25 15
Output
6
7
10

162. Parallel Lines
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

Your younger sibling needs help with their algebra homework, and it involves a full worksheet of detecting parallel lines in equations! Too inarticulate to explain how to find these parallel lines, you decide to create a piece of code that will solve the problems for them.

Input

You will be given two lines of linear equations in $$$y=mx+b$$$ form. See the example input for the exact formatting. $$$m$$$ will always be written before the $$$x$$$ term, even if $$$m$$$ is equal to 1.

Output

If the two linear equations are parallel, output "PARALLEL", otherwise output "NOT PARALLEL".

Examples
Input
y=17x+12
y=2x+21
Output
NOT PARALLEL
Input
y=-8x+3
y=-8x+1
Output
PARALLEL

163. FizzBuzz
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

A "FizzBuzz" question is a standard interview question given to any computer science job applicants that tests the applicant's aptitude to solve and code basic problems, including the style they program in. A shocking fact, but many entry level computer science graduates do not know how to practically code, and this question is able to filter out the applicants that do not have the ability to program out of a simple question.

Given two numbers, $$$x$$$ and $$$y$$$, print out the numbers in between these two numbers, $$$x$$$ (inclusive) and $$$y$$$ (exclusive), but if the number is a multiple of 3, replace the printed number with the string, "Fizz", and if the number is a multiple of 5, replace the printed number with the string, "Buzz". If the number is a multiple of both 3 and 5, replace the printed number with the combination of the two strings, "FizzBuzz".

Input

Given two line-separated integers $$$a$$$ and $$$b$$$, implement the method described above.

Examples
Input
1
16
Output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
Input
11
18
Output
11
Fizz
13
14
FizzBuzz
16
17

164. Cashier
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You are working as a cashier for a supermarket, and items are handed to you to be scanned one by one by the customer. You do not know how many items they have, but after the last item is scanned, the customers usually say, "done".

Input

A series of row separated floats representing prices, with the word "done" succeeding the last item of the customer's cart.

Output

Print out the total price of all the items.

Examples
Input
4.99
9.99
5.49
19.49
done
Output
39.959999999999994
Input
6.39
38.13
1996.39
105.30
55.99
done
Output
2202.2

165. In The Zone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While doing your gym assignments in quarantine, your gym teacher makes you record your heart rate after your workouts, and separates them into five "zones". These zones of fitness are sorted dependant on your maximum heart rate (MHR), which is determined by taking your age, and subtracting it from 220.

The zones are separated thusly:

Zone 5: 90 - 100 percent of MHR

Zone 4: 80 - 89 percent of MHR

Zone 3 : 70 - 79 percent of MHR

Zone 2 : 60 - 69 percent of MHR

Zone 1 : <60 percent of MHR

Input

Given the first line as the age of the student, the second line will contain an integer $$$n$$$ which denotes the amount of test cases to follow.

Output

Print the appropriate fitness zone for each given test case.

Examples
Input
16
3
165
152
86
Output
Zone 4
Zone 3
Zone 1
Input
25
5
103
166
182
153
123
Output
Zone 1
Zone 4
Zone 5
Zone 3
Zone 2

166. Counting Calories (Easier Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 20 points.

Over the quarantine season, you decide to watch your weight by limiting yourself to a certain amount of calories a day. In your house, you stocked up on a small variety of foods before the quarantine, and regardless of what time of the day it is, you must choose from these items:

Steak: 500 Cal

Apple: 100 Cal

Bread: 50 Cal

Input

You will be given a number $$$n$$$, denoting the number of calories you have limited yourself to for the day.

$$$n$$$ will be divisible by 50.

Output

Print the minimum amount of articles of food you must consume for the day in order to reach your caloric limit exactly.

Examples
Input
2350
Output
Steak: 4
Apples: 3
Bread: 1
Input
2500
Output
Steak: 5
Apples: 0
Bread: 0

167. Blackjack
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the card game of blackjack, a player competes with a dealer, who in the first rounds, distributes two cards to both the player, and to themselves. These two cards determine the play of the next turn, as the objective of the game is to achieve a total score of 21, through the combination of number and face cards.

Each face card is worth 10 points, while the number cards are worth their value points in their numbers. An ace, however, is worth 11 points, but if an ace causes the player's pool to go over its 21 point limit, it may become devalued to 1 point.

Input

You will be given two space-separated card values, the total of which will not be less than 10. Assume that given aces will automatically be valued at 11.

Output

Print out the card value that you must get for the next round in order to reach a score of 21. If 10 points are needed, print "FACE CARD/10". If the two given cards' total value is already equal to 21, print, "BLACKJACK".

Examples
Input
A 10
Output
BLACKJACK
Input
3 8
Output
FACE CARD/10
Input
6 4
Output
A
Input
6 7
Output
8

168. Pascal's Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 30 points.

First envisioned by the French mathematician, Blaise Pascal, Pascal's Triangle is a formation of numerals that are arranged in such a way that a number composing a part of the triangle is the summation of the adjacent binomial pair of the previous row in the triangle.

Input

The only line of input contains a single positive integer $$$n$$$.

Output

Output $$$n$$$ lines. The $$$i$$$th line should contain $$$i$$$ space-separated integers, consisting of the $$$i$$$th row of Pascal's Triangle.

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

169. SOS
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 30 points.

Morse code, developed in 1837, along with the invention of the telegram, was a revolutionary invention that struck a new frontier in the subject of telecommunications. Through a series of electrical pulses, messages could be sent to far distances through a series of dots and dashes, and at a speed that was unheard of before its invention. Since then, telegrams and Morse code have been essential in the realm of communications, especially in its role in the military, where fighter pilots were required to memorize Morse code until the 1990s.

Your job is to create a translator that will take in messages encode it in morse, and output the result in alphabet form.

Input

You will receive a message, encoded in morse, whose dashes are represented by -, and dots represented by . Assume all letters will be uppercase. Each word will be separated via /, and each character will be separated by a space.

Output

Print out the complete translated statement.

Example
Input
- .. - .- -. .. -.-. / - --- / .- -. -.-- / ... .... .. .--. / -.-. --.- -.. / -.-. --.- -.. / ... --- ... / .-. . --.- ..- .. .-. . / .. -- -- . -.. .. .- - . / .- ... ... .. ... - .- -. -.-. . / -.-. --- -- . / .- - / --- -. -.-. . / .-- . / ... - .-. ..- -.-. -.- / .- -. / .. -.-. . -... ..- .-. --.
Output
TITANIC TO ANY SHIP CQD CQD SOS REQUIRE IMMEDIATE ASSISTANCE COME AT ONCE WE STRUCK AN ICEBURG

170. Cooldown
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

Every morning after you get out of bed, you brew yourself a nice cup of coffee to get yourself ready for the day. However, most of the time when you pick up the coffee to drink, it's too hot for you to drink! You know that Newton's Formula of Cooling is $$$T(t) = T_{s} + (T_{0} - T_{s})e^{-kt}$$$, where:

$$$T(t)$$$ is the temperature of the coffee at time $$$t$$$,

$$$T_{s}$$$ is the ambient temperature of the room,

$$$T_{0}$$$ is the initial temperature of the coffee, and

$$$k$$$ is the decay constant.

You also know that the coffee reaches your favorable heat from a initial temperature of 210 degrees to 120 degrees after 15 minutes of cooling, in a room temperature of 70 degrees.

Input

The first line of input will be an integer $$$n$$$, which denotes the amount of test cases to follow in the subsequent lines. The test cases will contain a positive integer $$$T(t)$$$, the temperature at time $$$t$$$.

Output

For each test case, output the time $$$t$$$ minutes it takes for the freshly brewed coffee to cool town to temperature $$$T(t)$$$.

Example
Input
3
150
120
90
Output
8.152756910910513
15.000000000000002
28.348972201535375

171. Nearest Palindromes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A number is called a palindrome if it reads the same forwards and backwards. For example, 5775, 98389, 7, and 66 are palindromes, but 552, 35, and 86867 are not palindromes.

Given a number $$$n$$$, figure out the closest $$$k$$$ palindromes to $$$n$$$. If two palindromes have the same distance away from $$$n$$$, print the smaller one first.

For example, let's say $$$n$$$ = 600 and $$$k$$$ = 4.

The closest palindrome to $$$n$$$ is 595, with a distance of 5. The next closest palindrome is 606, with a distance of 6. The next two are 585 (distance of 15) and 616 (distance of 16), so we would print 595, 606, 585, and 616, in that order.

Input

The only line of input consists of two space-separated integers $$$n$$$ and $$$k$$$: the number to check palindromes near, and the number of palindromes to print out, respectively.

Output

Output $$$k$$$ lines, each consisting of a palindrome, sorted by their distance from $$$n$$$ (calculated as abs($$$n$$$ - $$$p$$$) for a palindrome $$$p$$$).

The palindromes must be positive integers.

Examples
Input
600 4
Output
595
606
585
616
Input
753 8
Output
757
747
767
737
777
727
787
717
Input
6 10
Output
6
5
7
4
8
3
9
2
1
11

172. Snowball Fight
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're tired of the warm July weather, so you and your friends decide to take a trip to Antarctica, and have a snowball fight.

Each person is given a very large number of snowballs (essentially, an infinite number). Each person is also wearing a coat with a certain color, and boots with a certain color.

Throughout the snowball fight, each person throws their snowballs at everyone else who doesn't either have the same color of coat, or the same color of boots, exactly once. Obviously, people don't throw snowballs at themselves.

Given this information, figure out how many snowballs are thrown in total during the snowball fight.

Input

The first line of input consists of a single positive integer $$$n$$$: the number of people involved in the snowball fight.

The next line of input consists of $$$n$$$ space-separated strings: the coat color of each person involved in the snowball fight, in order.

The next line of input consists of $$$n$$$ space-separated strings: the boot color of each person involved in the snowball fight, in order.

Output

Output a single positive integer $$$n$$$: the total number of snowballs that are thrown during the snowball fight.

Examples
Input
5
red red green green blue
red blue yellow green green
Output
14
Input
5
red red green yellow purple
brown blue maroon pink orange
Output
18

173. Codeforces Top 10
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 45 points.

There have been a lot of online Codeforces contests recently.

On Codeforces, each user is given a rating, which is a positive integer less than 4000. After each worldwide contest (which 10000+ users compete in on average), everyone's rating value increases or decreases, depending on their performance in the competition. The higher your rating, the higher rank you will need to get a positive rating change. For example, if a user had a rating of 3700, their rating could decrease if they got 2nd place in a contest (out of 10000+ people). On the other hand, if a user was rated 900, their rating would increase even if they came in 5000th or 6000th place (out of 10000). As a result of this formula, the list of the top 10 users on Codeforces (based on rating) is constantly changing, although one person is usually at #1.

You're given a list of $$$n$$$ codeforces users, and their rating before any of the recent contests. You're then given a list of $$$k$$$ contests. Each contests contains the rating change for each contestant. Given this information, your task is to print out the list of the top 10 highest rated users after each contest.

Input

The first line of input consists of two space-separated integers $$$n$$$ and $$$k$$$: the number of Codeforces users, and the number of contests, respectively.

The second line of input consists of $$$n$$$ space-separated strings: each Codeforces user's username

The third line of input consists of $$$n$$$ space-separated positive integers: each Codeforces user's rating, before any of the recent contests

The next $$$k$$$ lines each contain info about a single contest. Each line will contain $$$n$$$ space-separated integers: the rating change for each user. Each user's index in the contest rating change list will be the same as their index in the original list of users. For example, if someone appeared first in the original list of users, their rating change would be first in each list of contest rating changes.

Each rating change will be given as +[amount], if the rating change was positive, -[amount], if the rating change was negative, and 0 otherwise. For example, +345, -172, and 0 are all valid rating changes.

Output

Output $$$k$$$ lines. On each line, output the names of the top 10 highest rated users after each contest. If two users have the same rating, sort them alphabetically by their username from lowest to highest.

Examples
Input
12 6
MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE apiadu Radewoosh
3681 3669 3358 3119 3232 3317 3016 3229 3230 3374 3397 3104
0 +4 +135 +97 +18 0 +141 0 0 -151 0 -168
0 +60 0 +57 -7 0 +30 0 -17 0 0 +171
0 -192 -59 -13 +110 0 0 0 +7 0 0 -2
0 -132 +110 0 +78 0 0 0 +40 0 0 -115
0 +111 +23 +49 -10 0 0 0 +23 0 0 +65
0 +47 -40 +149 -12 0 +85 0 -57 0 -214 +102
Output
MiFaFaOvO tourist Um_nik apiadu 300iq maroonrk Benq LHiC TLE ecnerwala
tourist MiFaFaOvO Um_nik apiadu 300iq ecnerwala maroonrk LHiC TLE Benq
MiFaFaOvO tourist Um_nik apiadu maroonrk 300iq ecnerwala LHiC TLE Benq
MiFaFaOvO Um_nik maroonrk tourist apiadu 300iq Benq ecnerwala LHiC TLE
MiFaFaOvO Um_nik tourist maroonrk apiadu 300iq ecnerwala Benq LHiC TLE
MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE
Input
12 6
MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE apiadu Radewoosh
3681 3669 3358 3119 3232 3317 3016 3229 3230 3374 3397 3104
0 +12 +135 +97 +18 0 +141 0 0 -151 0 -168
0 +60 0 +57 -7 0 +30 0 -17 0 0 +171
0 -192 -59 -13 +110 0 0 0 +7 0 0 -2
0 -132 +110 0 +78 0 0 0 +40 0 0 -115
0 +111 +23 +49 -10 0 0 0 +23 0 0 +65
0 +47 -40 +149 -12 0 +85 0 -57 0 -214 +102
Output
MiFaFaOvO tourist Um_nik apiadu 300iq maroonrk Benq LHiC TLE ecnerwala
tourist MiFaFaOvO Um_nik apiadu 300iq ecnerwala maroonrk LHiC TLE Benq
MiFaFaOvO tourist Um_nik apiadu maroonrk 300iq ecnerwala LHiC TLE Benq
MiFaFaOvO Um_nik maroonrk tourist apiadu 300iq Benq ecnerwala LHiC TLE
MiFaFaOvO Um_nik tourist maroonrk apiadu 300iq ecnerwala Benq LHiC TLE
MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE

174. Interstellar Travel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 50 points.

You're traveling through space, but unfortunately, your spaceship has a limited amount of fuel. There are $$$n$$$ planets that you want to travel to on your journey through space, and each planet can be represented by an $$$x$$$, $$$y$$$, and $$$z$$$ coordinate.

You start on Earth, which can be represented as the origin (0, 0, 0) on the 3D coordinate plane. You want to find the minimum distance you can travel, if you start on Earth, visit all of the planets at least once, and end on Earth.

Recall that to calculate the distance between two points in 3D space, you can use the distance formula:

$$$D$$$ = $$$\sqrt{(X2-X1)^2 + (Y2-Y1)^2 +(Z2-Z1)^2}$$$
Input

The first line of input consists of a single positive integer $$$n$$$: the number of planets. $$$n$$$ will be less than or equal to 8.

The next $$$n$$$ lines each contain three space-separated integers: the $$$x$$$, $$$y$$$, and $$$z$$$ coordinates of each planet.

Remember that the coordinates of the Earth are (0, 0, 0).

Output

Output a single positive integer: the minimum total distance that you travel, if you start and end on Earth, and visit all of the planets.

Don't round your answer.

Examples
Input
4
-1 0 0
-2 0 0
2 0 0
1 0 0
Output
8.0
Input
8
3 3 2
-3 -3 8
6 8 7
-5 6 3
-2 7 6
-4 4 -3
1 5 -3
5 4 0
Output
59.308719980502595
Input
4
3 3 -2
-2 5 4
4 8 -6
8 17 -3
Output
45.292233300341344

175. Counting Calories (Harder Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Over the quarantine season, you decide to watch your weight by limiting yourself to a certain amount of calories a day.

In this problem, you're given the number of calories of each food item in your house as input.

You want to figure out the minimum number of food items that you need to eat in order to have eaten exactly $$$n$$$ calories.

Input

The first line of input contains a single positive integer $$$n$$$: the target number of calories.

The second line of input contains a single positive integer $$$k$$$: the number of food items.

The next $$$k$$$ lines each contain a single positive integer $$$c$$$: the number of calories of each food item.

Output

Output a single positive integer $$$m$$$: the minimum number of food items that you need to eat, in order to have eaten exactly $$$n$$$ calories.

Examples
Input
2310
3
500
100
10
Output
8
Input
600
3
500
300
1
Output
2
Input
10000
3
3
7
11
Output
912
Note

This problem is not as easy as you think it is. The solution to the easier version of the problem does not correctly solve the second example case.

176. Catapult
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 85 points.

You're testing out a catapult that you built for POE class, and you're trying to get it to launch an eraser over a wall.

The catapult launches the eraser $$$a$$$ meters away from the wall, and you're trying to get the catapult to hit a target $$$b$$$ feet above the ground, and $$$c$$$ meters away from the wall in the exact opposite direction.

The wall is $$$d$$$ meters high, and it is very thin (assume it has no thickness).

Given this information, figure out the minimum possible maximum height of the eraser, such that the eraser still clears the wall. In other words, among all eraser trajectories that hit the target and successfully clear the wall, find the lowest possible maximum height of the eraser.

Assume that you launch the device in a vacuum (i.e. there is no air resistance).

Input

The only line of input contains 4 space-separated positive integers: $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$, as described above. $$$b$$$ is guaranteed to be less than $$$d$$$.

Output

Output a single positive integer $$$h$$$: the maximum height of the eraser, if you launch it so that it hits the target and clears the wall, and has the minimum possible maximum height.

Examples
Input
5 0 5 7
Output
7.0000000000000195
Input
5 0 9 7
Output
7.62222191701435
Input
5 6 1 12
Output
15.778572363190715
Note

You don't need to use any physics equations to solve this problem. You can solve it using only algebra.

Also, your answers don't have to be exactly equal to ours. As long as they're within a few decimal places, your solution will be judged as correct.

177. Ken Ken Solver
time limit per test
15 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 130 points. (It's really hard)

Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.

Like Sudoku, Ken Ken involves placing numbers into an n by n grid, and it requires each row and column to contain distinct integers from 1 to n. n can range from 4 to 7, inclusive.

Additionally, each of the n * n cells in the Ken Ken puzzle is assigned to a "cage" consisting of one or more cells. If a cage consists of multiple cells, they have to form a single block of cells connected vertically or horizontally, but not diagonally. For example, an L-shaped cage, or a 2 by 2 square cage would be valid, but a cage consisting only of two cells at the opposite end of the board would not be valid. Usually, cages don't have more than 4-5 cells (although there is no upper limit).

For each cage in the puzzle, if it consists of only one cell, the cage will simply be assigned a number, indicating which number is placed in the cage in the final solution. This is called a "freebie".

Otherwise, each cage with two or more cells is assigned a math operation. All of the cells in the cages must complete the math operation successfully. For example, if a cage had the operation "9+", the total sum of the numbers in the cells of the cage would have to sum to 9. If a cage had the operation "120x", the total product of the numbers in the cage would have to be 120.

Cages can also have subtraction or division operations. These types of cages have to have exactly two cells. For subtraction, the difference of the two numbers in the cage must equal the given number. For example, if a cage had the operation "2-", then the numbers could be 3 and 1, in any order. They could also be 4 and 2, 2 and 4, 5 and 3 (if the board was at least 5 by 5), and so on. Cages with division work similarly. The number in the cage must equal the quotient of the higher number divided by the lower number. For example, for a "2/" cage, the numbers could be 1 and 2, or 2 and 1, or 4 and 2, and so on. As such, the required number of a cage will always be a positive integer.

Note that although all rows and columns must consist of distinct numbers, cages do not have to.

Here's an example of what an unsolved Ken Ken puzzle looks like:

And here's the solution to the same Ken Ken puzzle:

Your task, as you might have guessed, is to write a program to solve a Ken Ken puzzle. All of the Ken Ken puzzles will range from 4 by 4 to 7 by 7 in size, and they will all be taken from a book of Ken Ken puzzles, meaning that they will all be potentially solvable by a human.

Good luck!

Input

The first line of input consists of a single positive integer $$$n$$$: representing the size of the Ken Ken puzzle (the puzzle will be an $$$n$$$ by $$$n$$$ puzzle). $$$n$$$ will be less than or equal to 7 for this problem.

The next lines will contain a grid representation of the Ken Ken puzzle. Each cage will be marked off with pipes ("|") and hyphens ("-"). See the example cases for the exact formatting of the input.

The cell in each cage closest to the top of the puzzle will contain the math operation. If two cells in a cage are the same distance from the top of the puzzle, the leftmost one will contain the math operation.

Output

Output $$$n$$$ lines, each consisting of $$$n$$$ integers: the solution to the Ken Ken puzzle.

Examples
Input
5
|---|---|---|---|---|
|40x        |2-     |
|           |       |
|---|---|---|---|---|
|8+ |24x        |8+ |
|   |           |   |
|   |---|---|---|   |
|       |8+ |       |
|       |   |       |
|---|---|   |---|---|
|5+     |   |15x    |
|       |   |       |
|---|---|   |---|---|
|2-     |   |2/     |
|       |   |       |
|---|---|---|---|---|
Output
25431
12345
34512
41253
53124
Input
5
|---|---|---|---|---|
|2- |12+|2  |10x|2/ |
|   |   |   |   |   |
|   |   |---|   |   |
|   |   |12x|   |   |
|   |   |   |   |   |
|---|   |   |   |---|
|3- |   |   |   |20x|
|   |   |   |   |   |
|   |---|   |---|   |
|   |20+|   |   |   |
|   |   |   |   |   |
|---|   |---|   |---|
|                   |
|                   |
|-------------------|
Output
34251
53412
15324
42135
21543

178. Multiple of Two
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

Welcome to the CodeRams team competition!

If you're not sure on the competition format or how to submit solutions, read this first.

Since your team may not have time to get through all of the problems, we recommend that you read all problems (since harder problems give more points).

Good luck! Here's the first problem:

Given a positive number, figure out whether or not it is a multiple of two. For example, 6 is a multiple of two, while 11 is not a multiple of two.

Input

The only line of input contains a positive integer.

Output

Print YES if the integer is a multiple of 2, and NO otherwise.

Examples
Input
3
Output
NO
Input
10
Output
YES

179. Engineering Challenge
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

For an engineering challenge, you have to make a project which has a certain height $$$n$$$, with a tolerance of $$$k$$$. This means that any height between $$$n$$$ - $$$k$$$ and $$$n$$$ + $$$k$$$ will be acceptable. For example, if $$$n$$$ was equal to 5, and $$$k$$$ was equal to 2, any height between 3 and 7, inclusive, would be acceptable.

Given these values $$$n$$$ and $$$k$$$, figure out the lower and upper height limit for the engineering project.

Input

The input consists of two lines: positive integers $$$n$$$ and $$$k$$$, each on separate lines.

Output

Output two lines. On the first line, output the lower height limit, as described above. On the second line, output the upper height limit, as described above.

Examples
Input
5
2
Output
3
7
Input
7
3
Output
4
10
Input
8
4
Output
4
12

180. Boring Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

You consider a string of text to be boring if it contains only "a" characters and "b" characters. For example, "abbaba" is boring, while "abcccbabc" is not boring.

Given a string, figure out whether or not it is a boring string.

Input

The only line of input contains a single string $$$s$$$, not containing spaces.

Output

If $$$s$$$ is boring, as described above, output "YES" (no quotes). Otherwise, output "NO".

Examples
Input
aaaaaa
Output
YES
Input
ccabbabbdd
Output
NO
Input
baaaaabad
Output
NO
Input
baaaaabba
Output
YES

181. Sorted Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 5 points.

You like sequences of numbers that are in sorted order. You have three integers, and you want to figure out whether or not they're sorted, i.e. the first number is less than (not equal to) the second number, and the second number is less than (not equal to) the third number.

Input

The only line of input consists of three space-separated integers.

Output

If the three integers given are sorted, output "SORTED" (no quotes). Otherwise, output "UNSORTED".

Examples
Input
3 5 8
Output
SORTED
Input
6 6 7
Output
UNSORTED
Input
5 2 1
Output
UNSORTED

182. Lucky Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You consider a number to be "lucky" if it has any digits equal to 7. For example, 7377, 87, and 98789 are lucky, while 6, 300, and 561 are not lucky. Given a number, figure out whether or not it is a lucky number.

Input

The only line of input consists of a single integer $$$n$$$.

Output

If $$$n$$$ is a lucky number, output "YES" (no quotes). Otherwise, output "NO" (no quotes).

Examples
Input
7377
Output
YES
Input
1101
Output
NO
Input
3060
Output
NO

183. Number Destruction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

After destroying half of all life in the universe, Thanos decides to destroy one-third of all positive integers in the universe. Thanos starts by destroying 0, and then proceeds to destroy any positive integers that are a multiple of 3.

Your task is to find the first $$$n$$$ integers that are left (have not been destroyed) after Thanos applies this operation. For example, the first 5 integers that are left are 1, 2, 4, 5, and 7.

Input

The only line of input consists of a single positive integer $$$n$$$: the number of integers to print.

Output

Output $$$n$$$ lines: the first $$$n$$$ integers that were not destroyed by Thanos.

Examples
Input
5
Output
1
2
4
5
7
Input
11
Output
1
2
4
5
7
8
10
11
13
14
16
Input
3
Output
1
2
4

184. Close Product
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 10 points.

You have $$$n$$$ positive integers, and you want to find their product. However, you have to omit exactly one of the integers from the list before calculating the product. You want to find the maximum product of the list, after omitting exactly one integer from the list.

For example, given the numbers $$$2$$$, $$$4$$$, and $$$5$$$, the maximum product is $$$5$$$ * $$$4$$$ = $$$20$$$. $$$2$$$ * $$$4$$$ * $$$5$$$ is not valid, because none of the numbers were omitted.

Input

The first line of input contains a single positive integer $$$n$$$: the number of integers in the list.

The next $$$n$$$ lines each contain a single positive integer: each element of the list.

Output

Output a single positive integer $$$p$$$: the maximum possible product of all integers in the list, if you omit exactly one. The answer is guaranteed to fit inside of a 32-bit integer type.

Examples
Input
5
3
5
6
8
10
Output
2400
Input
4
4
3
2
1
Output
24
Input
5
3
3
3
3
3
Output
81

185. Pleasing Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 15 points.

You consider a number to be a pleasing number if it contains no prime factors other than 2 and 3. For example, 1, 4, 12, 18, and 81 are pleasing numbers, while 7, 28, 210, and 30 are not pleasing numbers.

Given a number, figure out whether or not it is a pleasing number.

Input

The only line of input consists of a single positive integer $$$n$$$ less than or equal to 1000.

Output

If $$$n$$$ is a pleasing number, as described above, output "YES" (no quotes). Otherwise, output "NO" (no quotes).

Examples
Input
18
Output
YES
Input
35
Output
NO

186. Radio Filtration
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 15 points.

You're listening to the radio, and you have a "voice to text" machine that transcribes the radio's words. The machine transcribes some of the static of the radio, however, which it writes as certain random characters. The machine writes an underscore character before and after any static that it transcribes. Your task is to filter out the static and print the original message.

For example, if the machine transcribed "hello wor_xxxxxxxhsfdjsdkkdsfds_ld coderams", the filtered out text would be "hello world coderams".

Input

The only line of input contains a line of text, following the rules above.

Output

Output a single line: the text, after filtering out the static, as described above.

Examples
Input
hellowor_*%^&&^%&^&%*_ldcoder_%^%^_ams
Output
helloworldcoderams
Input
hello_***_hello
Output
hellohello
Input
_^*&^^&**&^*^&*&^*^&_code ram_^_s^^^
Output
code rams^^^

187. Mountain Biking
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 20 points.

You just went on a very hilly bike ride, and you want to find largest hill that you biked up during your ride.

You know the elevations of several points along your ride, and you want to find the vertical rise of the largest continously uphill section of the ride. A continuously uphill section must have a positive overall vertical rise, and must consist of only uphill segments. If a section of the ride has any downhill or flat subsections, it is not considered a continuously uphill section.

Input

The first line of input contains a single positive integer $$$n$$$: the number of points along the ride that you know the elevations for.

The next line contains $$$n$$$ space-separated integers: the elevation, along each point of the ride.

Output

Output a single positive integer $$$v$$$: the value of the biggest hill on the ride, defined as the vertical rise of the largest continiously uphill section, as defined above. There is guaranteed to be at least one continously uphill section in the route given in the input.

Examples
Input
7
600 650 700 690 740 520 600
Output
100
Input
5
400 500 600 700 400
Output
300
Input
8
100 200 300 300 400 500 600 700
Output
400

188. Quaternary Addition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 25 points.

You have two numbers, and you decide to apply a special addition technique on them: you convert both numbers to quaternary (base 4), and add each digit pair separately. If this results in a number greater than or equal to 4, you subtract four from the result.

For example, if you had the numbers 322312 and 213200 in base 4, the result would be 131112.

Given two numbers in base ten, apply this technique on them, and convert the result back into base 10.

Input

The first line of input contains a single positive integer $$$a$$$.

The second line of input contains a single positive integer $$$b$$$.

Output

Print the result of applying the operation described above on $$$a$$$ and $$$b$$$, converted back into decimal (Base 10).

Examples
Input
7
9
Output
12
Input
67
130
Output
193
Input
45
1003
Output
964

189. Journey to the Exoplanets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 25 points.

You're on an intergalactic space mission in the year 2100, and you come across a star with several planets orbiting it. You know the coordinates of each planet in 3D space, and given this information, you need to find the ordering of the planets from closest to farthest away from the star. Then, you can figure out which planets are most likely to have alien life forms.

You're given the coordinates of the star of the planetary system, and the coordinates for $$$n$$$ planets orbiting the star, and their names.

Recall that you can use the 3D distance formula to calculate the distance between two planets in 3D space:

$$$D$$$ = $$$\sqrt{(X2-X1)^2 + (Y2-Y1)^2 +(Z2-Z1)^2}$$$
Input

The first line of input consists of three space-separated integers: the X, Y, and Z coordinates of the star, respectively.

The next line of input contains a single positive integer $$$n$$$: the number of planets orbiting the star.

The next $$$n$$$ lines each contain three space-separated integers, representing the X, Y, and Z coordinates of each planet, respectively, followed by a space and a single string, representing the name of the planet.

No two planets in the input file will have the same distance away from the star.

Output

Output $$$n$$$ lines: the names of each planet in the exoplanetary system, ordered based on their distance from the star. The planet closest to the star should come first in the list, and the planet the furthest away from the star should come last in the list.

Example
Input
20 20 20
8
16 19 20 Venus
10 20 20 Mars
14 22 20 Earth
18 20 20 Mercury
-5 17 20 Uranus
2 21 21 Saturn
6 20 23 Jupiter
-11 20 21 Neptune
Output
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune

190. Contact Tracing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 30 points.

During the coronavirus pandemic, your town is attempting to trace the origins of recent COVID-19 cases.

You're given a list of people who had the disease, and who they got it from, and you're trying to find the names of "superspreaders". For this problem, we'll define a superspreader as someone who gave at least three other people COVID-19.

Given this information, your task is to figure out the names of all of the superspreaders in the town.

Input

The first line of input contains a single positive integer $$$n$$$: the number of people in the town.

The next $$$n$$$ lines contain two space-separated strings: the name of each person, and the name of the person they got the coronavirus from. Exactly one person in the town will have "OTHER" (no quotes) as the person they got the disease from, indicating that this person got the disease from a different town.

Output

Output $$$k$$$ lines, where $$$k$$$ is the number of superspreaders in the town. On each line, print the name of each superspreader in the order they were given in the input.

If there aren't any superspreaders in the town, output "NONE" (no quotes).

Examples
Input
10
Alice OTHER
Bob Alice
Cheryl Alice
Darryl Bob
Ernie Alice
Frank Darryl
Greta Darryl
Hank Cheryl
Irene Bob
John Darryl
Output
Alice
Darryl
Input
4
Keith OTHER
Larry Keith
Marshall Larry
Nancy Marshall
Output
NONE
Input
6
Alice Frank
Bob Ernie
Cheryl Darryl
Darryl Ernie
Ernie OTHER
Frank Ernie
Output
Ernie

191. Morbit Cipher Encryption
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 35 points.

You're trying to encrypt text using the Morbit Cipher, a cipher involving morse code.

Encrypting text using the Morbit Cipher involves several steps:

1. Convert the text to Morse Code. This involves converting all letters to their Morse Code equivalents, and placing a lowercase x letter in between two letters, and two lowercase x letters in between two words. See below for a list of morse code mappings which you can copy into your program.

2. Divide the Morse Code into blocks of two characters each. If there are an odd number of characters, add an "x" to the end of the Morse Code. There are now 9 total combinations of two-character blocks, since each position can have three possible characters (dot, dash, and "x").

3. Write each of the 9 combinations of two-character blocks in an arbitrary order, assigning each one to an integer from 1 to 9. This is the "key" of the cipher.

4. Replace each two-character block in the Morse Code text of the cipher with the number it corresponds to in the key.

5. You should now have a long sequence of numbers from 1-9. Now, your text is encrypted using the Morbit Cipher.

Here is a comma-separated list of the Morse Code equivalents of each letter from A to Z, in order. You can copy this into your program:

".-", "-...", "-.-.", "-..", ".", "..-.", "–.", "....", "..", ".—", "-.-", ".-..", "–", "-.", —", ".–.", "–.-", ".-.", "...", "-", "..-", "...-", ".–", "-..-", "-.–", "–.."

Input

The first line of input contains a line of text, consisting of only lowercase characters and spaces: the plaintext to encrypt using the Morbit Cipher.

The next 9 lines each contain a two-character block: the first one corresponds to the block that maps to "1", the second one corresponds to the block that maps to "2", and so on.

Output

Output a single string of numbers from 1 to 9: the plaintext, after applying the Morbit Cipher on it using the given key.

Examples
Input
we hope youre having fun in the competition so far
xx
.-
-.
x.
.x
..
--
-x
x-
Output
285465782341379742434166486245393163429545318664133979823494586979546971634825
Input
good luck in the rest of it
xx
.-
x-
.x
-.
-x
..
--
x.
Output
8486865495476553217343974495997318675173

192. Knight's Move
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 40 points.

You have an 8 by 8 chessboard with several knights on it. The chessboard has no other pieces on it. Given the positions of the knights, find all of the spaces that the knights can travel to in a single move.

Recall that in chess, a knight can move exactly 2 spaces in one direction, and exactly one space in a perpendicular direction. For example, a knight could move 2 spaces left and 1 space up, or 2 spaces up and 1 space left, but a knight could not move 2 spaces left on its own, or 1 space up and 1 space right, for example.

Input

The input consists of 8 lines, each consisting of 8 characters, representing the chessboard.

A single dot (".") represents an empty space on the chessboard, and an uppercase K ("K") represents the position of a knight.

Output

Output 8 lines, in the same format as the input, except, replace each empty space that can be moved to by at least one knight in a single move with an asterisk ("*").

Examples
Input
........
........
........
...K....
........
.....K..
........
........
Output
........
..*.*...
.*...*..
...K*.*.
.*.*.*.*
..*.*K..
...*...*
....*.*.
Input
........
..K....K
........
...K....
........
.....K..
........
......KK
Output
*...**..
..K.*..K
**..**..
.*.K*.*.
.*.*.*.*
..*.*K**
...***.*
....*.KK
Input
........
........
........
........
........
........
........
.......K
Output
........
........
........
........
........
......*.
.....*..
.......K

193. Quadratic Equation Factoring
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 40 points.

You're given a quadratic equation, in the form of $$$y = ax^2 + bx + c$$$. Your task is to find all possible factorizations of this quadratic equation, using only positive integers. In other words, you have to find all pairs of binomials $$$cx + d$$$, where $$$c$$$ and $$$c$$$ are both positive integers, such that the product of the two binomials is the original quadratic equation.

Sort the factorizations in ASCII order (you can use your language's built-in sorting method).

Input

The only line of input contains three space-separated positive integers $$$a$$$, $$$b$$$, and $$$c$$$: the coefficient on the $$$x$$$ term of the quadratic equation, and the constant term of the quadratic equation, respectively.

Output

Output all of the integer factorizations of the given quadratic equation, each on a new line. Each one should be in the format $$$(x + c1)(x + c2)$$$.

If there are no possible factorizations, output "-1" (no quotes).

Examples
Input
2 8 6
Output
(2x + 2)(x + 3)
(2x + 6)(x + 1)
(x + 1)(2x + 6)
(x + 3)(2x + 2)
Input
1 17 60
Output
(x + 12)(x + 5)
(x + 5)(x + 12)
Input
3 7 11
Output
-1

194. RSA Cipher
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 45 points.

The RSA cipher, invented in 1977, is widely used today for encryption of data online. The first step of making a key for the RSA cipher is choosing a number $$$n$$$ at the start. In the real world, $$$n$$$ is extremely large, usually at least 50 digits long, but for this problem, you'll select an $$$n$$$ less than $$$10^6$$$.

When choosing the numbers for the key, $$$n$$$ must be a semiprime. A semiprime is any number that has exactly two prime factors, not necessarily distinct. For example, 6, 34, and 25 are semiprimes, but 30, 7, and 27 are not semiprimes.

After choosing $$$n$$$, you choose another number $$$e$$$, which can be any number less than $$$n$$$ and greater than one that is relatively prime to $$$n$$$. Two numbers are relatively prime if they don't share any prime factors.

$$$n$$$ and $$$e$$$ compose the "public key", and the private key is calculated differently, which won't be covered in this problem.

Given a number $$$m$$$, find the public key that has the largest $$$n$$$, where $$$n$$$ and $$$e$$$ are less than or equal to $$$m$$$. If multiple answers have the same $$$n$$$, pick the one with the smallest $$$e$$$.

Input

The only line of input contains a single positive integer $$$m$$$: the upper limit on $$$n$$$ and $$$e$$$.

Output

Output two space-separated integers, representing your chosen public key: $$$n$$$ and $$$e$$$, as described above. $$$n$$$ and $$$e$$$ should both be less than or equal $$$m$$$, $$$n$$$ should be a semiprime, and $$$e$$$ should be relatively prime to $$$n$$$.

Examples
Input
197
Output
194 3
Input
259
Output
259 2
Input
372
Output
371 2
Input
98276
Output
98267 2

195. Dungeon
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 50 points.

Unfortunately, you find yourself trapped in a dungeon, which can be represented as a 2D grid. The dungeon contains some impassable walls, represented by X characters, and empty space, represented as single dots (".").

You start in the top left corner. You want to figure out how many cells are accessible from your starting space. You can move up, down, right, and left any number of times, but you cannot move diagonally, and you cannot move through walls. You also can't go off the board.

Input

The first line of input consists of a single positive integer $$$n$$$: the number of rows and columns of the dungeon (the dungeon is always square).

The next $$$n$$$ lines each contain $$$n$$$ characters: the grid representation of the dungeon. If a character is an "X", it represents an impassable wall, and if a character is a single dot, it represents empty space.

Output

Output a single positive integer $$$k$$$: the number of spaces in the dungeon accessible from your starting space, according to the rules above.

Examples
Input
5
...X.
..X..
....X
..XXX
.X...
Output
15
Input
5
..X..
.XX..
X....
.....
.....
Output
3

196. Cubical Classroom
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 55 points.

After the COVID-19 pandemic, a school decides to implement serious measures to ensure that students "socially distance" from each other. The school has divided each classroom into several squares, using glass walls, and each student is assigned to a single "sub-room" in the classroom.

Unfortunately, this strategy didn't accomodate enough students. To fix this, the school decided to stack several sub-rooms on top of each other, such that the sub-rooms form a cube. In other words, each classroom has $$$n^3$$$ sub-rooms, where $$$n$$$ is given as input.

Since everything was messed up by the COVID-19 quarantine, the school's classes all contain students of a wide range of ages. A student is called a leader if they're older than all of the students in adjacent sub-rooms, including diagonally (for example, a sub-room in the center of a classroom with $$$n=3$$$ would have 26 adjacent sub-rooms).

The teacher of the class wants to figure out which students are most likely to cause trouble. The teacher deduces that a student is likely to cause trouble if the following are true:

1. The student is not a leader (at least one student in an adjacent sub-room is older than them or the same age as them)

2. The student doesn't have any leaders in adjacent sub-rooms (including diagonally)

Given this information, help the teacher find out how many students in the classroom are likely to be troublemakers.

Input

The first line of input contains a single positive integer $$$n$$$: the number of sub-rooms in a single 1D cross-section of the classroom. There are $$$n^3$$$ sub-rooms and students in total.

The next $$$n$$$ lines each contain a 2D grid of space-separated integers: the ages of the students in each top-down cross-section of the classroom. Each cross-section will be separated by a new line.

Output

Output a single integer $$$k$$$: the number of potential troublemakers in the 3D classroom.

Examples
Input
3

13 11 15
10 12 18
3 16 12

11 12 17
9 12 13
18 15 15

14 15 16
13 9 8
12 10 7
Output
5
Input
2

4 4
4 4

5 5
5 5
Output
8

197. Three Lines
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 60 points.

You're given three lines on the coordinate plane. No pairs of the lines are parallel.

Figure out the area of the triangle formed by the intersection points of the three lines. In other words, label the points of interesection of lines 1 and 2, lines 1 and 3, and lines 2 and 3, $$$A$$$, $$$B$$$, and $$$C$$$, respectively. Then, your task is to find the area of triangle $$$ABC$$$.

Input

The input consists of three lines, each containing the equation for one of the lines, in $$$y = mx + b$$$ form, where $$$m$$$ represents the slope of the line, and $$$b$$$ represents the y-intercept of the line.

Output

Output a single decimal number representing the area of the triangle formed by the intersection points of the three lines. Do not round your answer. Your answer doesn't have to be exactly equal to ours; as long as it's within a few decimal places it will be judged as correct.

Examples
Input
y = 2x + 3
y = -2x + 9
y = x - 2
Output
28.166666666666664
Input
y = 2x + 3
y = -2x + 9
y = -x - 27
Output
793.5000000000001
Input
y = 2x + 3
y = -2x + 90
y = 7x - 2
Output
478.4027777777778
Note

Here is the graph of the first example case:

198. Bracket Challenge
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 60 points.

It is March, and the NCAA basketball tournament is happening soon. You're trying to figure out which teams have the best chances at winning the tournament.

Leading "bracketologists" have calculated, for each team, their probability of winning against each of the other teams. In other words, you know, for every pair of teams, the probability of each of the two teams winning in a game between the two teams, which can be represented by a table (more information in the input section).

There are $$$n$$$ teams in the tournament. $$$n$$$ will always be a power of two. Each team is given a unique number (their "seed"), from 1 to $$$n$$$.

In the first round of the tournament, the team with seed $$$s$$$ plays the team with the seed $$$n$$$ - $$$s$$$ + 1. For example, in the first round of an 8-team tournament, the 1 seed will play the 8 seed, the 2 seed will play the 7 seed, and the 3 seed will play the 6 seed.

After the first round, the teams that lost their match are eliminated from the tournament, and the teams that won their match move on to the next round.

In the next round, there are $$$\frac{n}{2}$$$ teams still left in the tournament. If every team with a lower numbered seed won each game, the second round proceeds similarly to the first round. For example, in the second round of an 8 player tournament where every lower numbered seed won each first round game, the 1 seed plays the 4 seed, and the 2 seed plays the 3 seed.

If a higher numbered seed won a first round game, they will play in the second round game that the team they beat would have played in. For example, if the 7 seed beat the 2 seed in the first round of an 8 player tournament, then the 7 seed would play the 3 seed in the second round, or the 6 seed, if the 6 seed beat the 3 seed in the first round.

This process repeats until the finals, when the winner of the finals wins the whole tournament.

Given the probability table described above, sort the teams by their probability to win the entire tournament.

Input

The first line contains a single positive integer $$$n$$$: the number of teams in the tournament. $$$n$$$ is guaranteed to be a power of two.

The next line contains $$$n$$$ space-separated strings: the name of each team in the tournament.

The next $$$n$$$ lines each contain $$$n$$$ space-separated integers. The $$$j$$$th integer on the $$$i$$$th line represents the probability that the $$$i$$$th seeded team will beat the $$$j$$$th seeded team. The probabilities will be given as an integer percentage out of 100. The probability that a team will beat themselves will be given as 50

Output

Output $$$n$$$ lines. Each line should contain the name of each team, a space, and the probability that the team will win the tournament, given as a percentage out of 100, rounded to the nearest integer. Sort the teams from highest to lowest, based on their probability of winning the tournament.

Note that you should round your answers after sorting the list of teams and their win probabilities.

Examples
Input
4
Syracuse Michigan Duke UNC
50 78 47 52
22 50 21 19
53 79 50 60
48 81 40 50
Output
Duke 45
Syracuse 28
UNC 23
Michigan 4
Input
8
Syracuse Duke Louisville UNC Virginia Pittsburgh Indiana Kansas
50 54 62 51 55 97 83 35
46 50 52 43 57 94 65 29
38 48 50 34 48 87 81 31
49 57 66 50 54 96 77 23
45 43 52 46 50 90 55 11
3 6 13 4 10 50 33 1
17 35 19 23 45 67 50 15
65 81 69 77 89 99 85 50
Output
Kansas 40
Louisville 18
Duke 14
Syracuse 11
UNC 11
Virginia 5
Indiana 2
Pittsburgh 0

199. Plane Tour
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 65 points.

Your team solved all of the problems at CodeQuest 2021, and as a reward, the supervisors of the competition decided to show your team a room full of new aircraft (CodeQuest is run by Lockheed Martin, which builds airplanes and helicopters at their Owego, NY site, which the CodeRams attend every year).

Once your team is dropped off in a room, the CodeQuest supervisors will let your team travel around the room and look at all of the new airplanes and helicopters. However, there are different rooms, and some of them are separated by impassable walls and locked doors.

Since your team performed so well in the CodeQuest competition, the supervisors let your team choose which room to tour. You can only go in one room during the tour.

Your task is to figure out the maximum number of aircraft that you can see, if you visit the optimal room on your team's private tour.

Input

The Lockheed Martin facility that the competition is taking place at can be represented as a 2D grid.

The first line of input contains two space-separated integers $$$n$$$ and $$$m$$$: the number of rows and columns of the grid representation of the facility, respectively.

The next $$$n$$$ lines each contain $$$m$$$ characters: the 2D top-down view representation of the Lockheed Martin facility.

If a character is a single dot ("."), then the space in the grid is empty space that can be walked through. If a character is an x ("X"), then the space in the grid is an impassable wall. If a character is a p ("P"), then the space in the grid is an airplane or helicopter. Note that you can walk through a space with an aircraft.

You cannot walk diagonally.

Output

Output a single positive integer $$$p$$$: the maximum number of aircraft that you can see on your facility tour, only visiting one room.

Examples
Input
5 5
P.X..
..XP.
XXXX.
...XP
...X.
Output
2
Input
11 10
XXXXXXXXXX
X..P.....X
X.XXX....X
X...X....X
X...XX...X
X.X.PX.P.X
X.XXXX...X
X....PXXXX
XXXXXX.P.X
XPPP.X.PPX
XXXXXXXXXX
Output
4

200. Rubber Bands
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 70 points.

You have placed $$$n$$$ pins on a bulletin board, and a rubber band. You want to place the rubber band around a certain subset of the pins, such that there aren't any pins inside of the rubber band that aren't touching the rubber band. In other words, the rubber band must touch all of the points inside of it.

Figure out the largest number of pins that you can choose, and still satisfy the condition described above.

Input

The first line of input contains a single positive integer $$$n$$$, less than or equal to 7: the number of pins.

The next $$$n$$$ lines each contain two space-separated integers $$$x$$$ and $$$y$$$: the x and y coordinates of each pin, respectively.

Output

Output a single positive integer $$$k$$$: the size of the largest subset of pins that you can wrap the rubber band around, such that the rubber band is touching all points inside of the rubber band.

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

201. Ken Ken Solver
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This problem is worth 100 points.

Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.

Like Sudoku, Ken Ken involves placing numbers into an n by n grid, and it requires each row and column to contain distinct integers from 1 to n. n will be equal to 5 for this problem.

Additionally, each of the n * n cells in the Ken Ken puzzle is assigned to a "cage" consisting of one or more cells. If a cage consists of multiple cells, they have to form a single block of cells connected vertically or horizontally, but not diagonally. For example, an L-shaped cage, or a 2 by 2 square cage would be valid, but a cage consisting only of two cells at the opposite end of the board would not be valid. Usually, cages don't have more than 4-5 cells (although there is no upper limit).

For each cage in the puzzle, if it consists of only one cell, the cage will simply be assigned a number, indicating which number is placed in the cage in the final solution. This is called a "freebie".

Otherwise, each cage with two or more cells is assigned a math operation. All of the cells in the cages must complete the math operation successfully. For example, if a cage had the operation "9+", the total sum of the numbers in the cells of the cage would have to sum to 9. If a cage had the operation "120x", the total product of the numbers in the cage would have to be 120.

Cages can also have subtraction or division operations. These types of cages have to have exactly two cells. For subtraction, the difference of the two numbers in the cage must equal the given number. For example, if a cage had the operation "2-", then the numbers could be 3 and 1, in any order. They could also be 4 and 2, 2 and 4, 5 and 3, and so on. Cages with division work similarly. The number in the cage must equal the quotient of the higher number divided by the lower number. For example, for a "2/" cage, the numbers could be 1 and 2, or 2 and 1, or 4 and 2, and so on. As such, the required number of a cage will always be a positive integer.

Note that although all rows and columns must consist of distinct numbers, cages do not have to.

Here's an example of what an unsolved Ken Ken puzzle looks like:

And here's the solution to the same Ken Ken puzzle:

Your task, as you might have guessed, is to write a program to solve a Ken Ken puzzle. All of the Ken Ken puzzles will have been taken from a book of Ken Ken puzzles, meaning that they will all be potentially solvable by a human.

Good luck!

Input

The first line of input consists of a single positive integer $$$n$$$: representing the size of the Ken Ken puzzle (the puzzle will be an $$$n$$$ by $$$n$$$ puzzle). $$$n$$$ will be equal to 5 for this problem.

The next lines will contain a grid representation of the Ken Ken puzzle. Each cage will be marked off with pipes ("|") and hyphens ("-"). See the example cases for the exact formatting of the input.

The cell in each cage closest to the top of the puzzle will contain the math operation. If two cells in a cage are the same distance from the top of the puzzle, the leftmost one will contain the math operation.

Output

Output $$$n$$$ lines, each consisting of $$$n$$$ integers: the solution to the Ken Ken puzzle.

Examples
Input
5
|---|---|---|---|---|
|2- |12+|2  |10x|2/ |
|   |   |   |   |   |
|   |   |---|   |   |
|   |   |12x|   |   |
|   |   |   |   |   |
|---|   |   |   |---|
|3- |   |   |   |20x|
|   |   |   |   |   |
|   |---|   |---|   |
|   |20+|   |   |   |
|   |   |   |   |   |
|---|   |---|   |---|
|                   |
|                   |
|-------------------|
Output
34251
53412
15324
42135
21543
Input
5
|---|---|---|---|---|
|40x        |2-     |
|           |       |
|---|---|---|---|---|
|8+ |24x        |8+ |
|   |           |   |
|   |---|---|---|   |
|       |8+ |       |
|       |   |       |
|---|---|   |---|---|
|5+     |   |15x    |
|       |   |       |
|---|---|   |---|---|
|2-     |   |2/     |
|       |   |       |
|---|---|---|---|---|
Output
25431
12345
34512
41253
53124