UTPC Contest 04-02-21 Div. 2 (Beginner)
A. Switching Up the Playlist
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Joanna has become tired of listening to the music in her playlist in the same order over and over again. She still really enjoys the contest of the playlist, but wants to try listening to it in a different order to try to switch things up. Specifically, she wants to try reversing the playlist so that the last song plays first, the second to last song plays second, and so on.

Given Joanna's playlist, can you write a program to reverse the playlist so that she can listen to music in the new ordering?

Input

The first line of the input will consist of a single integer $$$n (3 \leq n \leq 100)$$$ which gives the number of songs on Joanna's playlist. The next $$$n$$$ lines each contain a string $$$s_i (5 \leq |s_i| \leq 20)$$$ made up of only lowercase and uppercase letters giving the name of the $$$i$$$th song on Joanna's playlist.

Output

Output Joanna's playlist in reverse order, with a single song per line.

Example
Input
3
BohemianRhapsody
HookedOnAFeeling
CountryRoads
Output
CountryRoads
HookedOnAFeeling
BohemianRhapsody

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

Arturo realized that he doesn't listen to his vinyl records very often anymore so he decides to hang them up on the wall of his study. He grabs one of his vinyl records which consists of $$$n$$$ concentric circles (circles are concentric if they all share the same center) and decides to paint over the top of the vinyl record to fit the decor of his room. He starts at the outermost ring of the vinyl (a ring is defined as the space between two concentric circles that lie within the circle of a bigger radius and outside the circle with the smaller radius) and paints it red. He then paints the outermost unpainted ring blue and continues this process of alternating colors for each of the rings, each time choosing the outermost one that has not been painted yet.

Given the radii (in centimeters) of the $$$n$$$ concentric circles for a particular vinyl, help Arturo figure out the area (in $$$\text{cm}^{2}$$$) of the vinyl that gets painted red.

Input

The first line contains a single integer $$$n$$$ where $$$1 \leq n \leq 100$$$ and $$$n$$$ represents the number of concentric circles in the vinyl record.

The second line of input contains $$$n$$$ space-separated integers $$$r_1, \dots, r_n$$$ where $$$1 \leq r_i \leq 1000$$$ for all integers $$$1 \leq i \leq n$$$ representing the radii (in centimeters) of each of the concentric circles. It is guaranteed that $$$r_i \neq r_j$$$ for all $$$i \neq j$$$.

Output

Output the total area (in $$$\text{cm}^2$$$) of the vinyl record that will be painted red. Your answer will be accepted if the absolute or relative error does not exceed $$$10^{-6}$$$.

Examples
Input
2
2 1
Output
9.42477796076938
Input
4
4 1 3 2
Output
31.4159265358979
Note

In the first example the overall radius of the vinyl is $$$(2 \cdot \pi)^2$$$ and the inner circle of radius $$$1$$$ will be painted blue so the radius printed red is $$$(2 \cdot \pi)^2 - (\pi)^2 = 3 \cdot (\pi)^2 \approx 9.424$$$.

C. Melodic Harmonies I
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As many people know, there are 88 keys on the piano. When a key is pressed, the frequency of the sound produced can be measured. As it turns out, a perfectly tuned piano has as Middle C the frequency of 440 Hz. From there, an octave above is exactly double this, or 880 Hz, and an octave below is exactly 220 Hz. As it turns out, an octave is actually defined mathematically as the note that is double or half of the starting note.

For the notes in between, they happen to be exactly evenly spaced based on the log scale! In fact, given the octave starting at Middle C, the first note to follow Middle C, or D, has a frequency of exactly $$$440 \cdot 2^{\frac{1}{12}}$$$, and the second note has a frequency of exactly $$$440 \cdot 2^{\frac{2}{12}}$$$, and so on and so forth. As it turns out, this pattern holds for all octaves.

Matt has developed a robot that listens to music, and after listening to Alice and Bob's performances of the same song, it has determined the central $$$n$$$ frequencies that make up the melody of both Alice and Bob's performances. Now, given that they performed on an infinitely long piano, and that they both performed for the same time, we can define the difference between the melodies as follows. For every note $$$i$$$, we take the note's difference as $$$b_i - a_i$$$, where $$$b_i$$$ is Bob's note's position on the piano, and $$$a_i$$$ is Alice's note's position on the piano. Taking the sum over all $$$i$$$, we can define the overall difference as the absolute value of that sum.

Given Alice and Bob's melodies in terms of frequencies, determine their difference!

Input

The first line of the input will contain $$$n (1 \le n \le 10^4)$$$, the number of notes that both Alice and Bob will play.

The next $$$n$$$ lines of input will each contain two frequencies $$$f_i^a, f_i^b$$$, with the first being Alice's note, and the second being Bob's note that he plays at the same time. It is given that $$$10 \le f_i^a, f_i^b \le 10^{12}$$$. It is guaranteed each frequency will correspond to an exact note on an infinite piano within an error bound of $$$10^{-6}$$$.

Output

A single integer, the overall difference between Alice and Bob's performances.

Example
Input
7
440.000000 493.883301
440.000000 493.883301
659.255114 739.988845
659.255114 739.988845
739.988845 830.609395
739.988845 830.609395
659.255114 739.988845
Output
14
Note

The sample input is Alice playing the first 7 notes of Twinkle Twinkle Little Star in C Major, and Bob playing the same piece in D major. There is a 2 note difference between every note, and hence the overall difference is 14.

D. Melodic Harmonies II
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Note: The introduction explaining musical frequencies is the same as part 1 of this problem.

As many people know, there are 88 keys on the piano. When a key is pressed, the frequency of the sound produced can be measured. As it turns out, a perfectly tuned piano has as Middle C the frequency of 440 Hz. From there, an octave above is exactly double this, or 880 Hz, and an octave below is exactly 220 Hz. As it turns out, an octave is actually defined mathematically as the note that is double or half of the starting note.

For the notes in between, they happen to be exactly evenly spaced based on the log scale! In fact, given the octave starting at Middle C, the first note to follow Middle C, or D, has a frequency of exactly $$$440 \cdot 2^{\frac{1}{12}}$$$, and the second note has a frequency of exactly $$$440 \cdot 2^{\frac{2}{12}}$$$, and so on and so forth. As it turns out, this pattern holds for all octaves.

Matt has developed a robot that listens to music, and after listening to Alice and Bob's performances of the same song, it has determined the central $$$n$$$ frequencies that make up the melody of both Alice and Bob's performances. Now, given that they performed on an infinitely long piano, and that they both performed for the same time, we can define the difference between the melodies as follows. For every note $$$i$$$, we take the note's difference as $$$b_i - a_i$$$, where $$$b_i$$$ is Bob's note's position on the piano, and $$$a_i$$$ is Alice's note's position on the piano. Taking the sum over all $$$i$$$, we can define the overall difference as the absolute value of that sum.

Given Alice and Bob's melodies in terms of frequencies, we already know how to determine their difference. However, Eve noticed that perhaps, Alice and Bob are playing in different scales! In other words, if we move all of Alice's notes up or down an integer amount on the piano, then the difference with Bob's performance can be reduced. Given this, determine with the best possible movement for Alice, the minimum difference between the two.

Input

The first line of the input will contain $$$n (1 \le n \le 10^4)$$$, the number of notes that both Alice and Bob will play.

The next $$$n$$$ lines of input will each contain two frequencies $$$f_i^a, f_i^b$$$, with the first being Alice's note, and the second being Bob's note that he plays at the same time. It is given that $$$10 \le f_i^a, f_i^b \le 10^{12}$$$. It is guaranteed each frequency will correspond to an exact note on an infinite piano within an error bound of $$$10^{-6}$$$.

Output

A single integer, the minimum possible overall difference between Alice and Bob's performances.

Example
Input
7
440.000000 493.883301
440.000000 493.883301
659.255114 739.988845
659.255114 739.988845
739.988845 830.609395
739.988845 830.609395
659.255114 739.988845
Output
0
Note

The sample input is Alice playing the first 7 notes of Twinkle Twinkle Little Star in C Major, and Bob playing the same piece in D major. Shifting Alice up by 2, there is no difference in their melodies, and hence the minimum possible overall difference is 0.

E. Algo's Rhythm
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Algo the serial composer absolutely loves to write music and does it all the time. In fact, he has composed so many pieces over the years that now he has grown bored of having so much creative freedom and would like to give himself a challenge. Algo will now limit himself to composing with only the notes from a set of $$$N$$$ chosen note lengths, and he wants to match the overall target length of his song exactly.

For instance, if Algo wants to compose a 1-measure song using only quarter notes, half notes, and whole notes—of beat-lengths 1, 2, and 4 respectively—then there are 6 total possible songs that he could compose:

Algo has just been commissioned to write a song that is $$$M$$$ four-beat measures long. Determine how many unique songs ending at exactly $$$M$$$ measures Algo could possibly write, using only his $$$N$$$ chosen notes!

Input

The first line of input contains two integers $$$M$$$ and $$$N$$$, where $$$M$$$ ($$$1 \leq M \leq 10^5$$$) is Algo's desired song length in 4-beat measures and $$$N$$$ ($$$1 \leq N \leq 20$$$) is the number of unique note lengths that Algo will limit himself to using. Then, the second line of input contains $$$N$$$ space-separated integers, where each integer $$$n_i$$$ ($$$1 \leq n_i \leq M*4$$$) represents a chosen note length in beats.

Output

Output the total number of $$$M$$$-measure songs that Algo could possibly compose from his chosen notes! Because this amount could be very large, output the number of songs modulo $$$10^9+7$$$.

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

F. Ice-T
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ice-T has remained a powerful player in the rap game for almost forty years, ever since his debut in the early 80's. It is a little known secret that Ice-T powers his incredible rapping abilities by amassing points in a 2D plane and harvesting all of the 'T's that he can find among them.

A 'T' is defined to be a set of four points $$$A$$$, $$$B$$$, $$$C$$$, and $$$D$$$ where:

  1. Points $$$A$$$ and $$$B$$$ are collinear and form a segment $$$\overline{AB}$$$ that is parallel to either the $$$x$$$ or $$$y$$$ axis
  2. Point $$$C$$$ rests on the midpoint exactly equidistant between $$$A$$$ and $$$B$$$
  3. point $$$D$$$ forms a line segment perpendicular to the $$$\overline{AB}$$$ segment when connected with $$$C$$$

Help Ice-T become even more powerful! Given a set of $$$N$$$ points in 2D space, find the number of 'T's present.

Input

The first line of input contains a single integer $$$N$$$ ($$$1 \leq N \leq 1000$$$), the number of points in the 2D plane that Ice-T has already amassed. $$$N$$$ lines follow, each containing two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \leq x_i, y_i \leq 10^9$$$) which give the coordinate location of a unique point in the plane.

Output

Output the total number of unique 'T's contained within the given points.

Note that a single point can contribute to multiple 'T' sets. Additionally, any orientation of a 'T' (vertical, horizontal, or upside-down) is acceptable to Ice-T, so include them all in your total.

Example
Input
11
5 10
7 6
7 4
7 2
1 8
3 8
1 6
3 6
2 4
2 6
5 8
Output
3

G. Scale Goodness
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As an avid musician, Santiago loves to practice his music and work on his fundamentals. One of his favorite exercises is playing through arbitrary scales with notes labelled from $$$1$$$ to $$$n$$$ in order. However, he's recently gotten tired of just playing the same scales over and over again and wants to switch up the order of the notes of the scale.

Before playing each note in the permuted scale, Santiago finds the highest previously played note lower than the current note, $$$l$$$, and the lowest previously played note higher than the current note, $$$r$$$, and defines the goodness of the note as the number of notes in the interval $$$(l, r)$$$ (exclusive). If no such $$$l$$$ exists, Santiago takes all notes equal to or below the current note as part of the interval and if no such $$$r$$$ exists, Santiago takes all notes equal to or above the current note as part of the interval.

Santiago then defines the total goodness of the scale ordering to be the sum of the goodness of the notes played within the scale ordering. Santiago feels he gets higher quality practice from scales with higher goodness. Given a proposed scale ordering, output the total goodness of the corresponding scale so that Santiago knows which scale orderings are worth practicing.

Input

The input will consist of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) giving the total number of notes in Santiago's scale. The next line consists of permutation of size $$$n$$$, $$$a_i$$$ $$$(1 \leq a_i \leq n)$$$, which represents that the $$$i$$$th note in the scale ordering is $$$a_i$$$.

Output

Output the total goodness of the scale ordering as defined above.

Example
Input
5
3 4 5 2 1
Output
11
Note

The first note played, $$$3$$$, has a goodness of $$$5$$$ as no other notes have been played so all are included in the interval. The second note played, $$$4$$$, has a goodness of $$$2$$$ from the interval $$$(3, 5]$$$. The third note played, $$$5$$$, has a goodness of $$$1$$$ from the interval $$$(4, 5]$$$. The fourth note played, $$$2$$$, has a goodness of $$$2$$$ from the interval $$$[1, 3)$$$. The fifth note played, $$$1$$$, has a goodness of $$$1$$$ from the interval $$$[1, 2)$$$. Summing the goodness of each note gives us a total goodness of $$$5 + 2 + 1 + 2 + 1 = 11$$$.