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())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
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 z==S-x-y: count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
if 2<=K<=2500:
  if 0<=S<=3*K:
      for x in range(K+1):
        for y in range(K+1):
          for z in range(K+1):
            if z==S-x-y:
              count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if z==S-x-y: count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
      if x<=S:
        X_=[]
        X_.append(x)
        for y in Y:
          if y<=S:
            X_Y_=list(X_)
            X_Y_.append(y)
            wa_=sum(X_Y_)
            wa.append(wa_)
    wa= [w for w in wa if w<=S]
    for z in Z:
      if z<=S:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        X_=[]
        X_.append(x)
        for y in Y:
            X_Y_=list(X_)
            X_Y_.append(y)
            wa_=sum(X_Y_)
            wa.append(wa_)
    wa= [w for w in wa if w<=S]
    for z in Z:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    wa_=sum(X_Y_)
                    wa.append(wa_)
    for z in Z:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    wa_=sum(X_Y_)
                    wa.append(wa_)
    wa= [w for w in wa if w<=S]
    for z in Z:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    wa_=sum(X_Y_)
                    wa.append(wa_)
    for z in Z:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=list(X_Y_)
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=list(X_Y_)
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=list(X_Y_)
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    print(len([c for c in wa if c==S]))

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=X_.copy()
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=X_Y_.copy()
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    print(len([c for c in wa if c==S]))

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                X_Y_=[]
                X_Y_=X_.copy()
                X_Y_.append(y)
                for z in Z:
                    X_Y_Z_=X_Y_.copy()
                    X_Y_Z_.append(z) 
                    wa_=sum(X_Y_Z_)
                    wa.append(wa_)
    print(len([c for c in wa if c==S]))

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        X_=[]
        X_.append(x)
        for y in Y:
            X_Y_=[]
            X_Y_=X_.copy()
            X_Y_.append(y)
            for z in Z:
                X_Y_Z_=X_Y_.copy()
                X_Y_Z_.append(z) 
                wa_=sum(X_Y_Z_)
                wa.append(wa_)
    print(len([c for c in wa if c==S]))

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        X_=[]
        X_.append(x)
        for y in Y:
            X_Y_=[]
            X_Y_=X_.copy()
            X_Y_.append(y)
            for z in Z:
                X_Y_Z_=X_Y_.copy()
                X_Y_Z_.append(z) 
                wa_=sum(X_Y_Z_)
                wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

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

a = []

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            a.append(x+y+z)


print(a.count(s))

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

print(a)

Submission status: Time Limit Exceeded

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

a = 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:
                a+=1
            else:
                continue

print(a)

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 i in range(k+1):
    for j in range(k+1):
            if s-(i+j) in range(k+1):
                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:
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 s == x+y+z:
                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):
  if i*3==S:
    ans+=1
  for j in range(i+1,K+1):
    if i+2*j==S:
      ans+=3
    elif i*2+j==S:
      ans+=3
    for k in range(j+1,K+1):
      if i + j + k==S:
        ans+=6
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:
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())
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 itertools

K,S = map(int, input().split())
X = list(range(K+1))
count=0

for x,y in list(itertools.product(X, X)):
    if x+y <= S and x+y+K>=S:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:

import itertools

K,S = map(int, input().split())
X = list(range(K+1))
count=0

for x,y,z in list(itertools.product(X, X, X)):
    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())
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 i in range(k + 1):
    x = i
    for j in range(k + 1):
        y = j
        for l in range(k + 1):
            z = l
            if x + y + z == s:
                count += 1
print(count)

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

cnt = 0

l = itertools.product(range(0,k+1),repeat=3)

for i in l:
  if sum(i) == s:
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K,S = input().strip().split()
K,S = int(K),int(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 += 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(min(k + 1, s - x + 1)):
        for z in range(min(k + 1, s - x - y + 1)):
            if x + y + z == s:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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


print(idx)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    k,s = list(map(int, input().split()))
    count = 0
    for x,y,z in itertools.product(range(0, k+1),range(0, k+1),range(0, k+1)):
        count += 1 if x+y+z == s else 0
    print(count)


if __name__ == '__main__':
    main()

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(i,k+1):
        for k in range(j,k+1):
            if i+j+k == s:
                l = len({i,j,k})
                c += l*(l+1)//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
k,s = map(int,input().split())
c=0
for i in itertools.product(range(k+1), repeat=3):
    c += 1*(sum(i)==s)
print(c)

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 = 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
if(s == 0):
  print(1)
  exit()
elif(s == 3*k):
  print(1)
  exit()
  
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
        
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
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=input().split(" ")

number1=int(a[0])
number2=int(a[1])
n1=0
n2=0

for i in range(number1+1):
    for j in range(number1+1):
        n1=number2-int(i)-int(j)
        if n1<=number1 and 0<=n1:
            n2=n2+1

print(n2)

Submission status: Time Limit Exceeded

Solution code:
a=input().split(" ")

number1=int(a[0])
number2=int(a[1])
n1=0
n2=0

for i in range(number1+1):
    for j in range(number1+1):
        n1=number2-int(i)-int(j)
        if n1<=number1 and 0<=n1:
            n2=n2+1

print(n2)

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

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

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

        for t in range(k+1):
            if (i+j+t) == 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 t in range(k+1):
            if (i+j+t) == s:
                count += 1
                break

print(count)

Submission status: Time Limit Exceeded

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

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

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

count = 0
for x in range(K+1):
    if S-x<=2*K:
        for y in range(K+1):
            if S-x-y<=K:
                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):
        if S-x-y<=K:
            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:
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

k,s=mii()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

k, s = map(int, input().split())
permutations_lis = list(itertools.product(range(k + 1), repeat=3))
cnt = 0
for i in permutations_lis:
    if i[0] + i[1] + i[2] == s:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read

K, S = map(int, read().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>s or y>s or z>s or x+y>s or x+z>s or y+z>s:
        continue
      elif 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):
  if x>s:
    continue
  for y in range(k+1):
    if y>s:
      continue
    for z in range(k+1):
      if z>s:
        continue
      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:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    K, S = map(int, input().split())
    ret = 0
    for z in range(K+1):
        for y in range(K+1):
            if S-z-y in range(K+1):
                ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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())
N=0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X+Y+Z==S:
                N+=1
print(N)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for i in range(k+1):
  if(i>s):
    break
  for j in range(k+1):
    if(i+j>s):
      break
    for c in range(k+1):
      if(i + j + c == 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 c in range(k+1):
      if(i + j + c == s):
        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):
    if i == S:
        count += 1
        break
    for j in range(K+1):
        if (i + j) == S:
            count += 1
            break
        for m in range(K+1):
            if (i + j + m) == S:
                count += 1
                break
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 m in range(K+1):
            sub = i + j + m
            if sub == S:
                count += 1
                break
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:
import sys
input = sys.stdin.readline

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

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if k < 0 or k > K:
            continue
        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 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 i in range(k+1):
    x = k - i
    for j in range(k+1):
        y = k - j
        for l in range(k+1):
            z = k - l
            ss = x+y+z
            if ss == s:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np

K, S = map(int, input().split())
sets = []
for x in range(K+1):
    for y in range(S-K-x, S-x+1):
        if y >= 0 and y <= K:
            z = S - (x + y)
            sets.append((x, y, z))

print(len(sets))

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for i in range(k+1):
    if i > s:
        break
    for l in range(i+1):
        if i + l > s:
            break
        for j in range(l+1):
            if i + j + l == s:
                if i == j and j == l:
                    count += 1
                elif i != j and i != l and j!= l:
                    count += 6
                else:
                    count += 3 
print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for i in range(k+1):
    for l in range(i+1):
        for j in range(l+1):
            if i + j + l == s:
                if i == j and j == l:
                    count += 1
                elif i != j and i != l and j!= l:
                    count += 6
                else:
                    count += 3 
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:
        break
    for l in range(k+1):
        if i + l > s:
            break
        for j in range(k+1):
            if i + j + l == 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 l in range(k+1):
        for j in range(k+1):
            if i + j + l == 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())
 
cnt = 0
for i in range(K+1):
    flg = False
    for j in range(K+1):
        if flg == True:
            break
        for k in range(K+1):
            ijk_sum = i + j + k
            if ijk_sum == S:
                flg = True
                lim_tmp = min(K - j, k)
                cnt += lim_tmp + 1
                break
print(cnt)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
temp=[x+y+z for z in range(k+1) for y in range(k+1) for x in range(k+1)].count(s)
print(temp)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
x=[0]*k
for i in range(0,k):
  x[i]=i
x.append(k)
a=int(s/3)-1
#y=x[-a:]
count=0
for i in range(0,len(x)):
  for j in range(0,len(x)):
    if s-x[i]-x[j] in x:
      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):
    for j in range(K+1):
        for k in range(K+1):
            ijk_sum = i + j + k
            if ijk_sum == S:
                cnt +=1
                break
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):
          ijk_sum = i + j + k
          if ijk_sum == S:
              cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
k,s=map(int,input().split())
ans=0
z=[i for i in range(k+1)]
for x in range(k+1):
    for y in range(k+1):
        a=s-x-y
        if a<=k and z[bisect.bisect_left(z,a)]==a:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,input().split())
count = 0
for p in range(K+1):
    for q in range(K+1):
        for r in range(K+1):
            if p+q+r == S:
                count+=1
print(count)

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)