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: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
ans=0
l=[i for i in range(K+1)]
for x in range(K+1):
  for y in range(K+1):
    if (S-x-y in l)==True:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
ans=0
for z in range(0,K+1):
  for y in range(0,z+1):
    for x in range(0,y+1):
      if x+y+z==S:
        if x==y==z:
          ans+=1
        elif x!=y!=z:
          ans+=6
        else:
          ans+=3
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(K+1):
    x = i
    for j in range(K+1):
        y = j
        for k in range(K+1):
            z = k
            if x + y + z == S:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    k, s = map(int, input().split())
    c = 0
    for x in range(k + 1):
        for y in range(k + 1):
            for z in range(k + 1):
                if x + y + z == s:
                    c += 1
    return c


if __name__ == "__main__":
    print(solve())

Submission status: Time Limit Exceeded

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

for i in range(k + 1):
    for j in range(k + 1):
        if s - i - j in range(k + 1):
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(k + 1):
    for j in range(k + 1):
        for n in range(k + 1):
            if i + j + n == s:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

print(len([i for i in range(k+1)  for j in range(k+1)  for l in range(k+1) if i+j+l==s] ))

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int, input().rstrip().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(count)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

print(sum([len(set(itertools.permutations(l, 3))) for l in itertools.combinations_with_replacement(list(range(K+1)), 3) if sum(l) == S]))

Submission status: Time Limit Exceeded

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

R = 0

for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X + Y + Z == S:
                R += 1

print(R)

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

same_all = 0
same_two = 0
same_none = 0
K += 1

for i in range(1, K):
    if(i == S):
        same_two += 1
        
    for j in range(i,K):
        if (i + j == S):
            if (i == j):
                same_two += 1
            else:
                same_none += 1
            
        for k in range(j,K):
            if (i + j + k == S):
                if (i == j) and (j == k):
                    same_all += 1
                elif (i == j) or (j == k) or (i == k):
                    same_two += 1
                else:
                    same_none += 1                 

print(same_all + same_two*3 + same_none*6)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 0

for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                res += 1
                break

print(res)

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int,input().split())
x = list(range(k+1))
y = list(range(k+1))
z = list(range(k+1))
count = 0
for i in range(k+1):
    for j in range(k+1):
        if (s - (x[i] + y[j])) in z:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
count = 0
if K*3 < S:
    print(count)
else:
    for i in range(K, -1, -1):
        X = i
        for j in range(K, -1, -1):
            Y = j
            Z = S - (X + Y)
            if Y > K or Z > K:                
                continue
            elif Z < 0:
                continue
            else:
                count += 1
                #print(X, Y, Z)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

def solve(K, S):
    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 = count + 1
                if x + y + z > S:
                    break
    return count


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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

kouho_list = []

for x in range(k+1):
	for y in range(k+1):
		for z in range(k+1):
			tmp_sum = x + y + z
			if tmp_sum == s:
				kouho_list.append(tmp_sum)

print(len(kouho_list))

Submission status: Time Limit Exceeded

Solution code:
import bisect
K,S = map(int, input().split())
Z = [i for i in range(0,K+1)]
XY = []
for i in range(0,K+1):
    for j in range(0,K+1):
        XY.append(i+j)
cnt = 0
for xy in XY:
    rest = S - xy
    i = bisect.bisect_left(Z, rest)
    if i < len(Z) and Z[i] == rest:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a+b+c == S:
                count =count +1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

ans = 0

for x in range(k+1):
  if x > s:
    break
  for y in range(k+1):
    if x + y > s:
      break
    for z in range(k+1):
      if x + y + z > s:
        break
      if x+y+z == s:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for kx in range(0, k+1):
    for ky in range(0, k+1):
        kz = s - kx -ky
        if 0 <= kz <= k and kx + ky + kz == s:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for kx in range(0, k+1):
    for ky in range(0, k+1):
        kz = s - kx -ky
        if kx + ky + kz == s and 0 <= kz <= k:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
K, S = list(map(int, input().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(count)

Submission status: Time Limit Exceeded

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

ans = 0

num_list = [i for i in range(k+1)]
num_list2 = [i+j for i in range(k+1) for j in range(k+1)]

for num in num_list2:
    l, r = 0, k
    t = s - num
    while l <= r:
        m = (l+r) // 2
        if num_list[m] == t:
            ans += 1
            break
        elif num_list[m] < t:
            l = m + 1
        elif num_list[m] > t:
            r = m - 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for x in range(0, k+1):
    for y in range(x, k+1):
        for z in range(y, k+1):
            if x+y+z == s:
                if x == y == z:
                    ans += 1
                elif x != y != z != x:
                    ans += 6
                else:
                    ans += 3

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
c=0
for l in range(k+1):
    for m in range(k+1):
        for n in range(k+1):
            if l+m+n==s:c+=1
            else:pass
print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
k,s=map(int,input().split())
sati=0
for i in range(k+1):
  for j in range(k+1):
    for z in range(k+1):
      suma=i+j+z
      if suma==s:
        sati+=1
      suma=0
print(sati)

Submission status: Time Limit Exceeded

Solution code:
import sys
#n=int(input())
k,s=map(int,input().split())
sati=0
for i in range(k+1):
  for j in range(k+1):
    for z in range(k+1):
      suma=i+j+z
      if suma==s:
        sati+=1
      suma=0
print(sati)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for x in range(K+1):

    for y in range(x+1):

        for z in range(y+1):


            if x + y + z == S:

                #print(x,y,z)

                if x == y and y == z:

                    ans += 1

                elif x == y or y == z:

                    ans += 3

                else:

                    ans += 6

print (ans)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,input().split())
count = 0
#f = 0                                                                         
waru = S // 3
#print('waru{}'.format(waru))                                                  
if waru*3 >= S:
    for x in range(waru,K+1):
        for y in range(waru,K+1):
            for z in range(waru,K+1):
                if x+y+z == S:
#                    print('1{}{}{}'.format(x,y,z))                            
                    count += 1
                #               f = 1                                          
                    break

    print(count)
else:
    for x in range(0,K+1):
        for y in range(0,K+1):
            for z in range(0,K+1):
                if x+y+z == S:
 #                   print('2{}{}{}'.format(x,y,z))                            
                    count += 1
                    break

    print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,input().split())
count = 0
#f = 0                                                                         
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z == S:
#                print('{}{}{}'.format(x,y,z))                                 
                count += 1
 #               f = 1                                                         
                break

print(count)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

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

count= 0

Z1 = [i for i in range(K+1)]

for i in range(K+1):# X
  for j in range(K+1):#Y
    Z = S - i - j
    if Z in Z1:
      count += 1

print(count)

Submission status: Time Limit Exceeded

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

res = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

#+++++
		
def main():
	k, s = map(int, input().split())
	c=0
	for x in range(k+1):
		for y in range(k+1):
			for z in range(k+1):
				c+=1 if x+y+z==s else 0
	
	print(c)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

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

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            calc = x + y + z
            if calc > S:
                break
                print(ans)
            if calc == S:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            calc = x + y + z
            if calc == S:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
x=0
m=min(s+1,k+1)
for a in range(m):
  for b in range(m):
    if a+b>s:
      break
    for c in range(m):
      if a+b+c==s:
        x+=1
        break
print(x)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
x=0
for a in range(k+1):
  if a>s:
    break
  for b in range(k+1):
    if a+b>s:
      break
    for c in range(k+1):
      if a+b+c==s:
        x+=1
print(x)

Submission status: Time Limit Exceeded

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

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

print(counter)

Submission status: Time Limit Exceeded

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

x=0
y=0
z=0
s=0
while x<k+1:
    while y<k-x+1:
        if(x+y>n):
            break
        
        if n-x-y<k:
            s+=1
            break
print(s)

Submission status: Time Limit Exceeded

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

x=0
y=0
z=0
s=0
bx=True
by=True
bz=True

while x<k+1 and bx:
    while y<k-x+1 and by:
        if(x+y>n):
            break
        while z<k-x-y:
            if x+y+z==n:
                s+=1
                break
print(s)

Submission status: Time Limit Exceeded

Solution code:
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
                #print("{} {} {}".format(x, y, z))
                if  0 <= z <= k and x + y + z == s:
                        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
K,S = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for X in range(0,K+1):
    for Y in range(0,K+1):
        for Z in range(0,K+1):
            if X+Y+Z == S:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(k + 1):
  for j in range(k + 1):
    for l in range(k + 1):
      if i + j + l == s:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(k + 1):
  for j in range(k + 1):
    for k in range(k + 1):
      if i + j + k == s:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

lst = []
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x+y+z==s:
                lst.append((x,y,z))

cnt = 0
for e in lst:
    l = len(set(e))
    if l == 1:
        cnt += 1
    elif l == 3:
        cnt += 6
    else:
        cnt += 3

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
row = input().split()
K = int(row[0])
S = int(row[1])
count = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if S == x+y+z:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n+1):
    if i == s:
        count += 1
        break
    elif i > s:
        break
    for j in range(n+1):
        if i+j == s:
            count += 1
            break
        elif i+j > s:
            break
        for k in range(n+1):
            if i+j+k == s:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n+1):
    if i == s:
        count += 1
        break
    for j in range(n+1):
        if i+j == s:
            count += 1
            break
        for k in range(n+1):
            if i+j+k == s:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i+j+k == s:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
K, S = [int(n) for n in input().split()]
print(sum([1 for X in range(K+1) for Y in range(K+1) for Z in range(K+1) if X+Y+Z==S]))

Submission status: Time Limit Exceeded

Solution code:
K, S = [int(n) for n in input().split()]
c = 0
for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X+Y+Z == S:
        c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
ans = 0
for a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a + b + c == s:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
ans = 0
for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a + b + c == S:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x+y+z == s:
                if x==y==z:
                    cnt+=1
                elif (x==y and x!=z) or (x!=y and x==z) or (x!=y and y==z):
                    cnt+=3
                else:
                    cnt+=6
print(cnt)

Submission status: Time Limit Exceeded

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

    pattern = 0

    if s > 3 * k:
        print(pattern)
        return

    for x in range(k + 1):
        for y in range(min(k + 1, s - x + 1)):
            for z in range(min(k + 1, s - x - y + 1)):
                if x + y + z == s:
                    pattern += 1

    print(pattern)


if __name__ == "__main__":

    main()

Submission status: Time Limit Exceeded

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

    pattern = 0

    for x in range(k + 1):
        for y in range(min(k + 1, s - x + 1)):
            for z in range(min(k + 1, s - x - y + 1)):
                if x + y + z == s:
                    pattern += 1

    print(pattern)


if __name__ == "__main__":

    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

K, S = list(map(int, sys.stdin.readline().split()))

a = np.array(list(itertools.product(range(K + 1), repeat=2)))
s = a.sum(axis=1)
print(((S - K <= s) & (s <= S)).sum())

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x+y+z == s:
                if x == y and y == z:
                    count += 1
                elif x == y or y == z or x == z:
                    count += 3
                else:
                    count += 6
print(count)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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


print(c)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,input().split())
cnt = 0
for l in range(K+1):
  for m in range(K+1):
    for n in range(K+1):
      if l+m+n == S:
        cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int, input().split())
cnt=0
for i in range(K+1):
  X=i
  for j in range(K+1):
    Y=j
    for k in range(K+1):
      Z=k
      if X+Y+Z==S:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

for x in range(0,K+1):
    for y in range(0,K+1):
        for z in range(0,K+1):
            if ((x + y + z )== S):
                cnt += 1
                if((x + y + z )>S):
                    break

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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