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):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


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

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

    print(c)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

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

count = 0

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

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

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

def F(K,S):
  
  if S < 0:
    return 0
  if S <= K:
    return (S+1)
  if S > K+K:
    return 0
  return (K+K-S+1)

answer = 0

for x in range(K+1):
  answer += F(K,S-x)

print(answer)

Solution (Python):

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


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


print(counter)

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

print(cnt)

Solution (Python):
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, 2*K - T +1)
print(ans)

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

Solution (Python):

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

if 3*K < S:
    print(ans)
    exit()

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

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

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 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 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 i in range(K + 1):
    for j in range(K + 1):
        if i + j > S:
            continue
        elif i + j >= S - 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 s-k<=i+j<=s:
            cnt+=1
print(cnt)

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

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

Solution (Python):


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

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



if __name__ == "__main__":
    solve()

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


x = [ i   for i in range(n[0]+1)]



counter = 0
if n[0]*3 >= n[1]:
  for x1 in x:
    for y1 in x:
      if 0<= n[1]-x1-y1 <=n[0]  :
          counter +=1

        
print(counter)

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 = input().split(' ')
k,s = int(k),int(s)


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

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

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

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

print(cnt)

Solution (Python):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [K, S] = list(map(lambda x: int(x), inputs[0].split()))
    pattern = 0
    for x in range(0, K + 1):
        for y in range(0, K + 1):
            tmp_z = S - x - y
            if tmp_z <= K and tmp_z >= 0:
                pattern += 1

    return pattern


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

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

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

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

ar = itertools.product(range(K+1), repeat=2)

ans = 0
for a,b in ar:
  if S - a-b <= K and a+b <= S: 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):
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

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

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

    print(counter)

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

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

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

if not ((2 <= K and K <= 2500) or (0 <= S and S <= 3*K)):
    exit()

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

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

        if k2 > k or k2 < 0:
            continue

        if s == i + j + k2:
            ans += 1

print(ans)

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

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

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

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

ans = 0
for x in range(min(K+1, S+1)):
    if K < (S - x) //2:
        ans +=  0
    elif K < (S - x):
        ans += K * 2 - (S - x) + 1
    else:
        ans += (S - x) + 1

print(ans)

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

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

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

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

print(sum)

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

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

x =0

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

print(x)

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

import copy
import random
import bisect 
import fractions 
import math
import sys

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

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

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

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

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

Solution (Python):
k, s = map(lambda x: int(x), input().split(' '))
r = 0
for a in range(k + 1):
    if a > s:
        break
    for b in range(k + 1):
        if a + b > s:
            break
        elif s - (a + b) < k + 1:
            r += 1
print(r)

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    k,s = f()
    
    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)


solve()

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 <= K and S-i-j >= 0:
            ans += 1

print(ans)

Solution (Python):
k, s = map(int, input().split())
ks = [_ for _ in range(k+1)]

count = 0

for ksk1 in ks:
    for ksk2 in ks:
        z = s - ksk1 - ksk2
        if 0 <= z <= k:
            count += 1
            
print(count)

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

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

print(ans)

Solution (Python):






k, s = map(int,input().split())
xmin = (s - 2 * k) if (s - 2 * k) > 0 else 0
xmax = k if k < s else s
count = 0
for x in range(xmin, xmax+1):
  if 0 <= s-x and s-x <= k: 
    count += s-x+1
  elif k <= s-x and s-x <= 2*k: 
    count += 2*k-(s-x)+1
print(count)

Solution (Python):






k, s = map(int,input().split())
count = 0
for x in range(0, k+1):
  if 0 <= s-x and s-x <= k: 
    count += s-x+1
  elif k <= s-x and s-x <= 2*k: 
    count += 2*k-(s-x)+1
print(count)

Solution (Python):






k, s = map(int,input().split())
xmin = (s - 2 * k) if (s - 2 * k) > 0 else 0
xmax = k if k < s else s
count = 0
for x in range(xmin, xmax+1):
  ymin = (s - k - x) if (s - k - x) > 0 else 0
  ymax = k if k < s - x else s - x
  for y in range(ymin, ymax+1):
    if 0 <= s-x-y and s-x-y <= k:
        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 and s-x-y <= k:
        count += 1
print(count)

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

cnt = 0
for x in range(0, K + 1):
    if x > S:
        break
    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())

count = 0
for i in range(K+1):
    for j in range(K+1):
        z = S - i - j
        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):
        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())
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):
m,n,l = 1,1,1

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

rangeX,rangeY,rangeZ = K,K,K

W=S

cnt = 0
for i in range(min(W//m+1,rangeX+1)):
    for j in range( min((W-m*i)//n+1,rangeY+1)):
        if  (lambda d,m: m==0 and d<=rangeZ)(*divmod((W-m*i-n*j),l)):
            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):
        z = s - x - y
        if 0 <= z <= k:
            c += 1

print(c)

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

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

ret = 0

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

print(ret)

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):
answer=0
i = list(map(int, input().split()))
f=i[0]+1
for a in range(f):
    for b in range(f):
        sum=a+b
        if 0 <= i[1]-sum <= i[0] :
                answer+=1
print(answer)

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

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

print(cnt)

Solution (Python):

"""
B - Sum of Three Integers
https://atcoder.jp/contests/abc051/tasks/abc051_b

"""
import sys


def solve(K, S):
    ans = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if 0 <= z <= K:
                ans += 1
            elif z < 0:
                break
    return ans


def main(args):
    K, S = map(int, input().split())
    ans = solve(K, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

Solution (Python):
K,S=map(int, 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(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 = 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):
input_data = input().split()

k=int(input_data[0])
s=int(input_data[1])
count=0

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

print(count)

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

Solution (Python):
import bisect
import sys


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









k, s = map(int, input().split())
ans = 0
for i in range(k+1):
    if s-i > 2*k or s-i < 0:
        continue
    temp = s-i
    for j in range(k+1):
        if temp-j > k or temp - j < 0:
            continue
        ans += 1
print(ans)

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

Solution (Python):
import itertools

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

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

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 0 <= S - x - y <= K:
            count += 1

print(count)

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



m,n= (int(i) for i in input().split())       








total = 0
for i in range(m+1):
    for k in range(m+1):
        if n-i-k <= m and n-i-k >= 0: total+=1
print(total)

Solution (Python):
m,n= (int(i) for i in input().split()) 
total = 0
for i in range(m+1):
    for k in range(m+1):
        if n-i-k <= m and n-i-k >= 0: total+=1
print(total)

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

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

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

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())
if S<=K:
    print((S+2)*(S+1)//2)
elif S<=2*K:
    m=0
    for i in range(K+1):
        s=S-i
        if s<=K:
            m+=s+1
            
        else:
            c=s-K
            a=s-2*c
            m+=a+1         
    print(m)

else:
    s=3*K-S
    print((s+2)*(s+1)//2)

Solution (Python):
K,S=map(int,input().split())
count=0
for i in range(0,K+1):
        if max(S-2*i,0)<=2*K:
            for j in range(0,K+1):
                if (S-i-j<=K)&(0<=S-i-j):
                    count=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())
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())
cnt = 0

for X in range(K + 1):
    if S - X < 0:
        break
    for Y in range(K + 1):
        if S - X - Y < 0:
            break
        if S - X - Y <= K:
            cnt += 1

print(cnt)

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

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

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

Solution (Python):
if __name__ == '__main__':
    k, s = map(int, input().split())
    ans = 0
    for i in range(k+1):
        if i > s:
            break
        for j in range(k+1):
            z = s - i - j
            if i + j > s:
                break
            elif 0 <= z 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 <= K:
            ans += 1
print(ans)

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

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


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

if __name__ == '__main__': 
    K, S = map(int, input().split())
    
    solve(K, S)

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

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

Solution (Python):
from math import sqrt


def log(s):
    
    pass


def output(x):
    print(x, flush=True)


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


def main():
    k, s = tuple(input_ints())

    def solve2(ss):
        if ss > 2 * k:
            return 0
        elif ss > k:
            return 2 * k - ss + 1
        else:
            return ss + 1

    print(sum([solve2(ss) for ss in range(max(0, s - k), s + 1)]))


main()

Solution (Python):
def 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) <= k:
                cnt+=1
    print(cnt)
main()

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

import sys


def solve(K: int, S: int):
    ans = 0
    
    
    
    
    
    

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

    print(ans)
    return



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))  
    solve(K, S)

if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import defaultdict
dic = defaultdict(lambda: 0)
K,S=[int(a) for a in input().split(" ")]
for x in range(0,K+1):
    for y in range(0,K+1):
        dic[S-x-y] += 1
ans = 0
for z in range(0, K+1):
    ans += dic[z]
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 i+j <= S and i+j+K >= S:
      cnt += 1
print(cnt)