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:
ks = input().split()

k = int(ks[0])
s = int(ks[1])

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:
num = input().split()

k = int(num[0])
s = int(num[1])

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 
#print(x)

#xy = x + y

count =0
# p = xy[:,1]
#print(p)
# l=0
for i in range(k+1) :
    
        a = (np.arange(i,k+i+1)).reshape(k+1,1)
        bb = a +z
        #print('a:{0}'.format(a))
        #print('b:{0}'.format(bb))
        # print(a)
        count +=np.count_nonzero(bb == s)
        # l +=1
        # print(l)
print(count)

Submission status: Time Limit Exceeded

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

val=list(range(0, k+1))
n=len(val)
ans=0

for i in range(n):
    if val[i]>s:
        break
    for j in range(n):
        if val[i]+val[j]>s:
            break
        if s-(val[i]+val[j]) in val:
            ans+=1
            continue
print(ans)

Submission status: Time Limit Exceeded

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

val=list(range(0, k+1))[::-1]
n=len(val)
ans=0

for i in range(n):
    if val[i]>s:
        continue
    for j in range(n):
        if val[i]+val[j]>s:
            continue
        for k in range(n):
            if val[i]+val[j]+val[k]==s:
                ans+=1
                break
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 i in range(0,K+1):
    for j in range(0,K+1):
        for k in range(0,K+1):
            if i+j+k==S:
                count+=1
print(count)

Submission status: Time Limit Exceeded

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

count=0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        
        # 枝刈り
        if x+y>data[1]:
            break
        
        if data[0] >= (data[1]-(x+y)) >= 0:
            z = data[1]-(x+y)
            
            if x + y + z == data[1]:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
data = input().split(" ")
data = list(map(int, data))

count=0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        if data[0] >= (data[1]-(x+y)) >= 0:
            z = data[1]-(x+y)
            
            if x + y + z == data[1]:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
data = input().split(" ")
data = list(map(int, data))

count=0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        for z in range(data[0]+1):
            if x + y + z == data[1]:
                count+=1
print(count)

Submission status: Time Limit Exceeded

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

print(ret)

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:
t = input().split()
K, S = list( map(int, t) )
 
count = 0
 
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      temp = x + y + z
      if temp == 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 += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = input().split()

k = int(num[0])
s = int(num[1])

# print(k)
# print(s)

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 

xy = x + y
#print(xy)
count =0
p = xy[:,1]

# l=0
a = []
b = np.zeros(shape=(k+1,k+1))
#print(b)
for i in range(k+1) :
        a = z + xy[:,i].reshape(k+1,1)
        b = np.r_[b,a]
        #c = np.r_[b,a]
#print(b)

count =np.count_nonzero(b == s)
        # l +=1
        # print(l)
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = input().split()

k = int(num[0])
s = int(num[1])

# print(k)
# print(s)

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 

xy = x + y
#print(xy)
count =0
#p = xy[:,1].reshape(k+1,1)
#print(p)
# l=0
for i in range(k+1) :
        a =  z+ (x+y)[:,i].reshape(k+1,1)
        # print(a)
        count +=np.count_nonzero(a == s)
        # l +=1
        # print(l)
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = input().split()

k = int(num[0])
s = int(num[1])

# print(k)
# print(s)

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 

xy = x + y
#print(xy)
count =0
# p = xy[:,1]
#print(p)
# l=0
for i in range(k+1) :
        a =  z+ xy[:,i].reshape(k+1,1)
        # print(a)
        count +=np.count_nonzero(a == s)
        # l +=1
        # print(l)
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = input().split()

k = int(num[0])
s = int(num[1])

# print(k)
# print(s)

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 

xy = x + y
#print(xy)
count =0
p = xy[:,1]
#print(p)
# l=0
for i in range(k+1) :
        a =  z+ xy[:,i].reshape(k+1,1)
        # print(a)
        count +=np.count_nonzero(a == s)
        # l +=1
        # print(l)
print(count)

Submission status: Time Limit Exceeded

Solution code:
limit, result = map(int, input().split())  

sum = 0

for x in range(limit+1):
    for y in range(limit+1):
        for z in range(limit+1):
            if x + y + z == result:
                sum = sum+1
            
            
       
        
        
            
print(sum)

Submission status: Time Limit Exceeded

Solution code:
num = input().split()

k = int(num[0])
s = int(num[1])

# print(k)
# print(s)

import numpy as np

x = np.arange(k+1)
y = np.arange(k+1).reshape(k+1,1)
z = np.arange(k+1) 

xy = x + y
count =0
# l=0
for i in range(k+1) :
    for j in range(k+1) :
        a = x + xy[i][j]
        count +=np.count_nonzero(a == s)
        # l +=1
        # print(l)
print(count)

Submission status: Time Limit Exceeded

Solution code:
ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    for targetY in range(ks[0]+1):
        
        z = ks[1] - (targetX + targetY)
        
        if 0 <= z and z <= ks[0]:
            count += 1
            
    
        targetY +=1
        
    targetX +=1
        
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            z = ks[1] - (targetX + targetY)
            
            if 0 <= z and z <= ks[0]:
                count += 1
                
        
            targetY +=1
        
    targetX +=1
        
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
ks= list(map(int, input().split())) 
 
count = 0

from itertools import product

xs = range(0,ks[0]+1)
ys = range(0,ks[0]+1)
zs = range(0,ks[0]+1)

for x, y, z in product(xs, ys, zs):
  if x+y+z == ks[1]:
    count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            if targetY <= ks[0] and ks[1]-(targetX+targetY+ks[0]) <= 0:
        
                for targetZ in range(ks[0]+1):
                    
                    if targetZ <= ks[0]:
                        
                        if targetX + targetY + targetZ == ks[1]:
                            count +=1
                    
                    targetZ +=1
                    
                    
        
            targetY +=1
        
    targetX +=1
        
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
c = input() #print(c)
ini = c.split() #print(ini[1])
k = int(ini[0]) #k
s = int(ini[1]) #s

count = 0
#print('k:{0} s:{1}'.format(k, s))
def loop():
    count = 0
    for z in reversed(range(k+1)):
        if z + k*2 < s :
            break
        for y in reversed(range(k+1)):
            if z + k*2 < s :
                break
            for x in reversed(range(k+1)):
                if x + y + z == s:
                    count +=1
                    break
    return count

count = loop()
#print('count = {0}'.format(count))
print(count)

Submission status: Time Limit Exceeded

Solution code:
c = input() #print(c)
ini = c.split() #print(ini[1])
k = int(ini[0]) #k
s = int(ini[1]) #s

count = 0
#print('k:{0} s:{1}'.format(k, s))
def loop():
    count = 0
    for z in reversed(range(k+1)):
        for y in reversed(range(k+1)):
            if z + k*2 < s :
                break
            for x in reversed(range(k+1)):
                if x + y + z == s:
                    count +=1
                    break
    return count

count = loop()
#print('count = {0}'.format(count))
print(count)

Submission status: Time Limit Exceeded

Solution code:
c = input() #print(c)
ini = c.split() #print(ini[1])
k = int(ini[0]) #k
s = int(ini[1]) #s
count = 0
#print('k:{0} s:{1}'.format(k, s))

for z in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        if z + k*2 < s :
            break
        for x in reversed(range(k+1)):
            if x + y + z == s:
                count +=1
                break
            
#print('count = {0}'.format(count))
print(count)

Submission status: Time Limit Exceeded

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

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            if targetY <= ks[0] and ks[1]-(targetX+targetY+ks[0]) <= 0:
        
                for targetZ in range(ks[0]+1):
                
                    if targetZ <= ks[0]:
                        
                        if targetX + targetY + targetZ == ks[1]:
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

print(count)

Submission status: Time Limit Exceeded

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

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            if targetY <= ks[0]:
        
                for targetZ in range(ks[0]+1):
                
                    if targetZ <= ks[0]:
                        
                        if targetX + targetY + targetZ == ks[1]:
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

print(count)

Submission status: Time Limit Exceeded

Solution code:
c = input() #print(c)
ini = c.split() #print(ini[1])
k = int(ini[0]) #k
s = int(ini[1]) #s
count = 0
#print('k:{0} s:{1}'.format(k, s))

for z in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        for x in reversed(range(k+1)):
            if x + y + z == s:
                count +=1
                break
            
#print('count = {0}'.format(count))
print(count)

Submission status: Time Limit Exceeded

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

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[0]+1):
    
    if targetX <= ks[0]:
    
        for targetY in range(ks[0]+1):
            
            if targetY <= ks[0]:
        
                for targetZ in range(ks[0]+1):
                
                    if targetZ <= ks[0]:
                        
                        if targetX + targetY + targetZ == ks[1]:
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

print(count)

Submission status: Time Limit Exceeded

Solution code:
c = input() #print(c)
ini = c.split() #print(ini[1])
k = int(ini[0]) #k
s = int(ini[1]) #s
count = 0
#print('k:{0} s:{1}'.format(k, s))

for z in range(k+1):
    for y in range(k+1):
        for x in range(k+1):
            if x + y + z == s:
                count +=1
                #break
            
#print('count = {0}'.format(count))
print(count)

Submission status: Time Limit Exceeded

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

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[1]+1):
    
    if targetX <= ks[0]:
    
        for targetY in range(ks[1]+1):
            
            if targetY <= ks[0]:
        
                for targetZ in range(ks[1]+1):
                
                    if targetZ <= ks[0]:
                        if targetX + targetY + targetZ == ks[1]:
                        
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

#print(ks)
print(count)

Submission status: Time Limit Exceeded

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

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[1]+1):
    
    for targetY in range(ks[1]+1):
    
        for targetZ in range(ks[1]+1):
        
            if targetX <= ks[0] and targetY <= ks[0] and targetZ <= ks[0] and 0 <= targetX:
                if targetX + targetY + targetZ == ks[1]:
                
                    count +=1
            
            targetZ +=1
    
        targetY +=1
        
    targetX +=1
        

#print(ks)
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())
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 : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=S and X<=K):
    while(X+Y<=S and Y<=K):
        if 0 <= S-X-Y <=K:
            result +=1
        # Z = S-X-Y
        # # print("XYZ",X,Y,Z)
        # if X+Y+Z == S:
        #     if  Z<=K :
        #         result+=1 
        Y+=1
    Y=0
    X+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=S and X<=K):
    while(X+Y<=S and Y<=K):
        Z = S-X-Y
        # print("XYZ",X,Y,Z)
        if X+Y+Z == S:
            if  Z<=K :
                result+=1 
        Y+=1
    Y=0
    X+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=S):
    while(X+Y<=S):
        Z = S-X-Y
        # print("X,Y,Z",X,Y,Z)
        if X+Y+Z == S:
            if X<=K and Y<=K and Z<=K :
                result+=1 
        # Z=X+Y-S
        # if X+Y+Z==S:
        #     result +=1
        # while(Z<=K):
        #     if X+Y+Z<S:
        #         pass
        #     elif X+Y+Z==S:
        #         result +=1
        #     else:
        #         break
        #     Z+=1
        # if X+Y+Z>S:
        #     break
        if Y<K:
            Y+=1
        else:
            break
    if X<K:
        Y=0
        X+=1
    else:
        break

print(result)

Submission status: Time Limit Exceeded

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=S):
    while(X+Y<=S):
        Z = S-X-Y
        # print("X,Y,Z",X,Y,Z)
        if X+Y+Z == S:
            if X<=K and Y<=K and Z<=K :
                result+=1 
        # Z=X+Y-S
        # if X+Y+Z==S:
        #     result +=1
        # while(Z<=K):
        #     if X+Y+Z<S:
        #         pass
        #     elif X+Y+Z==S:
        #         result +=1
        #     else:
        #         break
        #     Z+=1
        # if X+Y+Z>S:
        #     break
        if Y<=K:
            Y+=1
        else:
            break
    Y=0
    X+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=S):
    while(X+Y<=S):
        Z = S-X-Y
        if X+Y+Z == S:
            if X<=K and Y<=K and Z<=K :
                result+=1 
        # Z=X+Y-S
        # if X+Y+Z==S:
        #     result +=1
        # while(Z<=K):
        #     if X+Y+Z<S:
        #         pass
        #     elif X+Y+Z==S:
        #         result +=1
        #     else:
        #         break
        #     Z+=1
        # if X+Y+Z>S:
        #     break
        Y+=1
    Y=0
    X+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
print(sum([1 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 : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=K):
    while(Y<=K):
        while(Z<=K):
            # print("X,Y,Z",X,Y,Z)
            if X+Y+Z<S:
                pass
            elif X+Y+Z==S:
                result +=1
            else:
                break
            Z+=1
        Z=0
        Y+=1
        if X+Y+Z>S:
            break
    Y=0
    X+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
while(X<=K):
    while(Y<=K):
        while(Z<=K):
            if X+Y+Z<S:
                pass
            elif X+Y+Z==S:
                result +=1
            else:
                break
            Z+=1
        Z=0
        Y+=1
    Y=0
    X+=1
print(result)

Submission status: Time Limit Exceeded

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

# a = []
ans = 0
for i in range(K + 1):
    for j in range(i + 1):
        for k in range(j + 1):
            # print(i, j, k)
            if i + j + k == S:
                # print(i, j, k)
                # tmp = [i, j, k]
                # a.append(tmp)
                if i == j and j == k:
                    ans += 1
                elif i == j or j == k:
                    ans += 3
                else:
                    ans += 6

print(ans)

Submission status: Time Limit Exceeded

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

a = []
ans = 0
for i in range(K + 1):
    for j in range(i + 1):
        for k in range(j + 1):
            # print(i, j, k)
            if i + j + k == S:
                tmp = [i, j, k]
                a.append(tmp)

                length = len(set(tmp))
                if length == 3:
                    ans += 6
                elif length == 2:
                    ans += 3
                else:
                    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

# 三重ループ？
# x,y,z の最大値はK

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

#これは立方体の中のどこか一点を選ぶ問題とみなせる
#その中で選ばれた座標の各要素の和が、Sに等しければ良い
#点の総和は(K+1)*3個あり（※ゼロを含むから）、それらが選択可能なx,y,zの集合である
#x,y,zの和がSに達しない場合は、Sを満たす集合はその立方体の外側にある

L=[]
counter=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            L.append([x,y,z])
            if (S==x+y+z):counter+=1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
Num , Sum =  map(int,input().split())
count = 0
check = 0

for x in range(Num+1):
    for y in range ( Num+1 ):

        if (Sum - x)  >  Num * 2:
            break
        elif 0 <= (Sum - x ) - y <= Num :
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
Num , Sum =  map(int,input().split())
count = 0

for x in range(Num+1):
    for y in range (Num+1):
        for z in range (Num+1):
            if Sum == x + y + z :
                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):
      total = x + y + z
      if total == 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+=1
print(cnt)

Submission status: Time Limit Exceeded

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

res = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            three_sum = i + j + k
            if S == three_sum:
                res += 1

print(res)

Submission status: Time Limit Exceeded

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

sum_list = [(i+j+k) == S for k in range(K+1) for j in range(K+1) for i in range(K+1)]

print(sum(sum_list))

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

L = [x + y + z
    for z in range(K+1)
    for y in range(K+1)
    for x in range(K+1)
    ]
print (L.count(S))

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

k, s = na()
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
                                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k, s = list(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:
import bisect
def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1
    
K,S =  list(map(int,input().split()))
sum_list = [i+j for i in range(0,K+1) for j in range(0,K+1)]

cnt = 0
for X in range(0,K+1):
    ans = index(sum_list,S-X)
    if ans == -1:
      continue
    else:
      cnt += sum_list.count(sum_list[ans])
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1
    
K,S =  list(map(int,input().split()))
sum_list = [i+j for i in range(0,K+1) for j in range(0,K+1)]

cnt = 0
for X in range(0,K+1):
    ans = index(sum_list,S-X)
    if ans == -1:
      continue
    cnt += sum_list.count(sum_list[ans])
      
print(cnt)

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:
#ABC051b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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):
            #print(x, y, z)
            if (x + y + z == s):
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools

max_range, sum_ = map(int, input().split())

count = 0
for x, y, z in itertools.combinations_with_replacement(range(max_range + 1), r=3):
    if x + y + z == sum_:
        len_set = len({x, y, z})
        if len_set == 1:
            count += 1
        elif len_set == 2:
            count += 3
        else:
            count += 6

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

max_range, sum_ = map(int, input().split())

count = 0
for x, y, z in itertools.product(range(max_range + 1), repeat=3):
    if x + y + z == sum_:
        count += 1
print(count)

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

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

print(counter)

Submission status: Time Limit Exceeded

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

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

print(counter)

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

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
counter = 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:
        counter += 1
      if x+y+z > S:
        break
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    if s >= x:
        for y in range(k + 1):
            if s >= x + y:
                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().rstrip("\n").split())
print(sum([x + y + z == s for x in range(k + 1) for y in range(k + 1) for z in range(k + 1)]))

Submission status: Time Limit Exceeded

Solution code:
import itertools as itr

k, s = map(int, input().rstrip("\n").split())
print(sum([sum(p) == s for p in itr.product(range(k + 1), repeat=3)]))

Submission status: Time Limit Exceeded

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