The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seconds to pass.

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.


-----Input-----

The first line contains two integers v_1 and v_2 (1 ≤ v_1, v_2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

It is guaranteed that there is a way to complete the segment so that:  the speed in the first second equals v_1,  the speed in the last second equals v_2,  the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d. 


-----Output-----

Print the maximum possible length of the path segment in meters. 


-----Examples-----
Input
5 6
4 2

Output
26
Input
10 10
10 0

Output
100


-----Note-----

In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.

In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.

Source: codeforces | Difficulty: MEDIUM
Tags: Dynamic programming

Mathematics

Greedy algorithms


Solutions:
R = lambda : map(int, input().split())
F = lambda : [int(x) for x in input().split()]
(v1, v2) = R()
(t, d) = R()
ans = v1 + v2
a1 = []
a2 = []
t1 = v1
t2 = v2
for i in range(t - 2):
	t1 += d
	t2 += d
	a1.append(t1)
	a2.append(t2)
a2.reverse()
for i in range(t - 2):
	ans += min(a1[i], a2[i])
print(ans)


(v1, v2) = sorted(map(int, input().split()))
(t, d) = map(int, input().split())
f = [v1 + i * d for i in range(t)]
s = [v2 + i * d for i in range(t)]
s.reverse()
ans = 0
for i in range(t):
	ans += min(f[i], s[i])
print(ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
print(sum([min(v1 + i * d, v2 + (t - 1 - i) * d) for i in range(t)]))


import sys
import math
import bisect

def main():
	(s, t) = map(int, input().split())
	(n, d) = map(int, input().split())
	A = [0] * n
	A[0] = s
	A[n - 1] = t
	for i in range(n - 1):
		A[i] = min(A[0] + d * i, A[n - 1] + (n - 1 - i) * d)
	print(sum(A))
main()


(vi, vf) = [int(k) for k in input().split()]
(t, d) = [int(k) for k in input().split()]
distances = [0] * t
for i in range(t - 1):
	f_max = vi + i * d
	b_max = vf + (t - 1 - i) * d
	maxi = min(f_max, b_max)
	distance = vi
	v = vi
	for j in range(i):
		v += min(d, maxi - v)
		distance += v
	distance1 = vf
	v = vf
	for j in range(t - 2, i, -1):
		v += min(d, maxi - v)
		distance1 += v
	distances[i] = distance + distance1
print(max(distances))


(v1, v2) = map(int, input().strip().split())
(t, d) = map(int, input().strip().split())
res = 0
l = v1
r = v2 + (t - 1) * d
for i in range(t):
	res += min(l, r)
	l += d
	r -= d
print(res)


(s, e, t, d) = [int(x) for x in input().split() + input().split()]
r = 0
for i in range(t):
	r += min(s + i * d, e + (t - i - 1) * d)
print(r)


(w1, w2) = list(map(int, input().split()))
(t, d) = list(map(int, input().split()))
a = [0] * t
if w1 > w2:
	(w1, w2) = (w2, w1)
a[t - 1] = w2
a[0] = w1
r = w1 + w2
if t % 2 == 1:
	b = t // 2
else:
	b = t // 2
for i in range(t - 2, b - 1, -1):
	a[i] = a[i + 1] + d
for i in range(1, t - 1):
	if a[i] == 0:
		a[i] = a[i - 1] + d
		r += a[i]
	elif a[i] - a[i - 1] > d:
		a[i] = a[i - 1] + d
		r += a[i]
	else:
		r += a[i]
print(r)


(v1, v2) = map(int, input().split(' '))
(t, d) = map(int, input().split(' '))
(l1, l2) = ([], [])
for (l, v) in zip((l1, l2), (v1, v2)):
	for i in range(t):
		l.append(v + d * i)
l2 = list(reversed(l2))
split = 0
for i in range(t):
	if l2[i] <= l1[i]:
		split = i
		break
l = l1[:split] + l2[split:]
print(sum(l))


from math import ceil
(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
dis = v1 + v2
for i in range(t - 2, 0, -1):
	for j in range(d, -d - 1, -1):
		a = ceil((v2 + j - v1) / i)
		if a > d:
			continue
		else:
			v2 = v2 + j
			dis = dis + v2
			break
print(dis)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
arr = []
arr1 = []
ans = 0
for i in range(t):
	arr.append(v1 + i * d)
	arr1.append(v2 + (t - i - 1) * d)
for i in range(t):
	if arr[i] <= arr1[i]:
		ans += arr[i]
	else:
		ans += arr1[i]
print(ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if t == 2:
	print(v1 + v2)
	from sys import exit
	exit()
(mi, ma) = (min(v1, v2), max(v1, v2))
res = v1 + v2
i = 0
if v1 != v2:
	while ma > mi + d:
		mi += d
		res += mi
		i += 1
	if t - 2 - i > 0:
		mi += d
		res += mi
		i += 1
	if i + 2 > t:
		res -= ma
for j in range((t - 2 - i) // 2):
	mi += d
	ma += d
	res += mi + ma
if (t - 2 - i) % 2 == 1 and i + 2 <= t:
	res += ma + d
print(res)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
res = 0
for i in range(1, t + 1):
	r1 = v1 + (i - 1) * d
	r2 = v2 + (t - i) * d
	res += min(r1, r2)
print(res)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
a = [0] * t
a[0] = v1
a[-1] = v2
left = 0
right = t - 1
while left != right - 1:
	if a[left] <= a[right]:
		left += 1
		a[left] = a[left - 1] + d
	else:
		right -= 1
		a[right] = a[right + 1] + d
print(sum(a))


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
a = [0] * t
b = [0] * t
(a[0], b[t - 1]) = (v1, v2)
for i in range(1, t):
	a[i] = a[i - 1] + d
for i in range(t - 2, -1, -1):
	b[i] = b[i + 1] + d
ans = sum([min(a[i], b[i]) for i in range(t)])
print(ans)


(a, b) = map(int, input().split())
(t, d) = map(int, input().split())
first = [0] * t
first[0] = a
for i in range(1, t):
	first[i] = first[i - 1] + d
second = [0] * t
second[0] = b
for i in range(1, t):
	second[i] = second[i - 1] + d
second = second[::-1]
final = [0] * t
for i in range(t):
	final[i] = min(first[i], second[i])
print(sum(final))


from collections import Counter, defaultdict, deque
import heapq as hq
from itertools import count, islice
import math
import sys
input = sys.stdin.readline
(v1, v2) = [int(x) for x in input().split()]
(t, d) = [int(x) for x in input().split()]
f = [v1]
b = [v2]
for i in range(t - 1):
	f.append(f[-1] + d)
	b.append(b[-1] + d)
b.reverse()
ans = 0
for i in range(t):
	ans += min(b[i], f[i])
print(ans)


(v1, v2) = map(int, input().split(' '))
(t, d) = map(int, input().split(' '))
a = [0] * (t + 1)
a[0] = v1
a[t - 1] = v2
cvb = 0
for i in range(1, t - 1):
	a[i] = min(a[i - 1] + d, v2 + (t - i - 1) * d)
	cvb += a[i]
print(cvb + v1 + v2)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
ans = 0
for i in range(1, t + 1):
	ans += min(v1 + d * (i - 1), v2 + d * (t - i))
print(ans)


[v1, v2] = [int(x) for x in input().split()]
[t, d] = [int(x) for x in input().split()]
left = [v1] * t
for i in range(1, t):
	left[i] = left[i - 1] + d
right = [v2] * t
for i in range(t - 2, -1, -1):
	right[i] = right[i + 1] + d
ans = 0
for i in range(t):
	ans += min(left[i], right[i])
print(ans)


(v1, v2) = [int(x) for x in input().split()]
(t, d) = [int(x) for x in input().split()]
total = 0
for i in range(t):
	total += v1
	if v1 + d - (t - i - 2) * d <= v2:
		v1 += d
	else:
		v1 = v2 + (t - i - 2) * d
print(total)


from math import inf
memo = {}

def foo(s, e, d, n):
	if n == 0:
		if abs(s - e) <= d:
			return s + e
		return -inf
	if (s, e, d, n) in memo:
		return memo[s, e, d, n]
	c = -inf
	for i in range(s - d, s + d + 1):
		if i <= 0:
			continue
		c = max(c, foo(i, e, d, n - 1))
	memo[s, e, d, n] = c + s
	return c + s
(s, e) = map(int, input().split())
(t, d) = map(int, input().split())
print(foo(s, e, d, t - 2))


import os
import sys
from io import BytesIO, IOBase
from math import inf

def main():
	(u, v) = map(int, input().split())
	(a, b) = map(int, input().split())
	dp = [[-1 for _ in range(1500)] for _ in range(1500)]

	def solve(t, x):
		if t == a:
			if x == v:
				return v
			else:
				return -inf
		if dp[t][x] != -1:
			return dp[t][x]
		ans = -inf
		for i in range(b + 1):
			ans = max(ans, solve(t + 1, x + i) + x)
			if x - i > 0:
				ans = max(ans, solve(t + 1, x - i) + x)
		dp[t][x] = ans
		return ans
	print(solve(1, u))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(a, b) = r()
(t, d) = r()
t -= 2
rem = t
diff = b - a
need = 0
if diff and d:
	need = (diff + d - 1) // d
ans = a + b
while rem:
	x = b + rem * d
	a = min(a + d, x)
	ans += a
	rem -= 1
print(ans)


def main():
	(v1, v2) = map(int, input().split())
	(t, d) = map(int, input().split())
	print(sum((min(vv) for vv in zip(range(v1, v1 + t * d, d), range(v2 + (t - 1) * d, v2 - 1, -d)))) if d else v1 * t)
main()


import sys
(curr_speed, v2) = [int(s) for s in sys.stdin.readline().split()]
(t, d) = [int(s) for s in sys.stdin.readline().split()]
path = [curr_speed]
sec_left = t - 2
while sec_left:
	max_allowed = v2 + d * sec_left
	max_possible = curr_speed + d
	curr_speed = min(max_allowed, max_possible)
	path.append(curr_speed)
	sec_left -= 1
path.append(v2)
print(sum(path))


(v1, v2) = list(map(int, input().split()))
(t, d) = list(map(int, input().split()))
if v1 > v2:
	(v1, v2) = (v2, v1)
if d == 0:
	print(t * v1)
else:
	a = [i for i in range(v1, v1 + t * d, d)]
	b = [i for i in range(v2, v2 + t * d, d)]
	b.reverse()
	i = 0
	answer = 0
	while i < t - 1:
		if abs(a[i] - b[i + 1]) <= d:
			if sum(a[:i + 1]) + sum(b[i + 1:]) > answer:
				answer = sum(a[:i + 1]) + sum(b[i + 1:])
		i += 1
	print(answer)


import itertools
(v1, v2) = list(map(int, str.split(input())))
(t, d) = list(map(int, str.split(input())))
cv = v1
s = v1 + v2
steps = list(itertools.accumulate((v1,) + tuple(range(2, t)), lambda x, _: x + d)) + [v2]
for i in range(t - 1, -1, -1):
	if steps[i - 1] - steps[i] > d:
		steps[i - 1] = steps[i] + d
	else:
		break
print(sum(steps))


(a, b) = list(map(int, input().split(' ')))
(t, d) = list(map(int, input().split(' ')))
if d == 0:
	print(a * t)
else:
	dist = 0
	t -= 1
	dist += a
	if t == 0:
		print(dist)
		quit()
	while a - b + d <= (t - 1) * d:
		a += d
		dist += a
		t -= 1
	if t == 0:
		print(dist)
		quit()
	extra = -1 * (a - b - d * (t - 1))
	a += extra
	dist += a
	t -= 1
	while t > 0:
		a -= d
		t -= 1
		dist += a
	print(dist)


import sys
input = lambda : sys.stdin.readline()
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : list(map(int, input().split()))
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(v1, v2) = f()
(t, d) = f()
(lf, lb) = ([0] * t, [0] * t)
lf[0] = v1
lb[-1] = v2
(sff, sfb) = ([0] * t, [0] * t)
(sff[0], sfb[-1]) = (v1, v2)
for i in range(1, t):
	lf[i] = lf[i - 1] + d
	lb[t - i - 1] = lb[t - i] + d
	sff[i] = sff[i - 1] + lf[i]
	sfb[t - i - 1] = sfb[t - i] + lb[t - i - 1]
mx = 0
for i in range(t - 1):
	if abs(lf[i] - lb[i + 1]) <= d:
		mx = max(mx, sff[i] + sfb[i + 1])
print(mx)


r = lambda : map(int, input().split())
(a, b) = r()
(t, d) = r()
print(sum((min(a + d * i, b + d * (t - i - 1)) for i in range(t))))
quit()
n = int(input())
arr = tuple(map(int, input().split()))
l = 0
lastedgelocation = 0
lastedge = 0
maxx = -1
for i in range(1, n):
	temp = arr[i] - arr[i - 1]
	if temp:
		if temp == lastedge:
			l = lastedgelocation
		lastedge = temp
		lastedgelocation = i
	maxx = max(maxx, i - l + 1)
print(maxx)
n = int(input())
a = tuple(map(int, input().split()))
block_size = int(pow(n, 0.5))
b = [0 for i in range(n // block_size + 2)]
for i in range(0, n, block_size):
	b[i // block_size] = sum(a[i:i + block_size])
q = int(input())
for _ in range(q):
	(l, r) = map(lambda x: int(x) - 1, input().split())
	(l1, l2) = (l // block_size, r // block_size)
	s = sum(b[l1:l2]) - sum(a[l1 * block_size:l]) + sum(a[l2 * block_size:r + 1])
	print(s // 10)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(v1, v2) = get_ints()
(n, d) = get_ints()
Arr = [0] * n
Arr[0] = v1
Arr[-1] = v2
maxi_Arr = [i for i in Arr]
for i in range(n - 2, 0, -1):
	maxi_Arr[i] = maxi_Arr[i + 1] + d
for i in range(1, n - 1):
	if Arr[i - 1] + d <= maxi_Arr[i]:
		Arr[i] = Arr[i - 1] + d
	else:
		Arr[i] = maxi_Arr[i]
print(sum(Arr))


s = [int(n) for n in input().split()]
z = [int(n) for n in input().split()]
a = [s[0] + n * z[1] for n in range(z[0])]
b = [s[1] + n * z[1] for n in range(z[0])]
b = b[::-1]
k = 0
for n in range(z[0]):
	if abs(a[n] - b[n + 1]) <= z[1]:
		k = n
		break
m = sum(a[:k + 1]) + sum(b[k + 1:])
print(m)


ninf = -500000
(u, v) = map(int, input().split(' '))
(t, d) = map(int, input().split(' '))
l = [[ninf] * 1201 for _ in range(2)]
l[0][u] = u
for i in range(1, t):
	for j in range(1201):
		l[i & 1][j] = max(l[~i & 1][max(0, j - d):min(1200, j + d) + 1]) + j
print(l[t - 1 & 1][v])


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate
from sys import stdout
R = lambda : map(int, input().split())
(v1, v2) = R()
(t, d) = R()
maxv = max(v1, v2) + t * d + 1
dp = [[-math.inf for j in range(maxv)] for i in range(t)]
dp[0][v1] = v1
for i in range(1, t):
	for v in range(maxv):
		dp[i][v] = max((dp[i - 1][v + dx] if 1 <= v + dx < maxv else -math.inf for dx in range(-d, d + 1))) + v
print(dp[-1][v2])


import itertools, functools, math

def solve():
	(v1, v2) = map(int, input().split())
	(t, d) = map(int, input().split())
	s = [0] * (t - 1)
	for i in range(t - 1):
		s[i] = min(v1 + d * i, v2 + d * (t - i - 1))
	s += [v2]
	return sum(s)
print(solve())


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
vm = [0] * t
v = v1
for i in range(t):
	vm[i] = v
	v += d
v = v2
for i in range(t - 1, -1, -1):
	vm[i] = min(v, vm[i])
	v += d
print(sum(vm))


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(v1, v2) = lst()
	(n, d) = lst()
	N = 1001
	dp = [[0 for _ in range(N)] for _ in range(n)]
	dp[0][v1] = v1
	for i in range(1, n - 1):
		for j in range(N):
			for diff in range(-d, d + 1):
				if 0 <= j + diff < N and dp[i - 1][j + diff] != 0:
					dp[i][j] = max(dp[i][j], dp[i - 1][j + diff] + j)
	for diff in range(-d, d + 1):
		if v2 + diff >= 0:
			dp[n - 1][v2] = max(dp[n - 1][v2], dp[n - 2][v2 + diff] + v2)
	print(dp[n - 1][v2])


(v1, v2) = map(int, input().split(' '))
(t, d) = map(int, input().split(' '))
t -= 1
total = v1
while v1 + d - (t - 1) * d <= v2 and t:
	v1 += d
	total += v1
	t -= 1
diff = v2 + (t - 1) * d - v1
if t:
	v1 += diff
	t -= 1
	total += v1
while t:
	t -= 1
	v1 -= d
	total += v1
print(total)
assert v1 == v2


(start, end) = map(int, input().split())
(t, d) = map(int, input().split())
ans = 0
for i in range(t):
	if start > end:
		(start, end) = (end, start)
	ans += start
	start += d
print(ans)


(v1, v2) = [int(c) for c in input().split()]
(t, d) = [int(c) for c in input().split()]
dist = v1
i = 1
while i <= t - 2:
	dist += min(v1 + i * d, v2 + (t - 1) * d - i * d)
	i += 1
dist += v2
print(dist)


(u, v) = (int(x) for x in input().split())
(t, d) = (int(x) for x in input().split())
ans = 0
while t > 1:
	if u < v:
		ans += u
		u += d
	else:
		ans += v
		v += d
	t -= 1
print(ans + min(u, v))


(u1, u2) = map(int, input().split())
(t, d) = map(int, input().split())
if u1 > u2:
	(u1, u2) = (u2, u1)
s = [u1 for i in range(t - 1)]
s.append(u2)
l = 1
r = t - 2
for i in range(t - 2, 0, -1):
	s[i] = s[i + 1] + d
i = 1
while s[i] - s[i - 1] > d:
	s[i] = s[i - 1] + d
	i += 1
print(sum(s))


(v1, v2) = list(map(int, input().split()))
(t, d) = list(map(int, input().split()))
L1 = [0] * t
L2 = [0] * t
L1[0] = v1
for i in range(1, t):
	L1[i] = L1[i - 1] + d
j = t - 2
L2[j + 1] = v2
while j >= 0:
	L2[j] = L2[j + 1] + d
	j -= 1
ans = 0
for i in range(0, t):
	ans += min(L1[i], L2[i])
print(ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
dst = v1
for i in range(2, t + 1):
	for x in range(d):
		if abs(v1 + 1 - v2) <= d * (t - i):
			v1 += 1
		elif abs(v1 - v2) > d * (t - i):
			if v1 > v2:
				v1 -= 1
			else:
				v1 += 1
	dst += v1
print(dst)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
(INF, C) = (99999, 1200)
S = [[-INF] * C for i in range(t + 1)]
S[1][v1] = v1
for i in range(2, t + 1):
	for j in range(1, C - 2 * d):
		for k in range(-d, d + 1):
			if j + k > 0 and S[i - 1][j + k] != -INF:
				S[i][j] = max(S[i][j], S[i - 1][j + k] + j)
print(S[t][v2])


import math
v = list(map(int, input().split()))
total = 0
b = list(map(int, input().split()))
t = b[0]
d = b[1]
if v[0] <= v[1]:
	total = v[0] * t
	a = v[1] - v[0]
else:
	total = v[1] * t
	a = v[0] - v[1]
del b
del v
if d != 0:
	t -= 1
	b = math.floor((t + a / d) / 2)
	total += b * (b + 1) * d / 2 + (t - b) * (t - b - 1) / 2 * d + a * (t - b)
print(int(total))


r = lambda : map(int, input().split())
(a, b) = r()
(t, d) = r()
print(sum((min(a + d * i, b + d * (t - i - 1)) for i in range(t))))


(v1, v2) = [int(x) for x in input().split()]
(t, d) = [int(x) for x in input().split()]
pre1 = [v1]
pre2 = [v2]
for i in range(1, t):
	pre1.append(pre1[i - 1] + d)
for i in range(1, t):
	pre2.append(pre2[i - 1] + d)
pre2 = pre2[::-1]
ans = 0
for i in range(t):
	ans += min(pre1[i], pre2[i])
print(ans)


(V1, V2) = map(int, input().split())
(T, D) = map(int, input().split())
Arr = [0] * 101
Arr2 = [0] * 101
for I in range(1, T + 1):
	Arr[I] = V1
	V1 += D
	Arr2[T + 1 - I] = V2
	V2 += D
Ans = K = 0
for I in range(1, T):
	if Arr2[I + 1] - Arr[I] > D:
		K = I
		Ans += Arr[I]
Ans += Arr[K + 1]
K += 2
for J in range(K, T + 1):
	Ans += Arr2[J]
print(Ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if v1 > v2:
	(v1, v2) = (v2, v1)
ans = v1 + v2
left = 0
need = v2 + d
remove = 0
for i in range(t - 2):
	dif = need - v1
	if dif > 0:
		if dif <= d:
			if t - 2 - i - 1 > 0:
				v1 += d
				remove = v1 - need
			else:
				v1 += dif
		else:
			v1 += d
		ans += v1
	else:
		left = t - 2 - i
		break
if left:
	updown = left // 2
	stable = left % 2
	if not stable:
		for i in range(updown - 1):
			v1 += d
			ans += v1
		v1 += d - remove
		ans += v1
	else:
		for i in range(updown):
			v1 += d
			ans += v1
		v1 -= remove
		ans += v1
	for i in range(updown):
		v1 -= d
		ans += v1
print(ans)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())
(v1, v2) = mi()
(t, d) = mi()
r1 = [v1] + [0] * (t - 1)
r2 = [0] * (t - 1) + [v2]
ans = v1 + v2
for i in range(1, t - 1):
	r1[i] = r1[i - 1] + d
for i in range(t - 2, 0, -1):
	r2[i] = r2[i + 1] + d
for i in range(1, t - 1):
	ans += min(r1[i], r2[i])
print(ans)


__author__ = 'clumpytuna'
(v1, v2) = map(int, input().split(' '))
(t, d) = map(int, input().split(' '))
sum = v1
z = d
for i in range(2, t):
	if v1 + d - (t - i) * d <= v2:
		v1 += d
		sum += v1
	else:
		while v1 + z - (t - i) * d > v2:
			z -= 1
		v1 = v1 + z
		sum += v1
		z = d
print(sum + v2)


from sys import stdin, stdout
from math import gcd
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(u, v) = iia()
(t, d) = iia()
res = 0
for i in range(t):
	if u > v:
		res += v
		v += d
	else:
		res += u
		u += d
print(res)


import math
(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
ans = v1 + v2
speed = v1
rem = t - 2 + 1
for i in range(t - 2):
	if speed + d - (rem - 1) * d <= v2:
		speed += d
		ans += speed
		rem -= 1
	else:
		x = v2 + (rem - 1) * d - speed
		if x == 0:
			ans += speed
			rem -= 1
		elif x > 0:
			speed += x
			ans += speed
			rem -= 1
		else:
			speed -= min(d, abs(v2 + (rem - 1) * d - speed))
			ans += speed
			rem -= 1
print(ans)


def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return [str(x) for x in stdin.readline().split()]

def dp():
	mem[1, v1] = v1
	for i in range(2, t + 1):
		for j in range(-500, 600):
			for k in range(-d, d + 1):
				mem[i, j] = max(mem[i, j], j + mem[i - 1, j + k])
	return
from sys import stdin
from collections import *
from math import ceil
(v1, v2) = arr_inp(1)
(t, d) = arr_inp(1)
mem = defaultdict(lambda : float('-inf'))
dp()
print(mem[t, v2])


(i, f) = map(int, input().split())
(t, d) = map(int, input().split())
a = []
b = []
a = [i + j * d for j in range(t)]
b = [f + j * d for j in range(t)]
b.reverse()
for j in range(t):
	if a[j] >= b[j]:
		print(sum(a[:j]) + sum(b[j:]))
		quit()


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
total = 0
for i in range(t):
	total += v1
	v = min(d, v2 + (t - i - 2) * d - v1)
	if v > 0:
		v1 += v
	elif v1 > v2 and i + 1 != t:
		dd = max(0, v1 - v2 - (t - i - 2) * d)
		v1 -= dd
print(total)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if t == 2:
	print(v1 + v2)
	exit()
ans = []
gan = []
for i in range(t - 2):
	if i == 0:
		ans.append([max(v1 - d, 0), v1 + d])
		gan.append([max(v2 - d, 0), v2 + d])
	else:
		ans.append([max(ans[i - 1][0] - d, 0), ans[i - 1][1] + d])
		gan.append([max(gan[i - 1][0] - d, 0), gan[i - 1][1] + d])
total = 0
gan = gan[::-1]
for i in range(len(ans)):
	total += min(ans[i][1], gan[i][1])
print(total + v1 + v2)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if d == 0:
	print(v1 * t)
else:
	i = 0
	while i < t:
		vm = i * d + v2
		if t - 1 - i == (vm - v1) // d + ((vm - v1) % d > 0) or t - 1 - i == (vm - v1) // d + ((vm - v1) % d > 0) + 1:
			break
		i += 1
	rs = 0
	v = v1
	j = (vm - v1) // d + ((vm - v1) % d > 0)
	for k in range(j):
		rs = rs + v
		v = v + d
	if i + j < t - 1:
		rs = rs + v
	v = v2
	for k in range(i + 1):
		rs = rs + v
		v = v + d
	print(rs)


(v1, v2) = [int(x) for x in input().split()]
(t, d) = [int(x) for x in input().split()]
dist = [0] * t
dist[0] = v1
curr_speed = v1
for i in range(1, t):
	max_val = v2 + d * (t - i - 1)
	curr_speed = min(curr_speed + d, max_val)
	dist[i] = dist[i - 1] + curr_speed
print(dist[t - 1])


import math
memo = [[-1 for j in range(11000)] for i in range(110)]

def dp(index, prev):
	global v1, v2, N, d, memo
	if index == N - 1:
		if abs(prev - v2) > d:
			return -1001000
		return v2
	if memo[index][prev] != -1:
		return memo[index][prev]
	ans = -1001000
	for k in range(-d, d + 1):
		pick = prev + k
		if pick < 0 or abs(pick - v2) > d * (N - index):
			continue
		ans = max(ans, dp(index + 1, pick) + pick)
	memo[index][prev] = ans
	return ans
(v1, v2) = tuple((int(i) for i in input().split()))
(N, d) = tuple((int(i) for i in input().split()))
print(int(dp(1, v1)) + v1)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if d == 0:
	print(v1 * t)
	exit()
print(sum((min(v1 + d * i, v2 + d * (t - i - 1)) for i in range(t))))


import os
from string import *
from math import *
from itertools import *
from collections import *
from re import *
from sys import *
from bisect import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
x = lambda : map(int, input().split())
(a, b) = x()
(c, d) = x()
(dp, dp1) = ([0] * c, [0] * c)
for i in range(c):
	dp[i] = a + i * d
for i in range(c):
	dp1[c - i - 1] = b + i * d
for i in range(c):
	dp[i] = min(dp[i], dp1[i])
print(sum(dp))


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(u, v) = Neo()
(t, d) = Neo()
Ans = 0
if d == 0:
	Ans += t * u
	print(Ans)
	exit()
for i in range(t):
	p = i
	q = i + 1
	s = u
	e = v
	k = 0
	for a in range(i + 1):
		k += s
		s += d
	for b in range(q, t):
		k += e
		e += d
	if abs(e - s) <= d:
		Ans = max(Ans, k)
	elif e > s:
		c = 0
		k -= e
		while c <= d:
			z = e - c
			if abs(z - s) <= d:
				k += z
				Ans = max(Ans, k)
				break
			c += 1
	else:
		c = 0
		k -= s
		while c <= d:
			z = s - c
			if abs(z - e) <= d:
				k += z
				Ans = max(Ans, k)
				break
			c += 1
print(Ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
s = 0
c1 = v1
c2 = v2 + d * (t - 1)
for i in range(t):
	s += min(c1, c2)
	c1 += d
	c2 -= d
print(s)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(a, b) = sep()
	(t, d) = sep()
	ans = a + b
	for i in range(2, t):
		temp = a + d
		if temp - (t - i) * d <= b:
			ans += temp
			a = temp
		else:
			temp = b + (t - i) * d
			ans += temp
			a = temp
	print(ans)
testcase(1)


from sys import stdin, stdout
from math import *
from itertools import *
lmap = lambda x, y: list(map(x, y))
lfilter = lambda x, y: list(filter(x, y))

def max_acceleration(v, v2, tl, d):
	max_next_v = v2 + d * (tl - 2)
	return min(d, max_next_v - v)

def solve(test):
	(v1, v2, t, d) = lmap(int, test.strip().split())
	v = v1
	s = 0
	for i in range(t):
		s += v
		v += max_acceleration(v, v2, t - i, d)
	return s
stdout.write(str(solve(stdin.read())))


vs = input().split()
v1 = int(vs[0])
v2 = int(vs[1])
vals = input().split()
t = int(vals[0])
d = int(vals[1])
a = [0 for i in range(t + 1)]
index = t
maxspeed = v2
while index > 0:
	a[index] = maxspeed
	index = index - 1
	maxspeed += d
answer = v1
current = v1
index = 2
done = False
while index <= t and (not done):
	if current + d <= a[index]:
		current = current + d
		answer = answer + current
		index = index + 1
	else:
		current = a[index]
		answer = answer + current
		index = index + 1
		done = True
while index <= t:
	current = current - d
	answer = answer + current
	index = index + 1
print(answer)


(a, b, c, d) = map(int, input().split() + input().split())
e = 0
for i in range(c):
	if a > b:
		(a, b) = (b, a)
	e += a
	a += d
print(e)


def solve(v1, v2, t, d):
	cache = {}

	def calc_max(cur_v, remain_t):
		if remain_t == 0:
			return 0
		cur_dist = float('-inf')
		if remain_t == 1 and cur_v != v2:
			return cur_dist
		cache_key = (cur_v, remain_t)
		if cache_key in cache:
			return cache[cache_key]
		max_v = min(cur_v + d, v2 + d * remain_t)
		min_v = max(0, max(cur_v - d, v2 - d * remain_t))
		for v in range(max_v, min_v - 1, -1):
			cur_dist = max(cur_dist, calc_max(v, remain_t - 1))
		cache[cache_key] = cur_v + cur_dist
		return cur_v + cur_dist
	return calc_max(v1, t)

def main():
	(v1, v2) = map(int, input().strip().split())
	(t, d) = map(int, input().strip().split())
	print(solve(v1, v2, t, d))
main()


def main():
	(v1, v2) = (int(i) for i in input().split())
	(t, d) = (int(i) for i in input().split())
	res = 0
	for i in range(t):
		res += min(v1 + d * i, v2 + d * (t - i - 1))
	print(res)
main()


(v1, v2) = map(int, input().split(' '))
(a, b) = map(int, input().split(' '))
ans = 0
z = [v1]
x = [v2]
for i in range(a - 2):
	z.append(z[-1] + b)
	x.append(x[-1] + b)
x.append(v1)
z.append(v2)
x.reverse()
for i in range(a):
	ans += min(x[i], z[i])
print(ans)


def check(k, v, v2, t, d):
	if (t - k - 1) * d >= abs(v2 - v):
		return 1
	else:
		return 0
(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
(v1, v2) = (min(v1, v2), max(v1, v2))
(k, v, s) = (0, v1, v1)
if d == 0:
	print(v1 * t)
else:
	while check(k, v, v2, t, d) == 1:
		k += 1
		v += d
		s += v
	s -= v
	k -= 1
	v = (t - k - 2) * d + v2
	while v > v2:
		s += v
		v -= d
	if v == v2:
		s += v
	if v != v2:
		v += d
		s -= v
		s += v2
	print(s)


def inum2(num):
	if num > int(num):
		return int(num) + 1
	else:
		return int(num)
(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
nowv = v1
s = 0
i = 1
if d > 0:
	while t + 1 > i:
		s += nowv
		nowv = min(nowv + d, v2 + (t - i - 1) * d)
		i += 1
	print(s)
else:
	print(v1 * t)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
dp = [[float('-inf') for x in range(1020)] for y in range(t + 1)]
dp[0][v1] = 0
for i in range(t):
	for j in range(1000):
		for k in range(-d, d + 1):
			if j + k >= 0:
				dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + j)
print(dp[t - 1][v2] + v2)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
ans = 0
for i in range(t):
	if v1 > v2:
		(v1, v2) = (v2, v1)
	ans += v1
	v1 += d
print(ans)


(v1, v2) = sorted(list(map(int, input().split())))
(t, d) = map(int, input().split())
s = v1 + v2
for i in range(1, t - 1):
	s += min(v1 + d * i, v2 + d * (t - i - 1))
print(s)


(u, v) = (int(i) for i in input().split())
(t, d) = (int(i) for i in input().split())
dist = 0
for i in range(t):
	dist += min(u + d * i, v + d * (t - i - 1))
print(dist)


import sys
(v1, v2) = map(int, sys.stdin.readline().strip().split(' '))
(t, d) = map(int, sys.stdin.readline().strip().split(' '))
ans = 0
v = v1
for i in range(0, t):
	ans += v
	max_v = v2 + d * (t - i - 2)
	if v > max_v:
		v = max_v
	elif v + d > max_v:
		v = max_v
	else:
		v = v + d
print(ans)


(start, end) = map(int, input().split())
(time, maxDelta) = map(int, input().split())
distance = 0
for x in range(time):
	distance += min(start + maxDelta * x, end + maxDelta * (time - 1 - x))
print(distance)


first_line_input = input().split()
second_line_input = input().split()
v1 = int(first_line_input[0])
v2 = int(first_line_input[1])
t = int(second_line_input[0])
d = int(second_line_input[1])
max = v1
step = 2
num = v1
while step < t:
	if v2 + (t - step) * d > num + d:
		num += d
	else:
		num += v2 + (t - step) * d - num
	max += num
	step += 1
max += v2
print(max)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
ans = 0
l = [0] * t
l[0] = v1
l[-1] = v2
i = 1
j = t - 2
while 1:
	if i < j:
		l[i] = l[i - 1] + d
		l[j] = l[j + 1] + d
	elif i == j:
		l[i] = l[i - 1] + d
	elif i > j:
		break
	i += 1
	j -= 1
for i in range(1, t):
	if l[i] - l[i - 1] > d:
		l[i] = l[i - 1] + d
for i in range(t - 2, -1, -1):
	if l[i] - l[i + 1] > d:
		l[i] = l[i + 1] + d
print(sum(l))


(v1, v2) = [int(next_token) for next_token in input().split()]
(t, d) = [int(next_token) for next_token in input().split()]
ans = v1 + v2
(v1, v2) = (min(v1, v2), max(v1, v2))
t -= 2
while t > 0:
	if v2 - v1 > d:
		v1 += d
		ans += v1
		t -= 1
		continue
	v1 += d
	(v1, v2) = (v2, v1)
	ans += v2
	t -= 1
print(ans)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
a = [0] * t
a[0] = v1
a[t - 1] = v2
for i in range(1, t - 1):
	a[i] = a[i - 1] + d
k = t - 1
while abs(a[k] - a[k - 1]) > d:
	if a[k] - a[k - 1] > 0:
		a[k - 1] = a[k] - d
	else:
		a[k - 1] = a[k] + d
	k -= 1
print(sum(a))


v = input().split()
p = input().split()
v1 = int(v[0])
v2 = int(v[1])
T = int(p[0])
d = int(p[1])
x = abs(v1 - v2)
t = T - 2
sum = v1 + v2
if v1 <= v2:

	def check(v1, v2, d, t):
		a = []
		z = d
		for i in range(v1):
			if v1 + z - v2 > d * t + d:
				z -= 1
			else:
				a.append(z)
		return int(a[0])
	for i in range(t):
		if v1 + d - v2 <= d * (t - (i + 1)) + d:
			sum += v1 + d
			v1 = v1 + d
		else:
			sum += v1 + check(v1, v2, d, t - (i + 1))
else:
	(v1, v2) = (v2, v1)

	def check(v1, v2, d, t):
		a = []
		z = d
		for i in range(v1):
			if v1 + z - v2 > d * t + d:
				z -= 1
			else:
				a.append(z)
		return int(a[0])
	for i in range(t):
		if v1 + d - v2 <= d * (t - (i + 1)) + d:
			sum += v1 + d
			v1 = v1 + d
		else:
			sum += v1 + check(v1, v2, d, t - (i + 1))
print(sum)


(v1, v2) = list(map(int, input().rstrip().split()))
(t, d) = list(map(int, input().rstrip().split()))
l = 0
for i in range(t):
	l += min(v1 + d * i, v2 + d * (t - i - 1))
print(l)


from sys import stdin
input = stdin.readline
(v1, v2) = list(map(int, input().split()))
(t, d) = list(map(int, input().split()))
dp = [0] * t
for i in range(t):
	dp[i] = min(v1 + d * i, v2 + d * (t - 1 - i))
print(sum(dp))


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
v = v1
ans = v1
for i in range(1, t):
	delta = v2 - v + (t - i - 1) * d
	v += min(d, delta)
	ans += v
print(ans)


(v1, v2) = list(map(int, input().split()))
(t, d) = list(map(int, input().split()))
ans = [0] * t
ans[0] = v1
ans[-1] = v2
n = t
for i in range(1, n - 1):
	if ans[-1] < ans[i - 1] + d:
		if ans[i - 1] + d - ans[-1] <= d * (n - 1 - i):
			ans[i] = ans[i - 1] + d
		else:
			ans[i] = ans[-1] + d * (n - 1 - i)
	else:
		ans[i] = ans[i - 1] + d
print(sum(ans))


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
dist = v1
v = v1
for i in range(1, t):
	v += d
	if v <= v2 + d * (t - i - 1):
		dist += v
	else:
		v = v2 + d * (t - i - 1)
		dist += (v + v2) * (t - i) / 2
		break
print(int(dist))


(a, b) = map(int, input().split())
(v1, v2) = (min(a, b), max(a, b))
(t, d) = map(int, input().split())
dist = 0
vn = v1
t -= 1
j = 0
a = 0
r1 = 0
while j < t and vn - (t - j) * d <= v2:
	vn += d
	j += 1
	a = 1
	r1 += 1
vd = vn
r1 -= a
x = 0
b = t > r1 + 1
while x < d and vd - (t - j) * d > v2:
	vd -= 1
	x += 1
dist = (r1 + 1) * v1 + (r1 + 1) * r1 * d // 2 + (t - j + 1) * v2 + (t - j) * (t - j + 1) * d // 2
if t == 1:
	dist = v1 + v2
if d == 0:
	dist = v1 * (t + 1)
print(dist)


(v1, v2) = map(int, input().strip().split())
(t, d) = map(int, input().strip().split())
speeds = [0] * t
speeds[0] = v1
speeds[t - 1] = v2
for i in range(1, t - 1):
	speeds[i] = min(v1 + d * i, v2 + d * (t - i - 1))
print(sum(speeds))


inp = input()
inp = inp.split()
v1 = int(inp[0])
v2 = int(inp[1])
inp = input()
inp = inp.split()
t = int(inp[0])
d = int(inp[1])
ans = v1
t -= 1
while t > 0:
	for i in range(-d, d + 1):
		v = v1 - i
		if d * (t - 1) >= abs(v2 - v):
			ans += v
			v1 = v
			t -= 1
			break
print(ans)


import sys
import math
from collections import defaultdict
import itertools
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	sys.stdout.write(str(ans) + '\n')

def solve(v1, v2, t, d):
	curTime = 1
	totalDistance = 0
	curSpeed = v1
	while curTime <= t:
		totalDistance += curSpeed
		for acc in range(d, -d - 1, -1):
			if curSpeed + acc - d * (t - (curTime + 1)) <= v2:
				curSpeed += acc
				break
		curTime += 1
	return totalDistance

def readinput():
	(v1, v2) = getInts()
	(t, d) = getInts()
	printOutput(solve(v1, v2, t, d))
readinput()


(startSpeed, endSpeed) = [int(x) for x in input().split()]
(seconds, maxChange) = [int(x) for x in input().split()]
speedUp = [startSpeed + maxChange * x for x in range(seconds)]
slowDown = list(reversed([endSpeed + maxChange * x for x in range(seconds)]))
speed = [min(speedUp[x], slowDown[x]) for x in range(seconds)]
print(sum(speed))


(i_speed, f_speed) = input().split(' ')
(time, transition) = input().split(' ')
i_speed = int(i_speed)
f_speed = int(f_speed)
time = int(time)
transition = int(transition)
path = [i_speed] * time
for i in range(1, len(path)):
	path[i] += transition * i
	while path[i] > f_speed + transition * (len(path) - i - 1):
		path[i] -= 1
print(sum(path))


v = [int(x) for x in input().split(' ')]
(t, d) = [int(x) for x in input().split(' ')]
s = 0
v.sort()
s += v[0]
for i in range(1, t):
	if v[0] - v[-1] > (t - i - 2) * d:
		v[0] = (t - i - 1) * d + v[-1]
	else:
		v[0] += d
	s += v[0]
print(s)


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
if v1 > v2:
	z = v1
	v1 = v2
	v2 = z
ans = v1
cur = v1
for i in range(2, t + 1):
	temp = (t - i) * d
	f = 0
	for j in range(d, -1, -1):
		if abs(cur + j - v2) <= temp:
			f = 1
			cur += j
			ans += cur
			break
	if f == 0:
		req = cur - v2
		z = i
		if req % d != 0:
			cur -= req % d
			z = i + 1
			ans += cur
		for j in range(z, t + 1):
			cur -= d
			if cur >= v2:
				ans += cur
			else:
				ans += v2
		break
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	(v1, v2) = map(int, input().split())
	(t, d) = map(int, input().split())
	if v2 < v1:
		(v1, v2) = (v2, v1)
	ans = v1 + v2
	i = 1
	sec_distance = v1 + d
	while sec_distance < v2 + d * (t - 2 - i):
		sec_distance = v1 + d * i
		ans += sec_distance
		i += 1
	for j in range(t - 2, i - 1, -1):
		ans += v2 + d * (t - 1 - j)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(v1, v2) = map(int, input().split())
(t, d) = map(int, input().split())
p = v1 + v2
for i in range(2, t):
	v1 = min(v1 + d, v2 + (t - i) * d)
	p += v1
print(p)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	(v1, v2) = get_ints()
	(t, d) = get_ints()
	dp = [0] * (t + 1)
	dp[1] = v1
	dp[-1] = v2
	for i in range(2, t):
		dp[i] = min(d + dp[i - 1], dp[-1] + d * (t - i))
	print(sum(dp))
main()