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, s = map(int, input().split())
ans = 0
for i in range(k + 1):
    for j in range(i + 1):
        l = s - (i + j)
        if 0 <= l <= k and l <= j <= i:
            if i == j == l:
                ans += 1
            elif i == j or j == l or l == i:
                ans += 3
            else:
                ans += 6
print(ans)

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

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

c = 0

for X in range(K+1):
    for Y in range(K+1):
        if X+Y <= S and X+Y+K >= S:
            c += 1

print(c)

Solution (Python):

input_lines=input().split()
K = int(input_lines[0])
S = int(input_lines[1])
M=0
for i in range(K+1):
  for j in range(i,K+1):
    k =S-i-j
    if i<=j<=k<=K:
      if i==j==k:
        M+=1
      elif i==j or j==k:
        M+=3
      else:
        M+=6
print(M)

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

ans = 0

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

print(ans)

Solution (Python):
def binary_search_list(beSearched,wanted) :
    l = 0
    r = len(beSearched)

    

    while r - l >= 1 :
        s = (l + r) // 2
        
        if beSearched[s] == wanted :
            return True
        if beSearched[s] > wanted :
            r = s
        else :
            l = s + 1

    return False

K,S = (int(_) for _ in input().split())
num = [_ for _ in range(K+1)]
out = 0
for i in range(K+1):
    for j in range(i+1):
        if 0 <= S - i - j <= j :
            if i == j and j == S - i - j:
                out += 1
            elif i == j or j == S - i - j or S -i - j == i:
                out += 3
            else :
                out += 6
        
        
        
        
            
                
            
                
            
                

print(out)

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

Solution (Python):
k, s = map(int, input().split())
r = k+1
print(sum(0<= s- i//r - i%r <= k for i in range(r*r)))

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

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

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

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

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

Solution (Python):
K,S = [int(x) for x in input().split()]
cnt = 0
for i in range(K+1):
    for j in range(K+1):
        if(S-i-j>=0 and S-i-j<=K):
            cnt += 1

print(cnt)

Solution (Python):
K, S = (int(i) for i in input().split())
counter = 0

for X in range(K+1):
	for Y in range(K+1):
		Z = S - (X+Y)

		if 0 <= Z <= K:
			counter += 1

print(counter)

Solution (Python):



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

X = Y = 0
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, input().split())
ans = 0

for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <= 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 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())
count=0
for X in range(K+1) :
    for Y in range(K+1) :
       Z=S-X-Y
       if 0<=Z<=K :
           count+=1
print(count)

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

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

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 - Y - X
        if Z >= Y and Z <= K:
                
            if len(set([X, Y, Z])) == 1:
                ans += 1
            elif len(set([X, Y, Z])) == 2:
                ans += 3
            else:
                ans += 6
print(ans)

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

ans = 0
for i in range(K+1):
    S_temp = S - i
    for k in range(K+1):
        z = S_temp - k
        if 0 <= z <= 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 i in range(K + 1):
    for j in range(K + 1):
        X = i
        Y = j
        Z = S - X - Y
        if 0 <= Z and Z <= K:
            ans += 1

print(ans)

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

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

print(count)

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

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

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

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

print(count)

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

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 0 <= z <= k:
            ans += 1

print(ans)

Solution (Python):
K,S = map(int,input().split())
ans = 0
for a in range(K+1):
    for b in range(K+1):
        c = S - a - b
        if 0 <= c and c <= K:
            ans += 1
print(ans)

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

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

for i in range(k+1):
    for m in range(k+1):
        if -1 < s-(i+m)  and s-(i+m) < k+1:
            
            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())

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, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if (z >= 0) & (z <= k):
            ans += 1
print(ans)

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

cnt = 0
K += 1


'''
for x in range(K):
    for y in range(K):
        for z in range(K):
            if x + y + z == S:
                cnt += 1
'''

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

print(cnt)

Solution (Python):
k, s = (int(i) for i in input().split())

cnt = 0
for x in range(k+1):
    c = s-x
    cnt += max(min(k,c)-max(0,c-k)+1,0)

print(cnt)

Solution (Python):

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

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

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

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

print(count)

Solution (Python):
a,b=map(int,input().split());print(sum(a>=b-s-t>=0for t in range(a+1)for s in range(a+1)))

Solution (Python):
ans=0
a,b=map(int,input().split())
for s in range(a+1):
    for t in range(a+1):
        if 0<=b-s-t<=a:
            ans+=1
print(ans)

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

Solution (Python):





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

cnt = 0

for i in range(K + 1):
    
    for j in range(K + 1):
        Z = S - i - j
        if 0 <= Z and Z <= K:
            cnt += 1
print(cnt)

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

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

c=0

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

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

Solution (Python):
K,S = map(int,input().split())
ans = 0
for k in range(0,K+1):
    for i in range(0,K+1):
        if S-(k+i)<=K and S-(k+i)>=0:
            ans+=1
print(ans)

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

for X in range(0, K+1):
  for Y in range(0, K+1):
    answer += (0<=(S-X-Y)<=K)
print(answer)

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

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

print(count)

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())
m=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if z>=0 and z<=k:
            m+=1

print(m)

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

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

Solution (Python):
K,S = map(int, input().split(" "))
count=0
for a in range(K+1):
    if S<a:
        break
    for b in range(K+1):
        c=S-(a+b)
        if c==0:
            count+=1
            break
        elif c>K:
            continue
        count+=1
print(count)

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 = list(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 = map(int, input().split())
cnt = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >= 0 and z <= K:
            cnt += 1
print(cnt)

Solution (Python):
K,S=[int(z) for z in input().split(" ")]
r=0

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

print(r)

Solution (Python):
x = y = z = 0
ans = 0

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

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

Solution (Python):



def main():
    x = y = z = 0
    ans = 0

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

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


if __name__ == '__main__':
    main()

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

for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - i - j <= K:
            count += 1

print(count)

Solution (Python):

'''
問題
整数X,Y,Zがいずれも0以上K以下であって,かつX+Y+Z=Sであるような(X,Y,Z)の組はいくつあるか？

考察
X,Yの2つがいずれも0以上K以下であって,かつX+Y=Tであるような(X,Y)の組の数をまず考える
TがK以下であればそのような組の数はmax(0,T+1)通り
TがK+1以上であればそのような組の数はmax(0,(T+1)-2*(T-K))通り

次にTのとりうる値の範囲を考える
Z=S-TであってZは0以上K以下でなければならないからTのとりうる値の範囲は0<=S-T<=K -S<=-T<=-S+K S-K<=T<=S

したがってS-K<=T<=Sについて上記の値を足し合わせればよい
'''

K,S=map(int,input().split(' '))
ans=0
for T in range(S-K,S+1):
	if T<=K:
		ans += max(0,T+1)
	else:
		ans += max(0,(T+1)-2*(T-K))
print(ans)

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

for x in range(max(0,S-2*K),min(S//3+1,K+1)):
    if S-x > 2 * K:
        pass
    else:
        for y in range(max(x,S-x-K),min((S-x)//2+1,K+1)):
            
            z = S - x - y
            if z < y:
                
                pass
            else:
                
                if x == y == z:
                    t += 1
                elif x == y or y == z:
                    t += 3
                else:
                    t += 6
print(t)

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

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

Solution (Python):

import sys

def main():
	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 0 > Z or K < Z:
				continue
			ans += 1
			
	print(ans)
	
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):
        if S-x-y <= K and S-x-y >= 0:
            ans += 1
print(ans)

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

Solution (Python):
import numpy as np
import sys

x = [[int(i) for i in input().split()] for j in range(1)]
k = x[0][0]
s = x[0][1]





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

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

print(count)

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

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

print(counter)

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

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

K, S = ints_raw()

ans = 0 
for X in xrange(K+1):
    for Y in xrange(K+1):
        Z = S-X-Y
        if Z>=0 and Z<=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):
    k=S-i-j
    if 0<=k<=K:
      ans+=1
        
print(ans)

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

ans=0

for i in range(K+1):
  if 0<=S-i<=K:
    ans+=S-i+1
  elif K<S-i<=2*K:
    ans+=2*K-(S-i)+1
        
print(ans)

Solution (Python):
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (-3 * (K ** 2) + 3 * K + 6 * S * K - 2 * (S ** 2) + 2) // 2
	print(int(ans))
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))

Solution (Python):
K, S = [int(x) for x in 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 = [ int(x) for x in input().split() ]

ans = 0
for X in range(K + 1):
    for Y in range(K + 1):
        Z = S - X - Y
        if 0 <= Z and Z <= K:
            ans += 1

print(ans)

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

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

print(count)

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

if s <= k:
    print((s + 2) * (s + 1) // 2)
else:
    ans = 0
    for x in range(k + 1):
        for y in range(min(k + 1, s - x + 1)):
            if 0 <= s - x - y <= k:
                
                ans += 1
    print(ans)

Solution (Python):

[K,S] = list(map(int, input().split()))


ans = 0 
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y          
    if 0 <= Z and Z <= K:  
      ans += 1
      

print(ans)

Solution (Python):
k,s=map(int,input().split());r=k+1;print(sum(k>=s-I//r-I%r>=0for I in range(r*r)))

Solution (Python):
k,s=map(int,input().split());r=k+1;print(sum(k>=s-I//r-I%r>=0for I in range(r*r)))

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

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

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

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

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

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

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 = (int(i) for i in 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,input().split())


num=0
for X in range(K+1):
    if X>S:
        break
    for Y in range(K+1):
        Z=S-Y-X
        if 0<=Z<=K:
            
            num+=1
print(num)

Solution (Python):
K, S = map(int,input().split())
count = 0
start = max(S - 2*K, 0)

for X in range(start,K+1):
    for Y in range(start,K+1):
        Z = S - X - Y
        if Z >= 0 and Z <= K:
            count += 1
print(count)

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 0 <= z & z <= k:
            count +=1
print(count)

Solution (Python):
inr = lambda: list(map(int, input().split()))

K, S = inr()

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

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


count = 0






































for i in range(0,k+1):
    for j in range(i,k+1):
        l = s-i-j
        if l>=j and l <= k:
            if i!=j and j != l and i!=l:
                
                count += 6
            elif i == j and j == l and i == l:
                
                count += 1
            else:
                
                count += 3

print(count)

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:
			continue
		if S-x-y <= K:
			count += 1
print(count)

Solution (Python):
k, s = map(int, input().split())
res = 0
for x in range(k+1):
  if 3 * x == s:
    res += 1
for x in range(k+1):
  for y in range(k+1):
    if x == y:
      continue
    if 2 * x + y == s:
      res += 3
for x in range(k+1):
  for y in range(x+1, k+1):
    d = s - x - y
    if d > y and d <= k:
      res += 6

print(res)

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

for x in range(k+1):
    for y in range(k+1):
        test = s-x-y
        if 0 <= test and test <= k:
            ans += 1

print(ans)

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

count = 0

if s > 3 * k:
    print(count)

else:
    for i in range(k + 1):
        x = i
        if x < s:
            for j in range(k + 1):
                y = j
                if s - (x + y) <= k and x + y <= s:
                    count = count + 1
                elif x + y > s:
                    break
        elif x == s:
            count = count + 1
        else:
            break

print(count)

Solution (Python):
K, S = [int(x) for x in  input().split()]

res = 0
for x in range(K+1):
    for y in range(K+1):
        if 0 <= S - (x + y) <= K:
            res += 1
print(res)

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


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

print(counter)

Solution (Python):
k,s=[int(i) for i in 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())
c = 0
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-x-y<=k:
            c += 1
print(c)

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

Solution (Python):
k,s=map(int,input().split())
ans=0
for x in range(k+1):
  for y in range(k+1):
    if k>=s-x-y>=0:
      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):
    if k>=s-x-y>=0:
      ans+=1
print(ans)

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

Solution (Python):
K, S = map(int, input().split())
count = 0
for i in range(K+1):
	for l in range(K+1):
		if S - i - l <= K and S - i - l >=0: 
			count = count + 1
print(count)

Solution (Python):
K, S = map(int, input().split())
cnt = 0
for i in range(K+1):
    for j in range(K+1):
        Z = S - (i + j)
        if 0 <= Z <= K:
            cnt += 1
print(cnt)

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 0 <= z <= k:
            count += 1
print(count)

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

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

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(0<= z <= K):
      ans += 1
print(ans)

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

Solution (Python):
temp = list(map(int,input().split()))
K = temp[0]
S = temp[1]
newK = K+1
cnt = 0
minlim = S-K
maxlim = S
for x in range(0, newK):
    for y in range(0, newK):
        if minlim <= x+y and x+y <= maxlim:
            cnt += 1
print(str(cnt))

Solution (Python):
K, S = map(int, 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 <= 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):
k,s=map(int,input().split())
cnt=0
for l in range(k+1):
    for m in range(k+1):
        
        if 0<=s-l-m and s-l-m<=k:
            cnt+=1
            
print(cnt)

Solution (Python):

K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S - i > 2 * K:
        continue
    elif S - i < 0:
        break
    if S - i > K:
        ans += 2 * K + 1 - S + i
    else:
        ans += S - i + 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 = [int(i) for i in input().split()]
ans=0
for x in range(k+1):
  for y in range(k+1):
    if 0<=s-x-y<=k:
      ans+=1
print(ans)

Solution (Python):
K,S=map(int,input().split())
s=0
for i in range(K+1):
    for j in range(K+1):
        t=S-i-j
        if 0<=t and K>=t:
            s+=1
print(s)

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

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

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

for i in range(K+1):
    for j in range(K+1):
            if 0<=(S-i-j)<=K:
                c += 1

print(c)

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

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

for x in range(k+1):
    for y in range(x, k+1):
        z = s-x-y
        if y <= z <= k:
            if x == y == z:
                c += 1
            elif x == y or y == z:
                c += 3
            else:
                c += 6

print(c)

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

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

print(c)

Solution (Python):
k, s = map(int, input().split())
x = range(k+1)
y = range(k+1)
z = range(k+1)
cnt = 0
for i in x:
    for p in y:
        if (s-(i+p)) in z:
            cnt += 1
print(cnt)

Solution (Python):
limit, target = map(int, input().split(" "))
answer = 0
for i in range(limit + 1):
    for j in range(limit + 1):
        if 0 <= target - i - j <= limit:
            answer += 1
            

print(answer)

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):
K, S = map(int, input().split())
X = range(K + 1)
Y = range(K + 1)
Z = range(K + 1)

count = 0

for i in X:
    for p in Y:
        if (S - (i + p)) in Z:
            count += 1

print(count)

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 or z > K:
            pass
        else:
            count += 1

print(count)

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

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

print(cnt)

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

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

Solution (Python):
import sys
inp = sys.stdin.readline

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

cnt = 0
for i in range(K+1):
  for j in range(K+1):
    if(0 <= S-i-j < K+1):
      cnt += 1
print(cnt)

Solution (Python):
a,b=map(int, input().split())
count = 0
for i in range(a+1):
  for j in range(a+1):
    s = b-i-j
    if s>=0 and s<=a:
      count += 1
print(count)

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

ans = 0

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

print(ans)

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

    ans = 0

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

    print(ans)

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
    ans += 1 if z>=0 and z<=k else 0
print(ans)

Solution (Python):
"""AtCoder"""

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

ans = 0

for i in range(K+1):
  for j in range(K+1):
    if i + j <= N and i + j + K >= N:
      ans += 1



print(ans)

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

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

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(K+1):
    for Y in range(K+1):
        Z = S - X - Y
        if 0 <= Z <= 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(S-i-j>=0 and S-i-j<=K):
      ans+=1
print(ans)

Solution (Python):

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

for i in range(K+1):
    for j in range(K+1):
    	k=S-i-j
    	if(k<=K and 0<=k):
    		count+=1
print(count)

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):
k,s = (int(i) for i in input().split())
answer = 0
for x in range(k + 1):
  for y in range(k + 1):
    if 0 <= s - (x + y) <= k:
      answer += 1
print(answer)

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

Solution (Python):
if __name__ == '__main__':
    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) and s-(x+y)<=k:
                cnt = cnt+1
    print(cnt)

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

Solution (Python):
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
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())
p=0
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-x-y<=k:
            p+=1
print(p)