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.



Sample input:
2 2


Sample output:
6

Submission status: Accepted

Solution code:
# ABC 051 B
K, S = [int(x) for x in input().split()]
#print(K,S)#

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = [ int(i) for i in input().split() ]
count = 0
for X in range(K+1):
    for Y in range(K+1):
        if (X + Y) <= S and S - (X+Y) <= K:
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = 0
for x in range(n + 1):
    for y in range(n + 1):
        if m - x - y <= n and m - x - y >= 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

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

Submission status: Accepted

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

ans = 0
for x in range(k+1):
    if 0 <= s - x <= k:
        ans += s-x+1
    elif 0 <= s-x-k <= k:
        ans += k - s + x + k + 1
    # print(x, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ret = 0 
for X in range(K+1):
  for Y in range(X, K+1):
    Z = S - X - Y
    if Z < Y: break
    if Z >= 0 and Z <= K:
      if X == Y and Y == Z: ret += 1
      elif X != Y and Y != Z and Z != X: ret += 6
      else: ret += 3

print (ret)

Submission status: Accepted

Solution code:
K,S = map(int,input().split())
patterns = 0

# # arr = [[x+y for y in range(min(S-x+1,K+1))] for x in range(K+1)]
# farr = list(chain.from_iterable(arr))
# for z in farr:
#     temp_z = S - z
#     if temp_z <= K and temp_z >=0:
#         patterns += 1
# print(farr)
# print(farr.count(S))

for x in range(K+1):
    for y in range(max(0,S-K-x), min(K+1,S-x+1)):
        patterns += 1
print(patterns)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
int_k, int_s = map(int, input().split())
counter = 0
for x in range(int_k + 1):
    for y in range(int_k + 1):
        if 0 <= int_s - (x + y) <= int_k:
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


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

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
ret = 0
for i in range(k+1):
    ret += max(0,min(s-i, 2*k-s+i)+1)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

K, S = [int(_) for _ in sys.stdin.readlines()[0].strip().split(' ')]
total_pattern = 0

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

Submission status: Accepted

Solution code:
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(x,y,z)
print(ans)

Submission status: Accepted

Solution code:
import sys, itertools
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]

K, S = inpl()
print(sum([0 <= S - x - y <= K for x, y in itertools.product(range(K+1), repeat = 2)]))

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
ans = 0
for x in range(min(S + 1, K + 1)):

    if x + K < S - K:
        continue
    else:
        ans += (min(S - x, K) - max(0, S - K - x) + 1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,n = map(int, input().split())
res = 0
for i in range(k+1):
    for j in range(k+1):
        if i + j > n : break
        h = n - i - j
        if h <= k:
            res +=1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)))
#コピペです。

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 += 1
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest051-B
#  https://atcoder.jp/contests/abc051/tasks/abc051_b
from itertools import product
def  queueAnswer(maxValue,sumNumber):
	baseList = list(range(0,maxValue+1,1))
	xyPool = product(baseList,baseList)
	counter = 0
	for x,y in xyPool:
		z = sumNumber - x - y
		if ( 0 <= z ) and ( z <= maxValue):
			counter = counter + 1

	answer = counter
	return answer


if __name__ == '__main__':
	k,s = map(int,input().strip().split(' '))
	solution=queueAnswer(k,s)
	print(solution)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
n = 0
for i in range(max(S-2*K,0),min(K+1,S+1)):
    X = i
    for j in range(max(S-i-K,0),min(K+1,S-i+1)):
        Y = j
        Z = S - i - j
        n += 1
print(n)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
def main():
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__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 x <= y <= z <= K:
                ans += [None, 1, 3, 6][len( set( [x,y,z]))]
   
    print(ans)

Submission status: Accepted

Solution code:
K,S = map(int,raw_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

Submission status: Accepted

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

count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            # print("{} {} {}".format(x, y, z))
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N,M = map(int,input().split())
X = [i for i in range(N+1)]

count = 0
for x,y in itertools.product(X,X):
	if 0 <= M - x - y <= N:
		count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
        else:continue
print(count)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
line = input().split(" ")
k = int(line[0])
s = int(line[1])
count = 0

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

print(count)

Submission status: Accepted

Solution code:
K,S = [int(i) for i in input().split()]
patterns = 0

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

print(patterns)

Submission status: Accepted

Solution code:
K,S = list(map(int,input().split()))
count = 0
countb=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
maxi,total = map(int,input().split(" "))
ans = 0
for i in range(maxi+1):
    for j in range(maxi+1):
        if 0 <= total-i-j <= maxi:
            ans += 1
            
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = map(int, raw_input().split())
res = 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:
            res += 1
print res

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

nums=[i for i in range(k+1)]

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

Submission status: Accepted

Solution code:
import itertools
K,S=[int(_) for _ in input().split()]
ans=0
for i,j in itertools.product(range(K+1),repeat=2):
    if i+j<=S and S-i-j<=K:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
def main():
    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
K,S=map(int,input().strip().split(" "))
count=0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if((x+y+z)==S):
                count+=1
                #print(x,y,z)
print(count)
            
"""

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k, s = list(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 and z <= k:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(n)

Submission status: Accepted

Solution code:
# coding: utf-8
K, S = map(int, input().split())
cnt=0
for x in range(K+1):
        yz = S - x
        if yz < 0:
                break
        elif yz > 2*K:
                continue
        else:
                cnt += yz + 1 - 2 * max(0, yz - K)
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
K, S = map(int, input().split())
cnt=0
for x in range(K+1):
        yz = S - x
        if yz < 0:
                break
        elif yz > 2*K:
                continue
        else:
                for y in range(K+1):
                        z = S - x - y
                        if 0<=z<=K:
                                cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


"""
https://beta.atcoder.jp/contests/abc009/tasks/abc51_2
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
ans = 0

for x in range(a+1):
  for y in range(a+1):
    z = b - x - y
    
    if z >= 0 and a >= z:
      ans += 1

print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
K,S=input().split()
k=int(K)
s=int(S)
L=0
for i in range(0,k+1):
    X=i
    if 0<int(S)-X<k*2:
        for j in range(0,k+1):
            Y=j
            Z=s-(X+Y)
            if 0<=Z<=k:
                L=L+1
            else:
                L=L
    if s-X==0 or s-X==k*2:
        L=L+1
    else:
        L=L
print(L)

Submission status: Accepted

Solution code:
K,S=input().split()
k=int(K)
s=int(S)
L=0
for X in range(0,k+1):
    for Y in range(0,k+1):
        Z=s-(X+Y)
        if 0<=Z<=k:
            L+=1
        
print(L)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
k, s = map(int, input().split())
# calc
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= (s - x - y) <= k:
            ans += 1
# output
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k,s = (int(_) for _ in 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)

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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) and (s-x-y <= k):
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s = map(int, input().split())
a = (s+2)*(s+1)/2
b = (s-k+1)*(s-k)/2
c = (s-2*k)*(s-2*k-1)/2

if s <= k:
    print(int(a))
elif s <= 2*k+1:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


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


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# Sum of Three Integers

"""
    2 ≦ K ≦ 2500
    0 ≦ S ≦ 3K
    K, S は整数である。
"""

test = False

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


def scan(k, s):
    """
    x, y の値を動かすと z は一意に定まる。
    """
    counter = 0

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

        for y in range(K+1):
        # y = 0,1,2,…,k
            if x + y > s:
                break
            if s - x - y > k:
                continue
            if test:
                print('x = {}\ty = {}\tz = {}'.format(x, y, s-x-y))
            counter += 1

    return counter


def main():
    """
    関数に値を適用
    """
    answer = scan(K, S)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(k+1):
        z = s - i - j
        if 0<= z <= k:
            n += 1
print(n)

Submission status: Accepted

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

print(ct)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
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(i,j,s-i-j)

print(cnt)

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
ans = 0
for z in range(k+1):
  r = s-z
  if r<0:
    ans += 0
  elif r<=k:
    ans += r+1
  elif r<=2*k:
    ans += 2*k+1-r
print(ans)