Problem:
 Score : 200 points    Problem Statement You are given two integers K and S . Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K . How many different assignments of values to X, Y and Z are there such that X + Y + Z = S ?      Constraints  2≤K≤2500   0≤S≤3K   K and S are integers.         Input The input is given from Standard Input in the following format:  K  S       Output Print the number of the triples of X, Y and Z that satisfy the condition.        Sample Input 1 2 2      Sample Output 1 6  There are six triples of X, Y and Z that satisfy the condition:   X = 0, Y = 0, Z = 2   X = 0, Y = 2, Z = 0   X = 2, Y = 0, Z = 0   X = 0, Y = 1, Z = 1   X = 1, Y = 0, Z = 1   X = 1, Y = 1, Z = 0        Sample Input 2 5 15      Sample Output 2 1  The maximum value of X + Y + Z is 15 , achieved by one triple of X, Y and Z .

Solution (Python):

K,N=map(int,raw_input().split())
count=0
for i in range(K+1):
	for j in range(K+1):
		
		if 0<=(N-(i+j))<=K:
			count+=1
print count

Solution (Python):
K,S = map(int, raw_input().split())
ans = 0
for x in xrange(0,K+1):
    for y in xrange(0,K+1):
        if x + y <= S and S - (x+y) <= K: 
            ans += 1
print ans

Solution (Python):
K, S = map(int, input().split(" "))
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if 0 <= z <= K:
            cnt += 1
print(cnt)

Solution (Python):


k,s=map(int,raw_input().split())
cnt=0
for x in xrange(k+1):
 for y in xrange(k+1):
  z=s-x-y
  if z>=0 and z<=k:
   cnt+=1
print cnt

Solution (Python):
k,s=map(int,input().split())
total=0
for x in range(0,min(s,k)+1):
    for y in range(0,min(s-x,k)+1):
        if 0 <= s-x-y and s-x-y <= k:
            total+=1
print(total)

Solution (Python):

 
k, s = list(map(int, input().split()))
 
ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - (i + j) <= k: ans += 1
 
print(ans)

Solution (Python):
K,S=map(int,input().split())
ans=0

for x in range(K+1):
    for y in range(K+1):
        z=S-x-y
        if z>=0 and z<=K:
            ans += 1
print(ans)

Solution (Python):

 
K_MAX = 2500
k, s = list(map(int, input().split()))
 
smz = [False] * (2 * K_MAX + 1)
 
for i in range(k + 1):
    if 0 <= s - i <= 2 * k: smz[s - i] = True
 
cnt = 0
for i in range(k + 1):
    for j in range(k + 1):
        if smz[i + j]:
            cnt += 1
 
print(cnt)

Solution (Python):
from sys import stdin
k,s = map(int,stdin.readline().split())
ans = 0
for i in xrange(k+1):
 for j in xrange(k+1):
  x = s - i - j
  if x>=0 and x<=k:
   ans+=1
print ans

Solution (Python):
k, s = map(int, input().split())

ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k :
            ans += 1

print(ans)

Solution (Python):
k,s = map(int,input().split())
ans = 0
for x in range(0,k+1):
  for y in range(0,k+1):
    if s-x-y<=k and s-x-y>=0:
      ans+=1

print(ans)

Solution (Python):
K, S = map(int, raw_input().split(" "))

res = 0
for X in xrange(K + 1):
    for Y in xrange(K + 1):
        Z = S - X - Y
        if 0 <= Z <= K:
            res += 1

print res

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    k,s = LI()
    r = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s-x-y
            if z > k:
                continue
            if z < 0:
                break
            r += 1

    return r


print(main())

Solution (Python):
K, S = map(int, raw_input().split())
ans = 0
for X in xrange(K+1):
    for Y in xrange(K+1):
        Z = S - X - Y
        if 0 <= Z <= K:
            ans += 1
print ans

Solution (Python):
K, S = map(int, input().split(" "))
print(sum([max(0, min(K, S-X) - max(0, S-X-K) + 1) for X in range(min(K, S)+1)]))

Solution (Python):
k, s = map(int, input().split())

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if s - x - y >= 0 and s - x - y <= k:
                count += 1
print(count)

Solution (Python):
k,s=map(int,raw_input().split())
c=0
for x in xrange(k+1):
    for y in xrange(k+1):
        if 0<=s-x-y and s-x-y<=k: c+=1
print c

Solution (Python):
def main():
    K, S = map(int, input().split())
    ans = 0
    for x in range(min(K, S) + 1):
        for y in range(min(K, S-x) + 1):
            if S-x-y <= K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):



k, s = map(int, input().split())

ans = 0

for i in range(k+1):
    for j in range(k+1):
        z = s-i-j
        if 0 <= z and z <=k:
            ans = ans+1

print(ans)

Solution (Python):
K,S = map(int, input().split(" "))

combo_count = 0
for X in range(max(0, S-K*2), min(S//3, K)+1):
    S2 = S-X
    for Y in range(max(X,S2-K), min(S2//2, K)+1):
        Z = S2 - Y
        if X == Y and Y == Z:
            combo_count += 1
        elif X == Y or Y == Z:
            combo_count += 3
        else:
            combo_count += 6
print(combo_count)

Solution (Python):
K, S = map(int, input().split())
n = 0
for x in range(K + 1):
    for y in range(K + 1):
        if (x + y) > S:
            break
        elif (S - (x + y)) <= K:
            n += 1
print(str(n))

Solution (Python):

K, S = map(int, input().split())
wariate = 0

for x in range(0, K + 1):
    for y in range(0, K + 1):
        z = S - (x + y)
        if 0 <= z <= K:
            wariate += 1

print(wariate)

Solution (Python):
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)

Solution (Python):


k, s = list(map(int, input().split()))
z = min(k,s)
y = min(k,s-z)
xmax = min(y + z,k)
x = s-z-y
count = 0

while x <= xmax and z >= 0 :
    z0 = z
    y0 = y
    while z >= 0 and y<= k:
        z -= 1
        y += 1
        count+=1
    z = z0+1
    y = y0-1
    while y >= 0 and z<= k:
        y -= 1
        z += 1
        count+=1
    z = z0-1
    y = y0
    x +=1
print(count)

Solution (Python):
k, s = map(int, input().split())

def count(k, s):
	x = 0
	res = 0
	for x in range(k+1):
		s_ = s - x
		if s_ < 0:
			return res
		for y in range(k+1):
			s__ = s_ - y
			if 0<= s__ <= k:
				res += 1
	return res

print(count(k, s))

Solution (Python):
K, S= list(map(int,input().split()))

ans=0
for i in range(K+1):
        M=min(S-i,K)
        m=max(0,S-i-K)
        if M>=m:
                ans += M-m+1

print(ans)

Solution (Python):
k, s = map(int, input().split())
cnt = 0

for i in range(k + 1):
    t = s - i
    if t >= 0:
        cnt += max(0, (t + 1) - 2 * (max(0, t - k)))
print(cnt)

Solution (Python):
import itertools
k,s = map(int,input().split())
count = 0
for i,j in itertools.product(range(k+1),range(k+1)):
	d = s -(i+j)
	if 0 <= d <= k:
		count += 1
		
print(count)

Solution (Python):
import sys

K,S = map(int, raw_input().split())
ans=0
for X in range(0,K+1):
 for Y in range(0,K+1):
  Z=S-X-Y
  if(0<=Z and Z<=K):
   ans=ans+1
print ans

Solution (Python):
k, s = list(map(int, input().split()))
count = int(0)

for x in range(k+1)[::-1]:
    yz = s - x
    if yz > k*2:
        break
    for y in range(k+1)[::-1]:
        z = yz - y
        if x >= y >= z >= 0:
            if len({x, y, z}) == 1:
                count += 1
            elif len({x, y, z}) == 2:
                count += 3
            else:
                count += 6

print(count)

Solution (Python):
def count(i, j, k):
    if i == j and j == k:
        return 1
    elif i == j or j == k or i == k:
        return 3
    else:
        return 6

def solve(K, S):
    ans = 0
    for i in range(K, -1, -1):
        for j in range(i, -1, -1):
            k = S - (i + j)
            if k >= 0 and k <= j:
                ans += count(i, j, S - (i + j))
    return ans

k, s = tuple(int(x) for x in input().split())
print(solve(k, s))

Solution (Python):
K, S = map(int, input().split())

cnt = 0
for x in range(0,K+1):
	if S-x < 0:
		break
	for y in range(0, min(K,S-x)+1):
		z = S-x-y
		if z>-1:
			if z < K+1:
				cnt += 1
		else:
			break

print(cnt)

Solution (Python):
K,S = map(int,input().split())

def nHr(n):
    return (n+2)*(n+1)//2
whole = nHr(S)
oneGreater = twoGreater = threeGreater = 0

if S >= K+1:
    oneGreater = nHr(S-(K+1))
    if S >= 2*(K+1):
        twoGreater = nHr(S-2*(K+1))
        """
        if S >= 3*(K+1):
            threeGreater = nHr(S-3*(K+1))
        """

ans = whole -(oneGreater*3 - twoGreater*3 + threeGreater)
print(ans)

Solution (Python):
k,s=map(int,raw_input().split())
cnt=0
for x in range(k+1):
    if 0<=(s-x)<k:cnt+=(s-x+1)
    if k<=(s-x)<=2*k:cnt+=(2*k-s+x+1)
print cnt

Solution (Python):
K, S = list(map(int, input().split()))

cnt = 0
for x in range(K + 1):
    if S - x > K:
        y_max = K + 1
    else:
        y_max = S - x + 1

    if S - x > 2 * K:
        continue
    else:
        
        pass

    for y in range(y_max):

        if S - (x + y) <= K:
            cnt += 1
print(cnt)

Solution (Python):

K, S = map(int, input().split())
wariate = 0

for x in range(0, K + 1):
    if S - x <= K:
        wariate += max(S - x + 1, 0)
    else:
        wariate += max(0, 2 * K - (S - x) + 1)

print(wariate)

Solution (Python):
K, S = map(int, input().strip().split(' '))
cnt = 0
if S < K:
	for X in range(0, S+1):
		cnt += (S-X+1)
else:
	for X in range(0, K+1):
		if (S-X) <= (2*K):
			if (S-X) < K:
				cnt += (S-X+1)
			elif (S-X) > K:
				Z = S-X-K
				cnt += (K-Z+1)
			else:
				cnt += (K+1)
 
print(cnt)

Solution (Python):
[k, s] = [int(s) for s in input().split(' ')]
count = 0
for x in range(max(s-2*k, 0), min(k,s)+1):
    count += min(s-x, 2*k-(s-x)) + 1

print(count)

Solution (Python):

k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(x, k+1):
        z = s - x - y
        if x <= y <= z <= k:
            ans += [ None, 1, 3, 6 ][ len(set([ x, y, z ])) ]
print(ans)

Solution (Python):
k,s = input().strip().split(' ')
k,s = [int(k),int(s)]
cnt = 0
for i in range(k+1):
	if i>s:	
		break;
	for j in range(k+1):
		if i+j>s:
			break;
		elif s-i-j<=k:
			cnt+=1
print (cnt)

Solution (Python):
K, S = list(map(int, input().split()))

a = 0
for i in range(K + 1):
    r = S - i
    if i <= S and r <= K * 2:
        t = (r + 1) - max(0, r - K) * 2
        a += t

print(a)

Solution (Python):
k,s=map(int,raw_input().split())
ans=0
for i in range(k+1):
 for j in range(k+1):
  if 0 <= s-i-j<=k:ans+=1
print ans

Solution (Python):
import sys
inp=sys.stdin.readline()
K,S=map(lambda x: int(x), inp.split(' '))
K,S

if S<=K:
    ret=(S+1)*(S+2)/2
elif S>=K*2:
    S=K*3-S
    ret=(S+1)*(S+2)/2
else:
    ret=(S+1)*(S+2)/2-(S-K)*(S-K+1)/2*3
print(int(ret))

Solution (Python):
def count(k, s):
  h = min(k, s)
  l =  max(s - k, 0)
  return max(h - l + 1, 0)

k, s = map(int, input().split())
print(sum([count(k, s - x) for x in range(min(k, s)+1)]))

Solution (Python):
[K, S] = raw_input().split()
K = int(K)
S = int(S)

res = 0
for X in xrange(K+1):
	for Y in xrange(K+1):
		res += 0 <= S - X - Y <= K
		
print res

Solution (Python):

K,S = map( int, input().split() )

counter = 0


for x in range(K,-1,-1):
    for y in range(min(S-x,K),-1,-1):
        if 0<=(S-x-y)<=K:
            counter += 1


print(counter)

Solution (Python):

[K, S] = raw_input().split()
K = int(K)
S = int(S)

res = 0
for X in xrange(K+1):
	for Y in xrange(K+1):
		Z = S - X - Y
		if 0 <= Z <= K:
			res+=1
		
print res

Solution (Python):


import sys

def main(argv):
    for line in sys.stdin:
        k, s = line.rstrip("\n").split(" ")
        k = int(k)
        s = int(s)
        counter = 0
        for x in xrange(0, k + 1):
            for y in xrange(x, k + 1):
                if x + y <= s:
                    z = s - x - y
                    if z >= y and z <= k:
                        if (x+y+z) == s:
                            if x == y and y == z:
                                counter += 1
                            elif x == y or y == z or x == z:
                                counter += 3
                            else: 
                                counter += 6
        print counter

if __name__ == "__main__":
    main(sys.argv)

Solution (Python):
from sys import stdin

k, s = map(int, stdin.readline().split())

result = 0


def get_variants(target, maximum):
    result = 0
    for x in range(maximum, -1, -1):
        y = target - x
        if 0 <= y <= maximum:
            result += 1
    return result

for z in range(k+1):
    variants = get_variants(s - z, k)
    result += variants

print(result)

Solution (Python):
k,s=[int(i) for i in input().split()]
ans=0
chk=set([])
for i in range(k+1):
    for j in range(i,k+1):
        tmp=s-i-j
        if 0<=tmp<=k and i<=j<=tmp:
            if i==j==tmp:
                ans+=1
            elif i==j or i==tmp or j==tmp:
                ans+=3
            else:
                ans+=6
print(ans)

Solution (Python):
k, s = map(int, raw_input().split())
ans = 0
for x in xrange(0, k+1):
    for y in xrange(0, min(k, s-x)+1):
        z = s-x-y
        if 0 <= z <= k:
            ans += 1
print ans

Solution (Python):
[K,S]=[int(i) for i in input().split()]
c=0
for i in range(K+1):
 a=S-i
 for i in range(K+1):
  if a-i>K or a-i<0:
    c+=1
print((K+1)**2-c)

Solution (Python):
k,s=map(int,input().split())
res=0
for x in range(k+1):
    t=s-x
    if t<0:
        continue
    ymin=max(t-k,0)
    ymax=min(t,k)
    res+=max(ymax-ymin+1,0)
print(res)

Solution (Python):
(k, s) = [int(i) for i in input().split(" ")]
total = 0
for x in range(0, k + 1):
    rem = s - x
    if rem < 0:
        break
    for y in range(0, k + 1):
        rem = s - x - y
        if rem < 0:
            break
        if rem <= k:
            total = total + 1

print(total)

Solution (Python):
K,S = map(int,input().split())
ans = 0
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y
    if Z < 0: continue
    if Z <= K : ans += 1
print(ans)

Solution (Python):
k, s = map(int, input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            cnt += 1
print(cnt)

Solution (Python):



def func(k, n):
    if n <= k:
        return n + 1
    elif n <= 2 * k:
        return 2 * k - n + 1
    else:
        return 0

K,S = map(int,input().split())
ans = 0
for a in range(K+1):
    if S-a >= 0:
        ans += func(K, S-a)
print(ans)

Solution (Python):
def main():
    K,S = map(int,input().split())

    count = 0
    for x in range(max(0,S - 2*K), K + 1):
        for y in range(max(0,S - x - K), K + 1):
            if 0 <= S - x - y <= K:
                count += 1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
k, s = map(int, input().split())

ans = 0

for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if z in range(k + 1):
            ans += 1

print(ans)

Solution (Python):
K,S = map(int, input().split())

ans = 0
for i in range(K+1):
	if i > S:
		break
	if i + 2*K < S:
		continue
	for j in range(K+1):
		t = S - i - j
		if 0 <= t and t <= K:
			ans += 1 
print(ans)

Solution (Python):
K, S = map(int, input().split())
count = 0
x_min = max(0, S-K*2)
x_max = min(K, S)
for x in range(x_min, x_max+1):
	rest = S-x
	if rest<K:
		count = count+rest+1
	else:
		count = count+K*2-rest+1
print(count)

Solution (Python):
k, s = [int(x) for x in raw_input().split()]

ans = 0
for x in range(k + 1):
    yz = s - x
    ans += max(0, min(yz + 1, 2 * k - yz + 1))

print ans

Solution (Python):
k, s = map(int, raw_input().split())
ans = 0
for x in xrange(k + 1):
    for y in xrange(k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        ans += 1
print ans

Solution (Python):
K, S = map(int, input().split())
ans = 0
for x in range(min(K,S)+1):
	for y in range(min(K,S)+1):
		if 0 <= S - x - y <= K:
			ans += 1
print(ans)

Solution (Python):
k, s = [int(i) for i in input().split()]
result = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            result += 1
print(result)

Solution (Python):
k,s=map(int,raw_input().split())
ans=0
for x in xrange(k+1):
    for y in xrange(k+1):
        if 0<=s-x-y<=k:
            ans+=1
print(ans)

Solution (Python):
k, s = map(int, raw_input().split())
ans = 0
for x in xrange(k+1):
    for y in xrange(k+1):
        z = s - x - y
        if 0 <= z <= k:
            ans += 1
print ans

Solution (Python):


import sys
stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()

def main():
    ct = 0
    k,s = na()
    for i in range(0, k+1):
        for j in range(0, k+1):
            if 0 <= s-(i+j) <= k:
                ct += 1
    print(ct)
    pass


if __name__ == '__main__':
    main()