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

import math
def comb(M, N):
    if M<0: return 0
    if M<N: return 0
    return (math.factorial(M)//(math.factorial(M-N)*math.factorial(N)))

print(comb(S+2, 2)-3*(comb(S+2-K-1, 2))+3*(comb(S+2-2*(K+1), 2)))

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

ans = 0
for i1 in range(min(k+1, s+1)):
    for i2 in range(0, min(k+1, s - i1 + 1)):
        if s - (i1 + i2) <= 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())
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):
    t = s - (i + j)
    if 0 <= t <= 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())

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(x+1):
        if x+y>s:
            continue
        else:
            z=s-x-y
            if z>x or z>y:
              continue
            if x==y==z:
                count+=1
            elif x==y or y==z or z==x:
                count+=3
            else:
                count+=6
print(count)

Solution (Python):
def answer(k: int, s: int) -> int:
    count = 0
    
    for x in range(k + 1):
        y_max = min(k, s - x)
        y_min = max(0, s - x - k)
        comb = y_max - y_min + 1
        
        if 0 < comb:
            count += comb

    return count


def main():
    k, s = map(int, input().split())
    print(answer(k, s))


if __name__ == '__main__':
    main()

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

ans=0
for i in range(k+1):
    for q in range(k+1):
        if i+q+k>=s and i+q<=s:
            ans+=1
print(ans)

Solution (Python):
import sys
def input():
  return sys.stdin.readline().rstrip()

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

print(count)

Solution (Python):
k, s = map(int, input().split())
counter = 0
for i in range(k + 1):
    counter += max(min(k, s - i) - max(0, s - k - i) + 1, 0)

print(counter)

Solution (Python):
k, s = map(int, input().split())
counter = 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:
                counter += 1
            elif x == y or y == z:
                counter += 3
            else:
                counter += 6

print(counter)

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

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

print(kotae)

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

if __name__ == '__main__':
	main()

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

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

if k*3==s:
  print(1)
  exit()

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())
upper  = min(k,s)+1
lower = max(0,s-2*k)
ans = 0
for i in range(lower,upper):
  for j in range(lower,upper):
    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):
        if 0<=s-(x+y)<=k:
            ans+=1
print(ans)

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

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

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

print(ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


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

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

success = 0

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

print(success)

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

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):
a,b=map(int,input().split())
n=0

for y in range(a+1):
  for z in range(a+1):
      p=b-y-z
      if 0<=p and p<=a:
        n+=1
print(n)

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

print(count)

Solution (Python):
k_num, s_num = map(int, input().split())

cnt = 0
for x in range(k_num+1):
    l = s_num - x
    for y in range(k_num+1):
        z = l - y
        if 0 <= z <= k_num:
            cnt += 1

print(cnt)

Solution (Python):
k_num, s_num = map(int, input().split())

cnt = 0
for x in range(k_num+1):
    l = s_num - x
    for y in range(k_num+1):
        z = l - y
        if 0 <= z <= k_num:
            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) and 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(k + 1):
        z = s - i - j
        if 0 <= z <= k:
            cnt += 1

print(cnt)

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

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

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

print(Sum)

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

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

a = 0

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

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K, S = LI()

    ans = 0
    for x, y in itertools.product(range(K + 1), repeat=2):
        if 0 <= S - (x + y) <= K:
            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):


k,s = map(int,input().split())
c = 0
min_limit = s - k

for i in range(k+1):
    for j in range(k+1):
        if i + j <= s and i + j >= min_limit:
            c += 1
print(c)

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

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

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

      ans += 1
print(ans)

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

Solution (Python):
k,s=map(int,input().split())
print(len([1 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())
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=map(int, input().split())
ans = 0
x = S//3+1
for i in range(x):
  y = (S-i)//2+1
  for j in range(i, y):
    k = S - i - j
    if k > K:
      continue
    if i == j == k:
      ans += 1
    elif i == j or j == k:
      ans += 3
    else:
      ans += 6
print(ans)

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

Solution (Python):
import itertools
url = "https://atcoder.jp//contests/abc057/tasks/abc057_a"

def main():
    k, s = list(map(int, input().split()))
    count = 0
    for x, y in itertools.product(range(k+1), range(k+1)):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
    print(count)


if __name__ == '__main__':
    main()

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

import sys
def input():
    return sys.stdin.readline()[:-1]

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



if __name__ == '__main__':
    main()

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())
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())
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 sys
import heapq
from decimal import Decimal

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

def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


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

cnt = 0
for idx1 in range(0, k+1):
    for idx2 in range(0, k+1):
        current = s - (idx1 + idx2)
        if 0 <= current <= k:
            cnt += 1

print(cnt)

Solution (Python):
a,b=input().split()
a=int(a)
b=int(b)
c=0
for i in range(a+1):
  for k in range(a+1):
    if b-a<=i+k<=b:
      c=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):
    Z=S-X-Y
    if 0<=Z<=K:
      ans+=1
print(ans)

Solution (Python):



def main():
    stdIn1, stdIn2 = map(int, input().split())
    stdOut = solve(stdIn1, stdIn2)
    print(stdOut)


"""
方針
x,y,zそれぞれを3重ループで0からkまで回す
(O(N^3)だが、k<=2500なので気にならない)
x+y+zが等しければパターンを1追加

TLEになったので、もう少し節約するパターンを考える必要あり
ひとまずx,x+y,x+y+zがsより大きなった場合はbreakさせてループを抜ける処理にしてみる
まだTLEになるので、もう少し考える
実はzはループする必要はなく z = s - (x + y) <= k であれば +1, > k であれば continueでよい
これでO(N^2)に計算量を抑えられる

"""


def solve(k, s):
    pattern = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            z = s - x - y
            if z <= k:
                pattern += 1

    return pattern


if __name__ == "__main__":
    main()

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


K,S = MI()

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

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

print(cnt)

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

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 i+j+k==S:
            if 0<=k<=K:
                ans+=1
print(ans)

Solution (Python):
def LI():
    return list(map(int, input().split()))


K, S = LI()
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
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


def lcm(a, b):
    
    g = gcd(a, b)
    return a // g * b


K, S = ints()
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 x in range(k+1):
  for y in range(k+1):
    if 0<=s-y-x<=k:ans+=1
print(ans)

Solution (Python):
import sys

K, S = map(int, sys.stdin.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):
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  K,S=map(int,pin().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)
  return 
main()

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 and z<=k:
            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 i + j <= s and s - i - j <= k:
            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):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


K,S = MI()

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
from itertools import product as prd
for x, y in prd(range(K+1),range(K+1)):
    if 0 <= S-x-y <= 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):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    k,s = LI()
    ans = 0
    for x in range(k+1):
        for y in range(k+1):
            if s-k<=x+y and x+y<=s:
                ans += 1

    print(ans)
main()

Solution (Python):
k, s = list(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 z in range(0, k+1):
            ans += 1
print(ans)

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

def main():
    k , s = map( int , input().split() )

    ans = 0

    for i in range( k + 1 ):
        if i > s:
            break
        if s - i > 2 * k:
            continue
        for j in range( k + 1 ):
            if i + j > s:
                break
            if s - i - j > k:
                continue
            ans += 1

    print( ans )




main()

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

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

for p in range(k+1):
    for q in range(k+1):
        r = s-p-q
        if r>=0 and r<=k:
            count += 1

print(count)

Solution (Python):
k,s = map(int, input().split(" "))
count = 0
for i in range(max(0, s-2*k), min(s, k)+1):
  count += min(k, s-i) - max(0, s-i-k) + 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 <= K:
              count += 1
print(count)

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

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

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

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

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

print(answer)

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

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

print(str(answer))

Solution (Python):
import sys

(K, S) = (int(x) for x in input().split())
comb = 0

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

      comb+=1

print(comb)

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

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

for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if(0<=z and z<=K):
            if(x == y and y == z):
                ans += 1
            elif(x != y and y != z and z != x):
                ans += 1
            else:
                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(0,k+1):
    if 0<=s-(i+j)<=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())
a = 0
for X in range(K+1):
    for Y in range(K+1):
        if 0<=S-X-Y<=K:
            a += 1
print(a)

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

for i in range(k+1):
    for j in range(k+1):

        x = i
        y = j
        z = s - x - y

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

Solution (Python):
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_range=min(K,S)
cnt=0
for x in range(max_range+1):
    for y in range(min(max_range,max(0,S-x-max_range)),min(max_range,S-x)+1):
        z= S-x-y
        if 0 > z:
            break
        if z <= max_range:
            cnt+=1
print(cnt)

Solution (Python):
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_loop=min(K,S)+1
cnt=0
for x in range(max_loop):
    for y in range(max_loop):
        z= S-x-y
        if 0 > z:
            break
        if z <= K:
            cnt+=1
print(cnt)