思路:

利用容斥原理,首先考虑总的情况,即求x+y+z<=l有多少种情况,即求x+y+z=i(i<=l)有多少种情况。

是组合数C(i+2,2),因为相当于刻度从1开始然后长度为i的尺子拆成三份有多少种情况,也就是在不同的位置切两刀,然后考虑,可以有最多两份长度为0,也就是说在0到1之间可以切两刀于是总共就是i+2个可以切的位置中选择两个。

然后进行容斥,把不符合形成三角形条件的情况(两边之和小于等于第三边)减去,枚举a,b,c分别做第三条边时的情况(设为a),先把它加成最大第三边,用去长度i(i>=0)。然后枚举它长度是a+i, a+i+1,....a+L的情况。此时假设当前用去长度i,则最大可用剩余长度是min( L - i, a + i - b - c),然后在这些长度里面任意分配。


#include<bits\stdc++.h>
using namespace std;
#define LL long long
LL cal(LL a,LL b,LL c,LL l)
{
     LL ans = 0;
	 for(LL i = max(b+c-a,0LL);i<=l;i++)
	 {
		 LL x = min(l-i,a+i-b-c);
		 ans+=(x+2)*(x+1)/2;
	 }
	 return ans;
}
int main()
{
     LL a,b,c,l;
	 LL sum = 0;
	 cin >> a >> b >> c >> l;
	 for(LL i = 0;i<=l;i++)
		 sum+=(i+2)*(i+1)/2;
	 sum-=cal(a,b,c,l);
	 sum-=cal(b,a,c,l);
	 sum-=cal(c,a,b,l);
	 cout << sum << endl;
}





C. Lengthening Sticks



time limit per test



memory limit per test



input



output



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

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



4 integers a, b, c, l (1 ≤ a, b, c ≤ 3·105, 0 ≤ l ≤ 3·105).



Output



l



Examples



input



1 1 1 2



output



4



input



1 2 3 1



output



2



input



10 2 1 7



output



0



Note



1

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.