Problem A. Bonus points

Input file:Standard input   Time limit:1 sec
Output file:Standard output   Memory limit:512 Mb

Statement

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?

Input format

Four lines of input contain four integers: n, d1, d2 and k. It is guaranteed that k is correct.

Output format

Output a single decimal digit — answer to the problem.

Constraints

1 ≤ n ≤ 109

1 ≤ k ≤ n + 1

1 ≤ d1, d2 ≤ 9

Notes on sample

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.

Sample tests

No. Standard input Standard output
1
2
5
8
1
1

Задача B. online addition

Ввод / вывод:интерактивный   Ограничение времени:1 сек
  Ограничение памяти:256 Мб

Условие

Данная задача является интерактивной.

На вход подаются числа. Ваша программа должна вычислить их сумму.

Протокол взаимодействия

На каждом шаге взаимодействия ваша программа должна:

  1. Считать число x со входного потока.
  2. Если это число равно  − 1 — завершить выполнение.
  3. Иначе произвести необходимые вычисления и вывести во выходной поток текущую сумму s всех x с последующим символом конца строки. Не забудьте сбросить (flush) выходной буфер.

Формат входных данных

единственное число x на каждой из n итераций

Формат выходных данных

единственное число s на каждой из n итераций

Ограничения

|x| ≤ 263 − 1

|s| ≤ 264 − 1

1 ≤ n ≤ 107


Problem C. Edge of the knight

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

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 c1, g1, c3, g3, d4 and f4.

Sample tests

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

0.145s 0.009s 17