Input file: | Standard input | Time limit: | 1 sec | |
Output file: | Standard output | Memory limit: | 512 Mb |
Oh, those math lessons! Today, for example was the fourth test on the subject. To those who finished ahead of time the teacher offered an extra task for bonus points.
Two n-digit numbers are written on the blackboard, first composed of only the digit d1, second — of only the digit d2. Determine which digit occupies position k in the sum of those numbers. Positions are numbered left to right starting from 1.
You want bonus points, don't you?
Four lines of input contain four integers: n, d1, d2 and k. It is guaranteed that k is correct.
Output a single decimal digit — answer to the problem.
1 ≤ n ≤ 109
1 ≤ k ≤ n + 1
1 ≤ d1, d2 ≤ 9
Sample has n = 2 (adding two-digit numbers), d1 = 5 (first number is 55), d2 = 8 (second number is 88). Sum is 55 + 88 = 143. k = 1 (teacher asks the first digit of the result). The digit at first position of the number 143 is 1.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Ввод / вывод: | интерактивный | Ограничение времени: | 1 сек | |
Ограничение памяти: | 256 Мб |
Данная задача является интерактивной.
На вход подаются числа. Ваша программа должна вычислить их сумму.
На каждом шаге взаимодействия ваша программа должна:
|x| ≤ 263 − 1
|s| ≤ 264 − 1
1 ≤ n ≤ 107
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
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.
First line contains position of the first knight in a format of HW, where H — column (file), W — row (rank).
Output a single integer — number of squares for the second knight.
H ∈ (a, b, c, d, e, f, g, h)
1 ≤ W ≤ 8
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 c1, g1, c3, g3, d4 and f4.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|