Invitational stage of the All-Russian Olympiad in Informatics for schoolchildren
1. Long training
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Eugene is preparing for the city sports competition, where he wants to show himself as the strongest. He trains according to the system of Shaolin monks. The training consists of $$$N$$$ sets, each set lasting for $$$M$$$ minutes and $$$S$$$ seconds, and there is a break of $$$P$$$ seconds between each pair of consecutive sets.

Help Eugene determine how much time the training will take.

Input

The first line contains an integer $$$N$$$ $$$(1 \le N \le 100)$$$, which stands for the number of sets.

The second line contains an integer $$$M$$$ $$$(0 \le M \le 59)$$$, which stands for the number of minutes in one set.

The third line contains an integer $$$S$$$ $$$(0 \le S \le 59)$$$, which is the number of seconds in one set.

The fourth line contains an integer $$$P$$$ $$$(0 \le P \le 120)$$$, which denotes the duration of the break between the sets expressed in seconds.

It is assumed that one set takes a non-zero amount of time.

Output

Output two integers: the duration of training in minutes and seconds. The former equals the number of minutes the training takes. The latter is the number of seconds the training takes, ranging from $$$0$$$ through $$$59$$$.

Example
Input
4
3
24
70
Output
17
6
Note

In the example from the problem, Eugene needs to perform $$$4$$$ sets of training, each set lasts $$$3$$$ minutes $$$24$$$ seconds. At the same time, he will have $$$3$$$ breaks between the sets, each lasting $$$70$$$ seconds. Therefore, the entire training will take $$$17$$$ minutes and $$$6$$$ seconds.

2. Switching TV-Channels
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lisa's parents subscribed to a TV package containing $$$N$$$ TV channels, numbered from $$$1$$$ to $$$N$$$.

There are two buttons for switching channels on the remote control: "$$$+$$$" and "$$$-$$$".

A short press of button "$$$+$$$" switches to the next channel, if the current channel number is less than $$$N$$$. If the current channel number is equal to $$$N$$$, the TV continues to show that channel. If the button "$$$+$$$" is pressed and held for a while and the current TV-channel number is no more than $$$N - K$$$, it will switch to $$$K$$$ channels forward. Otherwise, a switch to channel $$$N$$$ occurs.

Similarly, pressing the button "$$$-$$$" shortly switches to the previous channel, if the current channel number is greater than $$$1$$$. If the current channel number equals $$$1$$$, the TV continues to show that channel. If the button "$$$-$$$" is pressed and held for some time and the current channel number is greater than $$$K$$$, it will switch to $$$K$$$ channels backward. Otherwise, a switch to channel $$$1$$$ occurs.

When Lisa turned on the TV, channel $$$P$$$ was on. Lisa knows that an interesting program will start soon on channel $$$U$$$. Estimate the minimum number of button presses on the TV remote control that Lisa needs to make in order to switch the TV to channel $$$U$$$.

Input

The first line contains an integer $$$N$$$ ($$$3 \le N \le 10^9$$$) which stands for the number of TV channels.

The second line contains an integer $$$K$$$ ($$$2 \le K \lt N$$$), which is the number of channels which are switched backward or forward when holding the corresponding switch button on the TV-controller.

The third line contains an integer $$$P$$$ ($$$1 \le P \le N$$$), which denotes the channel number that was on TV initially.

The fourth line contains an integer $$$U$$$ ($$$1 \le U \le N$$$), which is the channel number that Lisa wants to switch to.

It should be assumed that $$$P \neq U$$$.

Output

You should output a single integer, which stands for the minimum number of times one should press the TV-controller buttons required to switch from channel $$$P$$$ to channel $$$U$$$.

Scoring

Solutions that run correctly for $$$P \lt U$$$, $$$N \le 100$$$ score $$$24$$$ points.

Solutions that run correctly for $$$N \le 100$$$ score $$$48$$$ points.

Examples
Input
20
5
3
19
Output
4
Input
20
5
3
17
Output
4
Input
20
5
14
12
Output
2
Input
20
5
3
16
Output
4
Note

According to the first example, Lisa should first press the button "$$$+$$$" shortly and switch from channel 3 to channel 4, and then switch by 5 channels forward for three times. That is, first switch from channel 4 to channel 9, then from channel 9 to channel 14, and finally from channel 14 to channel 19.

In the second example, Lisa can first switch to channel 2 with a short press on the button "$$$-$$$", and then switch forward by 5 channels for 3 times, so that she switches first from channel 2 to channel 7, then from channel 7 to channel 12, and finally from channel 12 to channel 17.

In the third example, Lisa should press the button "$$$-$$$" shortly 2 times.

In the fourth example, Lisa needs to first switch backward to channel 1 holding the "$$$-$$$" button, and then switch forward three times, switching sequentially from channel 1 to channels 6, 11, and then 16.

3. Treasure Hunter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For his birthday, Timofey got a metal detector form his parents. The next morning, the boy, of course, went in search of treasure. Naturally, the next day the boy went in search of treasure. He assumed that someone might have dropped a gold coin on an ancient straight road a long time ago and, to make his search easier, he came up with a coordinate system. The $$$OX$$$ horizontal axis goes along the road, and the $$$OY$$$ vertical axis goes upwards.

The device works as follows: a positive integer number $$$r$$$ is set on its indicator, and if there is a golden object exactly at this distance, the green light turns on.

First, the young treasure hunter set the number $$$r_1$$$ at point $$$x = 0$$$, then moved to the point with a horizontal coordinate $$$x = a$$$ and set the number $$$r_2$$$, as shown in the figure. Beginners are lucky, the green light turned on both times. Determine the coordinates of the long-lost gold coin.

Input

The program gets three integers $$$a$$$, $$$r_1$$$, and $$$r_2$$$, that are written in separate lines ($$$1 \le a, r_1, r_2 \le 10^{9}$$$).

Output

Output two numbers in two separate lines that are coordinates of the treasure (first is the horizontal coordinate, second stands for the vertical coordinate). The ordinate value cannot be negative (the coin cannot hang in the air). It should be assumed that the input data is such that the answer exists and both coordinates of the coin are integers.

Scoring

Solutions that run correctly for $$$1 \le a, r_1, r_2 \le 100$$$ score $$$40$$$ points.

Solutions that run correctly for $$$1 \le a, r_1, r_2 \le 10^5$$$ score $$$60$$$ points.

Example
Input
21
10
17
Output
6
-8
Note

The figure illustrates the example from the problem.

4. Claims Processing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a pile of $$$N$$$ claims on the desk of a big boss. The claims are numbered from top to bottom from $$$1$$$ to $$$N$$$.

The boss signs the first claim and removes it from the pile, throws away the second one, and puts the third one down the pile. The process continues in this fashion until all the claims in the pile are gone.

Determine whether the claim with number $$$K$$$ will be signed or thrown away, and also the number of the step during which this will happen. One step is each of the three actions described above.

Input

The first line of the input contains an integer $$$N$$$, the second line contains an integer $$$K$$$ ($$$1 \le N \le 10^9$$$, $$$1 \le K \le N$$$).

Output

Оutput "Yes" if the claim with number $$$K$$$ will be signed, and "No" if it will be thrown away.

In the second line, output the step number during which this will happen.

Scoring

Solutions that runs correctly for $$$N \le 1000$$$ score 40 points.

Solutions that runs correctly for $$$N \le 5\cdot10^5$$$ score 60 points.

Examples
Input
4
3
Output
No
5
Input
5
3
Output
Yes
7
Note

In the first example in the problem, there are 4 claims in the pile: (1, 2, 3, 4). Claim 1 is signed, claim 2 is thrown away, and claim 3 is moved down to the bottom. After three steps, the pile will have claims (4, 3). Therefore, on the fifth step, claim 3 will be thrown away.

In the second example in the problem statement, the pile has claims (1, 2, 3, 4, 5). After three steps, the pile will look like (4, 5, 3). Over the next three steps, claim 4 will be signed, claim 5 will be thrown away, and claim 3 will be moved down the pile (which will contain nothing but claim 3). Therefore, after six steps, the pile will have the form (3). On the seventh step, claim 3 will be signed.

5. Beware, Evil Numbers!
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In mathematics, a non-negative integer with an even number of ones in its binary notation is called an evil number (for example, number 5 is evil, as it has two ones in its binary notation). These numbers are used in number theory when studying the Morse–Thue sequence and are applied in fractal image compression algorithms.

A positive integer is called very evil if it is even and the number of ones in its binary notation is also even. These are such numbers as 6, 10, 12, 18, 20, etc.

Given $$$n$$$, find the number of very evil numbers which do not exceed $$$n$$$.

Input

The only line of the input file contains an integer number $$$n$$$ ($$$1 \le n \le 10^{9}$$$).

Output

Output a single integer, which is the number of very evil numbers not exceeding $$$n$$$.

Scoring

Solutions that run correctly when $$$n$$$ does not exceed $$$10^{5}$$$ score 30 points.

Solutions that run correctly when $$$n$$$ is an exact power of 2 score 30 points.

Example
Input
20
Output
5