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

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):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

k,s=map(int,input().split())
if s<=k:
    print(cmb(s+2,2))
elif s>2*k:
    print(cmb(3*k-s+2,2))
else:
    ans=0
    for i in range(k+1):
        if s-i>=k:
            ans+=2*k-s+1+i
        else:
            ans+=s+1-i
    print(ans)

Solution (Python):
k,s=map(int, input().split())
ans=0
for x in range(k+1):
    buf=s-x
    if 0<=buf<=2*k:
        for y in range(k+1):
            z=buf-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):
        z=s-i-j
        if z>=0 and z<=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):
        if  0 <= S-x-y <= K:
            ans += 1
print(ans)

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

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

print(cnt)

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

Solution (Python):
k,s = map(int,input().split())
x,y,z = k,k,k
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):
import sys
input = sys.stdin.readline

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



ans = 0
for A in range(2*K+1):
    Z = S - A
    if 0 <= Z and Z <= K:
        for X in range(K+1):
            Y = A - X
            if 0 <= Y and Y <= 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 0 <= k <= K: 
            count += 1
print(count)

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):
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            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):
    if (S - i - j >= 0 and S - i - j <= 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):
    Z = S - X - Y
    if 0<=Z 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):
        if x + y <= s and x + y + k >= s:
            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 x + y <= s and x + y + k >= s:
            count += 1

print(count)

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 and 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):
        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(min(K, S)+1):
    for Y in range(min(K, S-X)+1):
        if 0 <= S-X-Y <= K:
            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-X)+1):
        if 0 <= S-X-Y <= 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):
i,j=map(int,input().split())
a=0
for x in range(i+1):
  for y in range(i+1):
    if j-(x+y)<=i:
      if x+y<=j:
        a+=1
print(a)

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

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


if __name__ == "__main__":
    main()

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):
import sys
input = sys.stdin.readline

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

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

print(count)

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

Solution (Python):
k,s = map(int,input().split())
ans = 0
for x in range(min(k+1,s+1)):
    l = max(s-k-x, 0)
    r = min(s-x,k)
    if l <= r:
        ans += r-l+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):
        z=S-i-j
        if 0<=z:
            if 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):
    z = s - x -y
    if z >= 0 and z <= k:
      count += 1

print(count)

Solution (Python):
import sys


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



min_num = 0

ans = 0

for x in range(min_num, k + 1):
    for y in range(min_num, k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        else:
            ans += 1

print(ans)

Solution (Python):
import sys


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

min_num = s - k * 2
if min_num <= 0:
    min_num = 0

ans = 0

for x in range(min_num, k + 1):
    for y in range(min_num, k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        else:
            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,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 and z<=k:
            ans+=1
print(ans)

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

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

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 t <= k and t >= 0:
            count += 1
        else:
            pass
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 S - i - j < 0 or S - i - j > K:
            continue
        else:
            cnt += 1
print(cnt)

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

count = 0
for i in range(k+1):
    for j in range(k+1):
        if i+j+k >= s and s-i-j >= 0:
            count += 1
        else:
            continue

print(count)

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

count = 0
for i in range(k+1):
    for j in range(k+1):
        if i+j+k >= s and s-i-j >= 0:
            count += 1
        else:
            continue

print(count)

Solution (Python):


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

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

flg = 0

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

print(flg)

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

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    K, S = MI()
    ans = 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:
                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):
        tmp = s-i-j
        if 0 <= tmp <= 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 0 <= Z and Z <= K:
      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):
        if 0<=s-(x+y)<=k:
            ans+=1
print(ans)

Solution (Python):
try:
    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)
except EOFError:
    pass

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

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 x in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        if s-(x+y) >= 0 and s-(x+y) <= 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 i + j == S:
      ans += 1
    elif 0 <= S - (i + j) <= K:
      ans += 1
print(ans)

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

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

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):
import itertools
k,s=map(int,input().split())

arr=[]
cnt=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:
        cnt+=1
      elif x==y or y==z or z==x:
        cnt+=3
      else:
        cnt+=6
print(cnt)

Solution (Python):
a,sums=list(map(int,input().split()))
if a*3==sums:
  print(1)
else:
  ret=0
  for x in range(a+1):
    if (sums-x <=2*a)&(sums>=x):
      for y in range(a+1):
        if (sums-x-y>=0)&(sums-x-y<=a):
          ret+=1
  print(ret)

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

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

Solution (Python):
try:
    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)
except EOFError:
    pass

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(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        z = s - x - y
        if y <= z and z <= k:
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 6
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 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 z >= 0 and 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 K >= Z and Z >= 0:
            ans += 1

print(ans)

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

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 >= 0 and k <= K:
            count += 1

print(count)

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


import copy


def main():
    K, S = map(int, input().split())
    result = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if 0 > z or z > K:
                continue
            else:
                result += 1

    print(result)


if __name__ == "__main__":
    main()

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

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

print(str(count))

Solution (Python):
import sys
input = sys.stdin.readline
K,S = [int(i) for i in 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())
list = []
for x in range(k + 1):
    for y in range(k - x + 1):
        z = s - (x + x + y)
        if x + y <= z <= k: list.append([x, y + x, z])
        y += 1
    x += 1

answer = 0
for id in list:
    if id[0] == id[1] == id[2]: answer += 1
    elif id[0] == id[1] or id[1] == id[2]: answer += 3
    else: answer += 6
print(answer)

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

import sys


def solve(K: int, S: int):
    cnt=0
    x_max = S if K >= S else K
    for x in range(0, x_max+1):
        y_max = S-x if K >= S-x else K
        for y in range(0, y_max+1):
            z = S - x - y
            if z <= K:
                cnt+=1
    return cnt


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  
    S = int(next(tokens))  
    print(solve(K, S))

if __name__ == '__main__':
    main()

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

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):
Max, Sum = map(int, input().split())

counter = 0
for i in range(Max+1):
  for j in range(Max+1):
    k = Sum - i -j
    if k >= 0 and k <= Max:
      counter += 1
 
print(counter)

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())
res = 0

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

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

x, y = 0, 0
ans = 0

for i in range(0, K+1):
    x = i
    for j in range(0, K+1):
        y = j
        z = S - x - y
        if 0 <= z <= K:
            ans += 1
        else:
            pass
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())
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())
from math import factorial
def c(n,r):
  return factorial(n)//factorial(n-r)//factorial(r)
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 = [int(i) for i in input().split()]
c = 0
for x in range(K+1):
    for y in range(x+1):
        z = S - x - y
        if x >= y >= z >= 0:
            if len({x, y, z}) == 3:
                c += 6
            if len({x, y, z}) == 2:
                c += 3
            if len({x, y, z}) == 1:
                c += 1
print(c)

Solution (Python):

K,S=map(int,input().split(" "))
answer=0
for X in range(K+1):
  if S-X>2*K:
    continue
  for Y in range(K+1):
    if S-(X+Y)<=K and S-(X+Y)>=0:
      answer+=1
print(answer)

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

l = []

for i in range(K + 1):
    l.append(i)

count = 0

for i in l:
    for j in l:
        z = S - i - j
        if 0 <= z and z <= 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(i, K+1):
    if 0 <= S - i - j <= K:
      if i == j:
        cnt += 1
      else:
        cnt += 2
print(cnt)

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

for i in range(k, -1, -1):
    
    if s - i > k * 2:
        continue

    
    for j in range(k, -1, -1):
        
        x = s - i - j

        if x > k:
            
            continue
        cnt += x >= 0
print(cnt)

Solution (Python):
k, s = map(int, input().split())
dst = 0
for z in range(k, -1, -1):
    if s - z > k*2:
        continue
    for y in range(k, -1, -1):
        x = s - z - y
        if x > k:
            continue
        dst += (x >= 0)
print(dst)

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

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

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):
        if 0 <= (s - x - y) <=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
		elif s - i - j < 0: break
print(ans)

Solution (Python):
import itertools

K, S = map(int, input().strip().split(' '))
X = list(range(K + 1))
count = 0
for i, j in itertools.product(X, repeat=2):
  if 0 <= S - i - j <= K:
    count += 1
print(count)

Solution (Python):
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K, S = map(int, readline().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):



def input_one_number():
    return int(input())


def input_multiple_number():
    return map(int, input().split())


def input_multiple_number_as_list():
    return list(map(int, input().split()))


def input_multiple_number_as_list_sep(N):
    ins = []
    for i in range(N):
        ins.append(input())
    return ins


def input_map():
    return [list(map(int,list(input()))) for i in range(h)]


def print_list(list):
    print(*list)
    return


def print_map(maplist):
    for i in maplist:print(*i, sep='')
    return


def generate_primenums():
    n = 100
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

def memo():
    a=[0]*5
    b=a  
    b2=a[:]  
    a[1]=3
    print('b:{}, b2:{}'.format(b,b2))  
    
    import copy
    a= [[0]*3 for i in range(5)] 
    b=copy.deepcopy(a)  
    
    
    odd=[i for i in range(100) if i%2==1] 

    
    import bisect
    a = [1, 2, 3, 5, 6, 7, 8, 9]
    b=bisect.bisect_left(a, 8)

    
    from itertools import permutations, combinations,combinations_with_replacement,product
    a=['a','b','C']
    print(list(permutations(a)))
    print(list(combinations(a,2)))
    print(list(combinations_with_replacement(a,3)))

    
    magics.sort(key=lambda x:x[2],reverse=True)



def kaijo(n):
    import math
    return math.factorial(n)


def num_combination(n,r):
    import math
    return math.factorial(n) // math.factorial(n - r)



def calc_gcd(a,b):
    import fractions
    GCD=fractions.gcd(a,b)
    lcm=a*b//gcd
    return gcd,lcm


def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = fractions.gcd(gcd, l[i])
    return gcd


def sum_digit(n):
    sum = 0
    while n > 0:
        sum += n%10
        n //= 10
    return sum

K,S = input_multiple_number()

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

print(cnt)

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):
        if 0 <= s-x-y <= 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 z >= 0 and k >= z:
            count += 1
            
print(count)

Solution (Python):

k, s = map(int, 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):
import sys

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

c=0

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

print(c)

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

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

count = 0

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

print(count)

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

for x_i in range(k+1):
  for y_i in range(k+1):
    if 0<=s-x_i-y_i<=k:
      counter += 1
    
print(counter)

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

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

print(ans)

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

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())
count = 0
for i in range(k + 1):
    for j in range(k + 1):
        l = s - i - j
        if l >= 0 and l <= k:
            count += 1

print(count)

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 = tuple(map(int, input().split()))


cnt = 0
for a in range(K+1):
    for b in range(K+1):
        c = S - (a + b)
        if 0 <= c <= K:
            cnt += 1
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(x, K + 1):
        z = S - x - y
        if z < y:
            break
        if z <= K:
            if x == y == z:
                ans += 1
            elif x == y or y == z or z == x:
                ans += 3
            else:
                ans += 6
print(ans)

Solution (Python):
from itertools import *
k, s = map(int, input().split())


t = sum(min(max(s - i + 1, 0), max(2*k - s + i +1, 0)) for i in range(k+1))
print(t)

Solution (Python):
K , S = map(int , 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):
N = input().split()
N = [int(i) for i in N]
count = 0
for i in range(N[0]+1):
    for j in range(N[0]+1):
        k = N[1] - i - j
        if((k <= N[0])and(k>=0)):
            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 k >= s-i-j >= 0: 
            ans += 1
print(ans)

Solution (Python):
def solve(k, s):
    return sum(
        s - x - y <= k
        for x in range(min(k + 1, s + 1))
        for y in range(min(k + 1, s - x + 1))
    )

_k, _s = map(int, input().split())
print(solve(_k, _s))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

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

print(ans)