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

result = 0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if S == X+Y+Z:
                result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
K,S=[int(i) for i in 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=[int(i) for i in 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())

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

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

print(number_of_combinations)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
K,S = (int(i) for i in input().split()) 
A=()
for i in range(K+1):
    A=A+(i,)

L=list(itertools.combinations_with_replacement(A,3))
SUM=0
for i in range(len(L)):
    if L[i][0]+L[i][1]+L[i][2]==S:
        if len(L[i]) == len(set(L[i])) + 2:
            SUM = SUM + 1  # sonomama! 3tu tyouhuku
        if len(L[i]) == len(set(L[i])) + 1:
            SUM = SUM + 3  # kakeru3 2tu tyouhuku
        if len(L[i]) == len(set(L[i])):  # kakeru6 tyouhuku 0
            SUM = SUM + 6

print(SUM)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,sum=map(int,input().split())
cnt=0

x,y,z=(0,0,0)
for i in range(n+1):
  for j in range(n+1):
    if i<=n and j<=n and sum-i-j<=n and 0<=sum-i-j:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,sum=map(int,input().split())
cnt=0

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

K, S = [int(x) for x in stdin.readline().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:
# -*- coding: utf-8 -*-
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):
            s = x + y + z
            if s == S:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def check(x, y, K, S):
  if x + y > S:
    return False
  for z in range(K+1):
    if x + y + z == S:
      return True
  return False

K, S = list(map(int, input('').split()))
count = 0
for x in range(K+1):
  for y in range(K+1):
    if check(x, y, K, S):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def check(x, y, K, S):
  for z in range(K+1):
    if x + y + z == S:
      return True
  return False

K, S = list(map(int, input('').split()))
count = 0
for x in range(K+1):
  for y in range(K+1):
    if check(x, y, 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(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 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 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 = list(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(" "))
sum = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+j+l == s:
                sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int, input().split())
S1 = 0
S2 = 0
counter = 0
for X in range(min(K,S)+1):
    S1 = S - X
    for Y in range(min(K,S1)+1):
        S2 = S1 - Y
        for Z in range(min(K,S2)+1):
            if X+Y+Z == S:
                counter += 1
                #print(X,Y,Z)
print(counter)

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:
                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
            elif x+y+z>s:
                break
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
#xがmax以下がどうかチェック
while x <= k:

#    xが合計よりおおきい
    if x > s:
        
        break
        
    y = 0
    #yがmax以下がどうかチェック
    while y <= k:
        
        
#        print(x,y,y>s,x+y>s,s-x>s*k,s-x-y>k,s-x-y,2*k)
#       yが合計より大きい　あるいは　x+yが合計より大きい
        if (y > s) or (x + y > s) or (s-x>2*k):
        
            break
            
#        if s-x-y>k:
#            
#            continue
#            
            
#        print(x,y,s-x-y,k,s-x-y<=k)    
        if s-x-y <= k:    

            cnt += 1

        y += 1

    x += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
while x <= k:

    if x > s:
        
        break
        
    y = 0
    while y <= k:
        
        if y > s or x + y > s or s-x > 2*k:
        
            break
            
#        print(x,y,s-x-y)    
        if s-x-y <= k:    

            cnt += 1

        y += 1

    x += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
while x <= k:

    if x > s:
        
        break
        
    y = 0
    while y <= k:
        
        if y > s or x + y > s :
        
            break
            
#        print(x,y,s-x-y)    
        if s-x-y<=k:    
            
            cnt+=1
            
        y += 1
    
    x += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
while x <= k:

    if x>s:
        
        break
        
    y = 0
    while y<=k:
        
        if y>s or x+y>s:
        
            break
        
        z=0
        while z<=k:
    
            
            if z>s or x+y+z>s:
                
                break
#            print(x,y,z)
            
            if x + y + z == s:
                
                cnt += 1
                break
            
            z+=1
            
        y+=1
    
    x+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
while x <= k:

    if x>s:
        
        break
        
    y = 0
    while y<=k:
        
        if y>s:
        
            break
        
        z=0
        while z<=k:
    
            
            if z>s:
                
                break
#            print(x,y,z)
            
            if x + y + z == s:
                
                cnt += 1
                break
            
            z+=1
            
        y+=1
    
    x+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt = 0
    
x = 0
while x <= k:

    if x>s:
        
        break
        
    y = 0
    while y<=k:
        
        if y>s:
        
            break
        
        z=0
        while z<=k:
    
            
            if z>s:
                
                break
#            print(x,y,z)
            
            if x + y + z == s:
                
                cnt += 1
        
            z+=1
            
        y+=1
    
    x+=1

print(cnt)
    
    
#    while(y <= k):
#    
#        while(z <= k):
#        
#            print(x, y, z)
#        

#                
#            z =  + 1        
#            
#        y =  + 1    

#    x =  + 1

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

cnt=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 or s<y or s<z:
                
                break
            
            if x+y+z==s:
                
                cnt+=1
                
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])


#print(k,s)

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 = (int(i) for i in input().split())
answer = 0
for i in range(((s-s%3)//3)+1):
	n = s-i
	for i2 in range(i,((n-n%2)//2)+1):
		for i3 in range(i2,k+1):
			if i+i2+i3==s:
				if i==i2 and i2==i3: answer += 1
				elif i==i2 or i2==i3: answer += 3
				else: answer += 6
				break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Time Limit Exceeded

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

count = 0
if int(s / 3) == 0:
    for x in range(s + 1):
        for y in range(s + 1):
            for z in range(s + 1):
                if x + y + z == s:
                    count += 1
else:
    for x in range(max(k, int(s / 3) + 1)):
        for y in range(max(k, int(s / 3) + 1)):
            for z in range(max(k, int(s / 3) + 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 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())
t=0
for i in range(k+1):
    for j in range(k+1):
        if 0<=i<=k and 0<=j<=k and 0<=s-i-j<=k:
            t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
    for i3 in range(k+1):
      if i+i2+i3==s:
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
a = raw_input().split()
K = int(a[0])
S = int(a[1])

number = []

for i in range(0,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i+j+k == S:
        number.append((i,j,k))
        number.append((i,k,j))
        number.append((j,i,k))
        number.append((j,k,i))
        number.append((k,i,j))
        number.append((k,j,i))

        
print(len(list(set(number))))

Submission status: Time Limit Exceeded

Solution code:
a = raw_input().split()
K = int(a[0])
S = int(a[1])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K,S = [int(i) for i 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 and X+Y+Z==S:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
K,S=map(int,raw_input().split())
l=list( itertools.product(range(K+1), repeat=3 ) )

cnt=0
for i,j,k in l:
	if i+j+k==S:
		cnt+=1
print cnt

Submission status: Time Limit Exceeded

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

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:
import itertools
k,s = map(int,input().split())
ans = 0
x = [i for i in range(k + 1)]
y = [i for i in range(k + 1)]
z = [i for i in range(k + 1)]
arr = list(itertools.product(x,y,z))
for i in arr:
    if sum(i) == 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:
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):
                if x + y + z == s:
                    c += 1
    print(c)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

x=0
count = 0

if S>K: n=K+1
else: n=S+1
for i in range(n):
	y=0
	while S-x>=0 and S-x<=2*K:
		if S-x-y>=0 and S-x-y<=K: count+=1
		y+=1
		if y>K: break
	x+=1
	if x>K: break

print(count)

Submission status: Time Limit Exceeded

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

x=0
count = 0

if S>K: n=K+1
else: n=S+1
for i in range(n):
	y=0
	while S-x>=0 and S-x<=2*K:
		if S-x-y>=0 and x<=K and y<=K and S-x-y<=K: count+=1
		if y>K: break
		y+=1
	x+=1

print(count)

Submission status: Time Limit Exceeded

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

x=0
count = 0

for i in range(S+1):
	y=0
	while S-x>=0:
		if S-x-y>=0 and x<=K and y<=K and S-x-y<=K: count+=1
		if y>K: break
		y+=1
	x+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
ans = 0
for X in range(min(K+1, S+1)):
    for Y in range(min(K+1, S+1)):
        for Z in range(min(K+1, S+1)):
            ans += (S - (X+Y)) == Z
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 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:
def main():
    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)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
k,s=[int(i) for i in input().split()]
count=0
for y in range(k+1):
 for x in range(k+1):
   if x + y <= s + k and s>=x+y and s<=k+x+y:
      count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
k,s=[int(i) for i in input().split()]
count=0
#print(k,s)
for y in range(k+1):
 for x in range(k+1):
   if x + y <= s + k and s-x-y>=0 and s-x-y<=k:
#      print(x,y,s-x-y)
      count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = [int(i) for i in input().split()]
ans = 0
for x in range(k, -1, -1):
    for y in range(k, -1, -1):
        for z in range(k, -1, -1):
            if x + y + z is 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 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())
count = 0
for z in range(K+1):
    for y in range(K+1):
        x = S - z - y
        if (0 <= x <= K) & (0 <= y <= K) & (0 <= z <= K):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

# sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    k, s = read_int_list()
    res = 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:
                    res += 1
    print(res)


main()

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:
a = input().split()
k = int(a[0])
s = int(a[1])
count = 0
for n1 in range(k+1):
    for n2 in range(k+1):
        for n3 in range(k+1):
            if n1+n2+n3==s:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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):
        for z in range(K+1):
            if x + y + z == S:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import queue

def count(S, K):
    c = 0
    q = queue.Queue()
    q.put((S, 0))
    s = []
    while(q.empty() == False):
        x, y = q.get()
        if x < 0:
            break
        if x <= K and y <= K and S-x-y <= K and (x, y) not in s:
            s.append((x, y))
            c += 1
        q.put((x-1, y+1))
        q.put((x-1, y))
    return c

if __name__ == "__main__":
    inp = [int(i) for i in input().split()]
    K = inp[0]
    S = inp[1]
    print(count(S, K))

Submission status: Time Limit Exceeded

Solution code:
import queue

def count(S, K):
    c = 0
    q = queue.Queue()
    q.put((S, 0, 0))
    s = []
    while(q.empty() == False):
        x, y, z = q.get()
        if x < 0:
            break
        if x <= K and y <= K and z <= K and (x, y, z) not in s:
            s.append((x, y, z))
            c += 1
        q.put((x-1, y+1, z))
        q.put((x-1, y, z+1))
    return c




if __name__ == "__main__":
    inp = [int(i) for i in input().split()]
    K = inp[0]
    S = inp[1]
    print(count(S, K))

Submission status: Time Limit Exceeded

Solution code:
K, S = list(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:
from collections import defaultdict


def main():
    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):
                ans += (x + y + z == S)
    print(ans)


if __name__ == '__main__':
    main()

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(s-x+1):
        z = s - x - y
        if x <= k and y <= k and z <= k:
            ans += 1

print(ans)

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:
import itertools
K, S = map(int, input().split())
list_ans = [(x,y,z) for x, y, z in itertools.product([w for w in range(K + 1)], repeat = 3) if ((x + y + z) == S)]
print(len(list_ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product as prod

k, s = [int(x) for x in input().split()]

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product as com
(t1,t2) = input().split()
a = int(t1)
b = int(t2)
print(len([True for i in com(range(a+1),range(a+1),range(a+1)) if sum(i) == b]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
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:
# -*- coding: utf-8 -*-
import traceback


def main():
    try:
        k,s = map(int,raw_input().split())
        if k < 2 or k > 2500:
            raise
        if s < 0 or s > k * 3:
            raise

        X = Y = Z = [i for i in range(k+1)]
        counter = 0
        for x in X:
            for y in Y:
                for z in Z:
                    if x + y + z == s:
                        counter += 1

        return counter

    except:
        #traceback.print_exc()
        return 0

print main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

if __name__ == '__main__':
    k, s = list(map(int,input().split()))

    a = 0
    for i in itertools.product(range(0, k+1), range(0, k+1), range(0, k+1)):
        if sum(i) == s:
            a += 1
    print(a)

Submission status: Time Limit Exceeded

Solution code:
K,S = [int(i) for i in raw_input().split(' ')]
print len([1 for x in xrange(K+1) for y in xrange(K+1) for z in xrange(K+1) if x+y+z == S])

Submission status: Time Limit Exceeded

Solution code:
(k,s),c=map(int,input().split()),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:
# http://abc051.contest.atcoder.jp/tasks/abc051_b
K,N=map(int,raw_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==N:
				count+=1
print count

Submission status: Time Limit Exceeded

Solution code:
n = input()
n = n.split()
K,S = map(int, n)
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:
# -*- coding:utf-8 -*-
n = input()
n = n.split()
K,S = map(int, n)

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:



def solve(k, s, x=[]):
    if len(x) < 2:
        ans = 0
        for i in range(k+1):
            nx = x.copy()
            nx.append(i)
            ans += solve(k, s, nx)
        return ans
    return 1 if 0 <= s-sum(x) <= k else 0


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