FAMCS Olympiad for scholars, Qualification (copy)
A. Three kings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Three kings: Barley, Hops and Malt brought their troops to the military review. The Emperor of the Beer Empire wants to know which of the kings has more warriors, but he cannot count. Emperor's advisers reported that Barley has $$$a$$$ regiments of $$$x$$$ warriors each, Hops has $$$b$$$ regiments of $$$y$$$ warriors each, and Malt has $$$c$$$ regiments of $$$z$$$ warriors each. Alas, the aged emperor forgot even the simplest arithmetic operations... Help him!

Input

The only line contains 6 integers: $$$a, b, c, x, y, z$$$ ($$$1 \le a, b, c, x, y, z \le 10^3$$$) — the number of regiments of Barley, Hops, Malt, and the number of warriors in them, respectively.

Output

If the king with the strongest army has $$$x$$$ warriors, on a single line print the names of all kings with $$$x$$$ warriors separated by spaces in lexicographical order.

Examples
Input
2 4 3 6 3 4
Output
Barley Hops Malt 
Input
2 3 3 6 3 4
Output
Barley Malt 

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

You have four kettlebells weighing respectively $$$p_1, p_2, p_3, p_4$$$. Is it possible to place all these weights on a balance scale so that the pans of these scales are in a state of equilibrium?

Input

Enter four integers $$$p_1, p_2, p_3, p_4$$$ ($$$1 \le p_i \le 10000$$$)

Output

Print 'YES' or 'NO' depending on whether the weights can be placed properly.

Examples
Input
7 3 5 5
Output
YES
Input
7 3 5 6
Output
NO

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

In the manufacture of picture frames, a special type of board is used - a baguette rail. The edges of this rail are treated differently so that the outer and inner edges stand out. Only the inner edge of the lath can be attached to the picture.

Usually the pictures are rectangular. However, one day a small framing workshop where you work as an apprentice carpenter received a new order: to make frames for an exhibition of paintings by avant-garde artists. The preparation of rails for this order is entrusted to you. When you saw the pictures, you were taken aback at first: they are not rectangular! After examining them more closely, you are convinced that each picture has the form of a convex quadrilateral.

Well, the order must be fulfilled... Unfortunately, the first attempt to prepare the material for the frame, based only on the information about the lengths of the sides of the quadrangle, turned out to be unsuccessful - you did not take into account that these values ​​do not uniquely determine the figure. Friends told you that you need to additionally know the length of one of its diagonals.

Can you determine the minimum length of baguette rail that you need to take to make a frame for one of these paintings? To make a frame, four trapezoidal parts are cut out from the lath. The outer and inner borders of the frame must be made from outer and inner edges of baguette rails respectively. The painting must fit into the frame without gaps or overlaps.

Input

The first line contains information about the width of the rail, the second — five values ​​that specify the type and size of the picture. More precisely, if the corners of the picture are denoted (in order of rotation) by the letters $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$, then the line contains the lengths of the sides $$$AB$$$, $$$BC$$$, $$$CD$$$, $$$DA$$$ and diagonal $$$AC$$$. All numbers are positive, not exceeding $$$10^4$$$ and written with no more than three decimal places.

Output

Выведите рассчитанную длину рейки с точностью до $$$10^{-4}$$$.

Example
Input
2
13 15 25 25 14
Output
102.12605

D. base64 encoding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Base64 is a standard for encoding binary data using only 64 ASCII characters. The encoding alphabet contains the Latin characters A-Z, a-z and 0-9 (62 characters) and two additional characters depending on the implementation system. Every three original bytes are encoded with four characters (thus increasing the number of bytes by $$$25\%$$$). For the purpose of this task, the additional characters are + and /.

To convert data to base64, the first byte is placed in the most significant eight bits of a 24-bit buffer, the next one in the middle eight, and the third one in the least significant eight bits. If less than three bytes are encoded, then the corresponding buffer bits are set to zero. Then every six bits of the buffer, starting with the most significant ones, are used as indexes of the string ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ (indexing starts from zero) and its characters, pointed to by the indices, are placed in the output string. If only one or two bytes are encoded, the result is only the first two or three characters of the string, and the output string is padded with two or one = characters. The process is repeated on the remaining input data.

The table shows the result of encoding the Cat string:

Write a program that encodes a sequence of bytes using the base64 standard.

Input

The first line contains the decimal representation of the length of the encoded sequence (an integer from $$$1$$$ to $$$50\000$$$). The second line contains the values ​​of each byte of this sequence, written as two hexadecimal digits (hexadecimal digits are selected from the string 0123456789ABCDEF) These values ​​are separated by single spaces. There are no spaces at the beginning or end of the string.

Output

Output the source sequence encoded according to the base64 standard.

Examples
Input
3
43 61 74
Output
Q2F0
Input
4
0F DD A4 12
Output
D92kEg==
Note

The first example matches the table from the condition.

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

Two non-empty strings with decimal representation of non-negative real numbers are given. Both integer and fractional parts contain no more than 100 000 digits and are separated by a dot. The fractional part may be absent, and the dot is not recorded in this case. The integer part may also be missing, in which case the dot is at the beginning of the line. Fractional and integer parts cannot be missing at the same time. An arbitrary number of zeros can be written at the beginning and end of the string. There are no other characters except those described in the lines.

Determine which number is bigger...

Input

Enter two strings of numbers in the format described above.

Output

Print a single line with the value -1 if the first of the input numbers is less than the second, 0 if these numbers are equal, and 1 if the first number is greater than the second.

Examples
Input
211.000000000000000001
211
Output
1
Input
15
00000000015.00000000
Output
0
Input
.15
00000000015.00000000
Output
-1

F. Corners
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Corners is one of the many games for two players on the chessboard. Initially, 12 white and black checkers are placed on the board as shown in the figure.

Players take turns moving pieces of their color (white starts the game). Each move consists either in moving one's checker to a free cell vertically or horizontally, or in performing a series of jumps. When jumping, the checker "flies" over the horizontally or vertically adjacent cell occupied by the checker (it does not matter, its own or the opponent's) and descends to the next cell in the same direction, which must be free. During the execution of a series of jumps, you can change the direction of the jumps, but you cannot go down twice on the same cell, as well as on the original cell.

The player who places his checkers on the opponent's starting position earlier than the other wins the game. The game ends in a draw if, after the white checkers have finished rebuilding, black can do the same in a single move.

Luckily, you don't have to write a program to implement this game! Instead, based on the analysis of the current position, determine the longest series of jumps that one of the checkers (of any color) can make. The length of a series is the number of jumps in it.

Input

The input contains eight lines of eight characters each. Each line corresponds to one line of the playing field (from top to bottom) and contains the symbols W, B or a dot, which corresponds to a white, black checker or an empty cell.

Output

The first line should contain the cell position from which the longest series of jumps can be made, in standard chess notation. The second line contains a single number — the number of jumps in such a series. If the problem admits several solutions, print the one for which the designation of the initial cell is minimal in the lexicographic order. If no jump can be made, the only line in the output file must contain the line Impossible.

Examples
Input
BBB.....
BBB.....
BBB.....
BBB.....
.....WWW
.....WWW
.....WWW
.....WWW
Output
a6
1
Input
B.B.B.B.
BB.B.B..
B.B.B.B.
...W....
........
..W.W.WW
WW.W.W..
..W.W.W.
Output
h3
7

G. Card trick
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jim works as a prestige man. In other words, he is a magician. Jim's main specialty is card tricks.

Jim recently came up with a new card trick. Initially, a deck of $$$n$$$ different cards is taken for the trick. After that, the spectator selects one card from the deck, remembers it, returns to the deck and carefully shuffles the cards.

And this is where the magic begins. Jim takes a shuffled deck of cards so that the cards are face down. Then he arranges the cards from the deck into $$$m$$$ piles, with the top card of the deck going into the first pile, the second from the top into the second, $$$m + 1$$$th card, if there is one in the deck, it goes back to the first pile, $$$m + 2$$$th to the second, and so on. After that, Jim asks the spectator which of the piles contains the card that the spectator has guessed. Let the card be in the $$$i$$$-th pile. After that, Jim collects the piles of cards back into one deck. In this case, the $$$i$$$-th heap is on top of the new deck, under it is the $$$i + 1$$$-th, and so on up to the $$$n$$$-th, after which the first heap follows, and so on up to $$$i - 1$$$-th. At the same time, the order of the cards in each pile is preserved, that is, the first card placed in the pile is the top one in the pile, the second is below it. Repeating these operations several times, after a while Jim says that by magic and sorcery he has achieved the hidden card was the top one in the deck. And the card really is the top one.

Consider an example of such a trick. Let $$$n = 6$$$ and cards are denoted by numbers from $$$1$$$ to $$$6$$$, and $$$m = 2$$$. Let the spectator guess the card $$$1$$$, and the crazy deck has the form $$$(4, 2, 1, 5, 6, 3)$$$. The first heaping results in heaps $$$(4, 1, 6)$$$ and $$$(2, 5, 3)$$$, after which Jim collects a deck of $$$(4, 1, 6, 2, 5, 3)$$$ from these piles. At the next step, heaps of $$$(4, 6, 5)$$$ and $$$(1, 2, 3)$$$, after that the deck looks like $$$(1, 2, 3, 4, 6, 5)$$$. And with the help of magic, the hidden card turned out to be the top one!

It depends on which card is hidden and how the cards are mixed in the deck, how many times you need to repeat the magical action to find the hidden card. However, there is such a minimum number $$$k$$$ that for any arrangement of the card in the deck and any hidden card, it is enough to repeat the unfolding $$$k$$$ times for the hidden card to be the top one.

Write a program that, given $$$n$$$ and $$$m$$$, finds the minimum $$$k$$$.

Input

Input two integers $$$n$$$ and $$$m$$$ ($$$2 \le m \le n \le 10^{9}$$$).

Output

Print a single number $$$k$$$ — the minimum number of unfoldings that need to be done in order for the hidden card to be exactly on top of the deck.

Examples
Input
6 2
Output
3
Input
21 3
Output
3

H. Triangles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A regular triangle with a side equal to $$$n$$$ is drawn on a piece of paper. After that, the figure is divided into unit triangles, as shown in the figure for $$$n = 3$$$. How many different triangles can you find in this picture? Triangles are considered distinct if they differ either in size or location.

Input

The only line contains the integer $$$n$$$ ($$$1 \le n \le 10^4$$$).

Output

Print a single number — the number of distinct triangles.

Examples
Input
2
Output
5
Input
4
Output
27