You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the length of any stick.

Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.


-----Input-----

The single line contains 4 integers a, b, c, l (1 ≤ a, b, c ≤ 3·10^5, 0 ≤ l ≤ 3·10^5).


-----Output-----

Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most l centimeters, so that you can make a non-degenerate triangle from it.


-----Examples-----
Input
1 1 1 2

Output
4

Input
1 2 3 1

Output
2

Input
10 2 1 7

Output
0



-----Note-----

In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter.

In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.

Difficulty: HARD
Tags: Mathematics

Combinatorics

Implementation

Starter code:

Solutions:
(a, b, c, l) = list(map(int, input().split()))
cnt = (l + 3) * (l + 2) * (l + 1) // 3
for i in (a, b, c):
	s = 2 * i - a - b - c
	for x in range(max(0, -s), l + 1):
		m = min(s + x, l - x)
		cnt -= (m + 1) * (m + 2)
print(cnt // 2)


(a, b, c, l) = map(int, input().split())
ans = (l + 3) * (l + 2) * (l + 1) // 3
for z in (a, b, c):
	s = 2 * z - a - b - c
	for x in range(max(0, -s), l + 1):
		m = min(s + x, l - x)
		ans -= (m + 1) * (m + 2)
print(ans // 2)


(a, b, c, d) = map(int, input().split(' '))
ans = -(d + 1) * (d + 2) * (d + 3) // 6
for l1 in range(0, d + 1):
	minx = min(d - l1, a - b - c + l1)
	if minx < 0:
		continue
	else:
		ans += (minx + 1) * (minx + 2) // 2
(a, b, c) = (b, c, a)
for l1 in range(0, d + 1):
	minx = min(d - l1, a - b - c + l1)
	if minx < 0:
		continue
	else:
		ans += (minx + 1) * (minx + 2) // 2
(a, b, c) = (b, c, a)
for l1 in range(0, d + 1):
	minx = min(d - l1, a - b - c + l1)
	if minx < 0:
		continue
	else:
		ans += (minx + 1) * (minx + 2) // 2
print(-ans)


def Solve(a, b, c, l):
	delta = a - b - c
	if delta < 0:
		return 0
	k = min(l, delta) + 1
	return k * (k + 1) // 2
(a, b, c, l) = list(map(int, input().split()))
ans = (l + 3) * (l + 2) * (l + 1) // 6
for d in range(l + 1):
	ans -= Solve(a + d, b, c, l - d) + Solve(b + d, a, c, l - d) + Solve(c + d, a, b, l - d)
print(ans)


__author__ = 'nobik'

def count(a, b, c, x):
	if a < b + c:
		return 0
	value = min(x, a - b - c)
	return (value + 1) * (value + 2) // 2
(a, b, c, l) = list(map(int, input().split()))
ans = (l + 1) * (l + 2) * (l + 3) // 6
for i in range(l + 1):
	ans -= count(a + i, b, c, l - i)
	ans -= count(b + i, a, c, l - i)
	ans -= count(c + i, a, b, l - i)
print(ans)


p = list(map(int, input().split()))
l = p.pop()
n = (l + 1) * (l + 2) * (l + 3) // 6
s = sum(p)
for q in p:
	t = 2 * q - s
	for d in range(l + 1):
		k = min(t + d, l - d) + 1
		if k > 0:
			n -= k * k + k >> 1
print(n)


def f(a, b, c, l):
	if a < b + c:
		return 0
	else:
		c = min(l, a - b - c)
		return (c + 1) * (c + 2) / 2
(a, b, c, l) = map(int, input().split())
z = (l + 1) * (l + 2) * (l + 3) / 6
i = 0
while i <= l:
	z -= f(a + i, b, c, l - i) + f(b + i, c, a, l - i) + f(c + i, a, b, l - i)
	i += 1
print(int(z))


def solve(a, b, c):
	ans = 0
	for da in range(max(0, b + c - a), l + 1):
		x = min(a - b - c + da, l - da)
		ans += (x + 1) * (x + 2) // 2
	return ans
(a, b, c, l) = list(map(int, input().split()))
print((l + 1) * (l + 2) * (l + 3) // 6 - solve(a, b, c) - solve(b, a, c) - solve(c, a, b))


def f(a, b, c, l):
	k = min(l, a - b - c)
	return 0 if a < b + c else (k + 1) * (k + 2) // 2
solve = lambda i: f(a + i, b, c, l - i) + f(b + i, c, a, l - i) + f(c + i, a, b, l - i)
(a, b, c, l) = map(int, input().split())
ans = (l + 1) * (l + 2) * (l + 3) // 6 - sum((solve(i) for i in range(l + 1)))
print(ans)