eolymp
bolt
Try our new interface for solving problems
Problems

Recursion - 2

Recursion - 2

The integers $a$, $b$, $c$ are given. Implement the recursive function:

$f(n) = \begin{cases} a, n = 0\\f(n - 1) + bn + c, n > 0\end{cases}$

Input

Four integers $a, b, c\:(|a|, |b|, |c| \le 1000), n\:(0 \le n \le 1000)$.

Output

Print the value of $f(n)$.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4 2 -3 10
Output example #1
84
Author Michael Medvediev