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):
x = list(map(int,input().split()))
count=0
for a in range(max(0,x[1]-2*x[0]),min(x[0],x[1])+1):
    for b in range(max(0,x[1]-a-x[0]),min(x[0],x[1]-a)+1):
        for c in range(max(x[1]-a-b,0),min(x[1]-a-b,x[0])+1):
            if(a+b+c==x[1]):
                count+=1
print(count)

Solution (Python):



import sys



intm1 = lambda x: int(x) - 1
intp1 = lambda x: int(x) + 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(intm1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(limitno, giventotal):
    result = 0
    for x in range(0, limitno+1):
        for y in range(0, limitno+1):
            z = giventotal - x - y
            if ( 0 <= z ) and (z <= limitno):

                result = intp1(result)
    return result


if __name__ == "__main__":
    K, S = MI()
    print("{}".format(solver(K, S)))

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

Solution (Python):
K, S = [int(i) for i in input().split()]
t = 0
for a in range(K+1):
    for b in range(a, K+1):
        c = S - a - b
        if 0 <= c <= K and c >= a and c >= b:
            if a == b == c:
                t += 1
            elif a == b or b == c:
                t += 3
            else:
                t += 6
print(t)

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

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

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

k, s = map(int, input().split())
cnt = 0
max_v = max(2 * (k + 2), s + 1)
memo = [0] * max_v
for i in range(k + 1):
  for j in range(k + 1):
    v = i + j
    if v > s:
      break
    memo[v] += 1
for i in range(k + 1):
  for j in range(max_v):
    v = i + j
    if v > s:
      break
    elif v == s:
      cnt += memo[j]
print(cnt)

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

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

print(sum(main()))

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

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

print(ans)

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

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

print(ans)

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

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

print(ans)

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

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

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=[int(x) for x in input().split()]

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

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

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

print(c)

Solution (Python):




import sys



int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(K, S):
    result = 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)):
                result = result + 1
    return result


if __name__ == "__main__":
    K, S = MI()

    print("{}".format(solver(K, S)))

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

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

def fact(n):
  return sum([x for x in range(1,n+1)])

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

print(ans)

Solution (Python):



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


available_value_list = range(K+1)

result = 0
for x in available_value_list:
    for y in available_value_list:
        z = S - x - y 
        if 0 <= z and z <= K:
            result += 1


print(result)

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

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(0,k+1):
	for g in range(0,k+1):
		if k>=s-i-g>=0:
			count+=1
print(count)

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

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

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

print(Y)

Solution (Python):
import math
K, S = [int(i) for i in input().split()]
count = 0

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

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

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

ans = 0
for x in range(0, k+1):
    if s-x < 0 or s-x > 2*k:
        
        continue
    elif 0 <= s-x <= k:
        ans += 1+s-x
    else:
        ans += k - (s-x-k) + 1

print(ans)

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

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

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

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

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

main()

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

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

print(count)

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

count = 0
for x in range(k,-1,-1):
    a = s - x
    if a > 2*k:
        break
    elif a == 0:
        count += 1
        continue

    if a >= k:
        tmp = k
    else:
        tmp = a

    for y in range(tmp, -1, -1):
        z = a - y
        if z > k :
            break
        else:
            count += 1

print(count)

Solution (Python):
import itertools
k,s = [int(x) for x in 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 = [int(n) for n in 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())

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

count=0

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

print(count)

Solution (Python):
K, S = map(int, input().split())
x = S if K>S else K

ans = 0
for i in range(x+1):
  x1 = S-i
  for j in range((K if x1>K else x1)+1):
    if S-i-j <= K:
      ans += 1

print(ans)

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

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

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

for y in range(K+1):
    for z in range(K+1):
        x = S - y - z
        
        if x < 0 or x > K:
            continue
        else:
            ans += 1
            continue
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)&(z<=K):
            count += 1
print(count)

Solution (Python):

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

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

Solution (Python):
k,s=input().split()
K=int(k)
S=int(s)
count =0
for p in range(K+1):
    for q in range(K+1):
        r=S-p-q
        if 0<=r and r<=K:
            count +=1
print(count)

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

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

    print(ans)




if __name__ == '__main__':
    main()

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

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

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

print(ans)

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

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

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

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

    count = 0
    for x in range(k+1):

        if k*2 + x < s:
            continue

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

    print(count)


if __name__ == "__main__":
    main()

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

cnt=0
if K*3==S:
    cnt+=1
elif K*3<S:
    pass
else:
    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()) 
print(len([True for x in range(K+1) for y in range(K+1) if (S-x-y>=0) and (S-x-y<=K)]))

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

Solution (Python):

s = input().split()
t = [int(p) for p in s]
K = t[0]
S = t[1]
counter = 0

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

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

count = 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:
            count += 1

print(count)

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

ans = 0

for i in range(k+1):
    for j in range(i,k+1):
        c = s-i-j
        if k >= c and c >=j:
            if i == j and j == c:
                ans += 1
            elif i!=j and j!=c and c!=j:
                ans += 6
            else:
                ans += 3
        
print(ans)

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

for i in range(k + 1):
    x = i
    tmp = s - x

    if tmp < 0:
        break

    if 2 * k >= tmp:
        if k >= tmp:
            ans = ans + tmp + 1
        else:
            ans = ans + ((k + 1) - (tmp - k))

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

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

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
import math
import sys
input = sys.stdin.readline

sys.setrecursionlimit(2147483647)

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

if __name__ == '__main__':
  main()

Solution (Python):

"""
Created on Wed Mar 18 20:25:04 2020

@author: naoki
"""

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

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

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

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

s3 = s // 3
m = max(k, s3)
for x in range(0, m + 1):
    
    for y in range(0, m + 1):
        ad = s - x - y
        if ad <= k and ad >= 0:
            ans += 1

print(ans)

Solution (Python):
import sys

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

print("{}".format(cnt))

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

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

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

def main():
    mod=10**9+7
    K,S=MI()
    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)

main()

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

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

print(cnt)

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

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

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










import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

K,S = splitintinput()

time_sta = time.perf_counter()
ans = 0

for i in range(K+1):
    for j in range(min(S-i + 1, K + 1)):
        if S - i - j <= K:
            ans += 1
print(ans)


time_end = time.perf_counter()

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

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

Solution (Python):








def resolve():
    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 0<=S-i-j<=K:
                cnt+=1

    print(cnt)
resolve()

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

print(count)

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

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

print(ans)

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

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

Solution (Python):
vec = input().split(' ')
k = int(vec[0])
s = int(vec[1])
count = 0
for x in range(k + 1):
    if x <= s:
        for y in range(k + 1):
            if x + y <= s:
                z = s - x - y
                if z >= 0 and z <= k:
                    count += 1
            else: break
    else: break
print(count)

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

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

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

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

def countPatterns(K, S):
  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
        
  return count

print(countPatterns(K, S))

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

Solution (Python):
K,S= input().split()
intK = int(K)
intS = int(S)
sum = 0
for X in range(intK+1):
    for Y in range(intK+1):
        Z = intS - (X+Y)
        if (Z < 0) or Z > intK:
            continue
        sum += 1
print(sum)

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

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

cnt = 0

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

print(cnt)

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

x=0
j=0

for j in range(k+1):
	if s-j<=k and s-j>=0:
		x=x+s-j+1
	elif (s-j)<=2*k and s-j>=0:
		x=x+(2*k-(s-j)+1)

print(x)

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

print(ans)

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

Solution (Python):
import itertools

K,S = list(map(int,input().split()))
l = set(range(K+1))
ans = 0

for x, y in itertools.product(l,l):
    if x + y + K >= S and x + y <= S:
        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 - y - x
        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 s <= i+j+k and i+j <= s:
            ans += 1
print(ans)

Solution (Python):
K,S = [int(i) for i in input().split()]
count = 0
for z in range(0,K+1):
	for y in range(0,K+1):
			if 0 <= S-y-z <= K:
				count += 1
print(count)

Solution (Python):
import itertools

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

cnt = 0

l = list(range(K + 1))

for i, j in itertools.product(l, repeat=2):
    if 0 <= S - i - j <= K:
        cnt += 1

print(cnt)

Solution (Python):
import itertools

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

cnt = 0



for i, j in itertools.product(list(range(K + 1)), repeat=2):
    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())

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

print(cnt)

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

print(count)

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