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.

Difficulty: interview

Starter code:

Solutions:
v1, v2 = list(map(int, input().split()))
t, d = list(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))


ninf = -500000

u, v = list(map(int, input().split(' ')))
t, d = list(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])


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()

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 = list(map(int, input().strip().split()))
    t, d = list(map(int, input().strip().split()))
    print(solve(v1, v2, t, d))

main()


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 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))


#!/usr/bin/env python

v1, v2 = list(map(int, input().split(' ')))
t, d   = list(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)


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))

v1, v2 = list(map(int, input().split()))
t, d = list(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)


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 = [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)

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)


def inum2(num):
    if num > int(num):
        return int(num) + 1
    else:
        return int(num)
v1, v2 = list(map(int,input().split()))
t, d = list(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)


__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
        #print(v1)
    else:
        while ((v1+z) - (t-i)*d) > v2:
            z -= 1
        v1 = v1 + z
        sum += v1
        #//print(v1, 'df')
        z  = d
print(sum+v2)

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)

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)


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()))
print(sum(min(v1 + d * i, v2 + d * (t - i - 1)) for i in range(t)))


#sry...

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] = [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 = list(map(int, input().split(' ')))
t, d = list(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))
#print(l1, l2)

split = 0
for i in range(t):
    if l2[i] <= l1[i]:
        split = i
        break

l = l1[:split] + l2[split:]
#print(l)
print(sum(l))



v1, v2 = [int(c) for c in input().split()]
t, d = [int(c) for c in input().split()]


dist = v1   # distance after the first interval [0, 1)
i = 1       # interval

# check the intervals [i, i+1)
while(i <= t-2):
    dist += min(v1 + i*d, (v2 + (t-1)*d) - i*d)
    i += 1

dist += v2  # last interval [t-1, t)
print(dist)

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)


V1,V2=list(map(int,input().split()))
T,D=list(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)