Problem A. Absolutely simple

Author:A. Klenin   Time limit:1 sec
Input file:input.txt   Memory limit:256 Mb
Output file:output.txt  

Statement

Vasya likes to decrease numbers, but does not like negative numbers. So, he picks some integer A1 and starts to decrease it by 100 and take an absolute value of the result. In other words, on each step he calculates next number in the sequence Ai + 1 = |Ai − 100|.

When Vasya calculates a number which was already present in the sequence, he gets bored and stops. Your program must, given A1, determine the number of steps Vasya would perform.

For example, if A1 = 1 then A2 = |1 − 100| = 99, and A3 = |99 − 100| = 1, so Vasya performs 2 steps.

Input file format

Input file contains a single integer A1.

Output file format

Output file must contain a single integer N — number of steps.

Constraints

0 ≤ |A1| ≤ 109

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
1
2
2
-1
4
3
500
6

Problem B. Edge of the knight

Author:A. Usmanov   Time limit:1 sec
Input file:input.txt   Memory limit:256 Mb
Output file:output.txt  

Statement

In a chess, it is useful in some positions if two knight figures cover one another.

Sergey has already placed one knight on an empty chess board. Now he wants to know number of squares where he can place the second knight so that knights would cover each other.

Input file format

First line contains position of the first knight in a format of HW, where H — column (file), W — row (rank).

Output file format

Output a single integer — number of squares for the second knight.

Constraints

H ∈ (a, b, c, d, e, f, g, h)

1 ≤ W ≤ 8

Note on samples

Remember that a knight moves in a shape of letter L. Knight moves for 1 square in one direction (vertically or horizontally), and for 2 squares in another direction.

In the first sample the second knight can be placed on squares c 1, g 1, c 3, g 3, d 4 and f 4.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
e2
6
2
f5
8

Problem C. Avengers and Shawarma

Author:A. Usmanov. Translation: V. Toropov.   Time limit:1 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

Avengers defeated alien invaders and decided to eat some shawarma.

Hulk ordered N shawarmas. M shawarmen immediately started to cook his order. Each shawarman can cook his first shawarma in T minutes. Each next shawarma requires S minutes more to cook than the previous one.

HULK SMASHes!!! awaiting his shawarmas.

You should help Avengers to find out the time when all shawarmas ordered by Hulk will be ready and green giant will calm down. Of course, Jarvis could solve this task, but Iron Man's suit is broken and only air conditioner is working right now.

Input format

First line contains two integers N and M — number of shawarmas ordered by Hulk, and number of shawarmen who are going to complete his order.

Second line contains two integers T and S — time needed to cook the first shawarma and the difference of cooking time between two shawarmas in the row.

Output format

Print one integer — time needed to complete Hulk's order.

Constraints

1 ≤ N, M, T ≤ 100

0 ≤ S ≤ 100

Sample tests

No. Standard input Standard output
1
5 2
10 5
45
2
13 4
4 1
22
3
10 1
5 0
50

0.284s 0.020s 17