Олимпиадный тренинг

Задача 33593. Laces


A shoe factory is about to start producing an elite model of boots. The holes for lacing will be arranged in two rows, the distance between the rows is  a, and the distance between the holes in the row b. The number of holes in each row is N. Lacing should take place in an elite way “up, horizontally to another row, up, horizontally, etc.” (see picture). In addition, in order for the laces to be tied with an elite bow, the length of the free end of the lace must be l. What is the lace length for these boots?
Forbidden to use if, while, for, repeat-until statements (Pascal)

Input: The program takes as input four natural numbers a, b, l and N.

Output: The program should output a single number – desired lace length.

Examples
input
2
1
3
4
output
26
Запрещенные операторы:for;while;until;max;min