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:
import math 
[K, S] = list(map(int, input().split()))
count = 0
total = 0
for X in range(K+1):
  if X > S:
    break
  for Y in range(K+1):
    for Z in range(K+1):
      total = X + Y + Z 
      if total == S:
        count += 1
      if total > S:
        break
      if total < S/2:
        Z += math.floor(S/2)
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math 
[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):
      total = X + Y + Z 
      if total == S:
        count += 1
      if total > S:
        break
      if total < S/2:
        Z += math.floor(S/2)
            
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 0
for x in reversed(range(k+1)):
    for y in reversed(range(k+1)):
        for z in reversed(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(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:
N,M=map(int,input().split())
counter=0
for a in range(N+1):
  for b in range(N+1):
    for c in range(N+1):
      if a+b+c==M:
        counter+=1
print(counter)

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K, S = [int(n) for n in input().split(" ")]
 
cnt = 0
 
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if x+y+z == S:
        cnt +=1
 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
ans = 0
for 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:
try:
    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
                    break
    print(cnt)
except EOFError:
    pass

Submission status: Time Limit Exceeded

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

number_lis = []
ans = 0

for i in range(0,K+1):
    number_lis.append(i)

for j in number_lis:
    for k in number_lis:
        for l in number_lis:
            if (j + k + l) == S:
                ans = ans + 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k, s = [int(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        for z in range(y, k + 1):
            if z > s:
                break
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 6
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans_count = 0
for i in range(0, input[0]+1):
  for j in range(0, input[0]+1):
    for k in range(0, input[0]+1):
      if (i + j + k == input[1]):
        ans_count+=1

print(ans_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().strip().split())

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

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

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

print(str(count))

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
X = []
Y = []
Z = []
count = 0

for i in range(0, K + 1):
	X.append(i)
	Y.append(i)
	Z.append(i)

for i in range(0 ,K + 1):
	for j in range(0 ,K + 1):
		for k in range(0 ,K + 1):
			if S == X[i] + Y[j] + Z[k]:
				count += 1

print(str(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
Max, Sum = map(int, input().split())

counter = 0
for i in range(Max+1):
  for j in range(Max+1):
    for k in range(Max+1):
      if i + j + k == Sum:
        counter += 1
 
print(counter)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
K,S=map(int,input().split(" "))
answer=0
for X in range(K+1):
  for Y in range(K+1):
    if S-(X+Y)<=K and S-(X+Y)>=0:
      answer+=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
K,S=map(int,input().split(" "))
answer=0
for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X+Y+Z==S:
        answer+=1
print(answer)

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

l = []

for i in range(K + 1):
    l.append(i)

count = 0

for i in l:
    x = i
    for j in l:
        y = j
        for k in l:
            z = k
            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 i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        ans += 1
        break
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:
import itertools

"""
整数K,S
2 <= K <= 2500, 0 <= S <= 3K

0 <= X,Y,Z <= K
X + Y + Z = Sを満たすX,Y,Zの割り当ては何通り？

"""
K, S = map(int, input().strip().split(' '))
X = list(range(K + 1))
Y = list(range(K + 1))
Z = list(range(K + 1))
count = 0

for i, j, k in list(itertools.product(X,Y,Z)):
  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:
import sys

k,s = list(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, 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())
yz = []
for y in range(K+1):
  for z in range(y,K+1):
    if y == z:
      yz.append([y+z,1])
    else:
      yz.append([y+z,2])
cnt = 0
for x in range(K+1):
  for i in range(len(yz)):
    if x + yz[i][0] == S and yz[i][1] == 1:
      cnt += 1
    elif x + yz[i][0] == S and yz[i][1] == 2:
      cnt += 2
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 l 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())
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

N = input().split()
N = [int(i) for i in N]
num = [i for i in range(N[0]+1)]

count = 0

#1
for i in range(N[0]+1):
    if(3*i == N[1]):
        count += 1

l2 = list(itertools.combinations(num, 2))
l3 = list(itertools.combinations(num, 3))
#print(num)
#print(l2)

#2
for i in range(len(l2)):
    if((l2[i][0] + 2*l2[i][1]) == N[1]):
        count += 1*3
    if((l2[i][0]*2 + l2[i][1]) == N[1]):
        count += 1*3

#3
for i in range(len(l3)):
    if((l3[i][0] + l3[i][1] + l3[i][2]) == N[1]):
        count += 1*6

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input().split()
N = [int(i) for i in N]

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

Submission status: Time Limit Exceeded

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

ans = 0
for h in range(k+1):
    for i in range(k+1):
        for j in range(k+1):
            if h+i+j==s:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for h in range(k+1):
    for i in range(k+1):
        for j in range(k+1):
            if h+i+j ==s:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input().split()
N = [int(i) for i in N]

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

Submission status: Time Limit Exceeded

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

l1 = [i for i in range(K+1)]
r = 0
for i in l1:
  for j in l1:
    if S - i - j in l1:
      r += 1
print(r)

Submission status: Time Limit Exceeded

Solution code:
(k, s),  = [list(map(int, s.split())) for s in open(0)]

pairs = []
for i in range(k + 1):
    for j in range(k + 1):
        if s - i - j <= k and s - i - j >= 0 :
            l = s - i - j
            pairs.append((i, j, l))
print(len(pairs))

Submission status: Time Limit Exceeded

Solution code:
(k, s),  = [list(map(int, s.split())) for s in open(0)]

pairs = []
for i in range(k + 1):
    for j in range(k + 1):
        for l in range(k + 1):
            if i + j + l == s:
                pairs.append((i, j, l))
print(len(pairs))

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
x = [n for n in range(0, k+1)]
y = [m for m in range(0, k+1)]
z = [l for l in range(0, k+1)]
cnt = 0

for i in range(k+1):
    for j in range(k+1):
        for t in range(k+1):
            if(x[i] + y[j] + z[t] == s):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
ans = 0
if a > b:
  for x in range(b+1):
    if x > a:
      break
    for y in range(b-x+1):
      if y > a:
        break
      for z in range(b-x-y+1):
        if (x+y+z)==b:
          ans += 1
        if z > a:
          break
else:
  for x in range(a+1):
    for y in range(a+1):
      for z in range(a+1):
        if (x+y+z)==b:
          ans += 1
        if (x+y+z)>=b and (x>=b or y>=b or z>=b):
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
ans = 0
if a > b:
  for x in range(b+1):
    for y in range(b-x+1):
      for z in range(b-x-y+1):
        if (x+y+z)==b:
          ans += 1
else:
  for x in range(a+1):
    for y in range(a+1):
      for z in range(a+1):
        if (x+y+z)==b:
          ans += 1
        if (x+y+z)>=b and (x>=b or y>=b or z>=b):
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
ans = 0
if a > b:
  for x in range(b+1):
    for y in range(b-x+1):
      for z in range(b-x-y+1):
        if (x+y+z)==b:
          ans += 1
else:
  for x in range(a+1):
    for y in range(a+1):
      for z in range(a+1):
        if (x+y+z)==b:
          ans += 1
        if (x+y+z)>=b:
          continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
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:
a,b=map(int,input().split())
print([_+y+z for _ in range(a+1) for y in range(a+1) for z in range(a+1)].count(b))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
print([_+y+z for _ in range(a+1) for y in range(a+1) for z in range(a+1)].count(b))

Submission status: Time Limit Exceeded

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

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())
n = []
for i in range(K + 1):
  n.append(i)

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

print(ans)

Submission status: Time Limit Exceeded

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

n = []
for i in range(K + 1):
  n.append(i)

import itertools
XYZ = list(itertools.product(n, repeat = 3))

count = 0
for j in range(len(XYZ)):
  if sum(XYZ[j]) == S:
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

print(len(XYZ))

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
for a in range(k+1):
  for b in range(k+1):
    for c in range(k+1):
      if a + b + c == s:
        count += 1
      else:
        pass
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 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 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())
ANS=0
for i in range(K+1):
  if i > S:
    break
  for j in range(K+1):
    zz = i + j
    if zz > S:
      break
    for k in range(K+1):
      z = i + j + k
      if z == S:
        #print(i,j,k)
        ANS+=1
      elif z >= S:
        break
print(ANS)

Submission status: Time Limit Exceeded

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

n = 0

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc051/tasks/abc051_b
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:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

K, S = map(int, readline().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())
#x + y + z = s z < k
counter = 0
for i in range(k + 1):
    if i > s:
        break
    for j in range(k + 1):
        if  i + j > s :
            break
        z = s - i - j
        if 0 <= z and z <= k:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

print(counter)

Submission status: Time Limit Exceeded

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

print(counter)

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):
      total = i +j + k
      if total == S :
        num += 1
print(num)

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
K,S = map(int,input().split())
#0<=S<=3K
res = 0
for X in range(0,K+1):
    if X > S:
        break
        print(res)
        sys.exit(0)
    for Y in range(0,K+1):
        if X + Y > S:
            break
        elif (0<=(S-X-Y)) and ((S-X-Y) <= K):
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
#B - Sum of Three Integers
K,S = map(int,input().split())
#0<=S<=3K
res = 0
for X in range(0,min((K+1,S+1))):
    if X > S:
        break
    for Y in range(0,K+1):
        if X + Y > S:
            break
        elif (0<=S-X-Y) and ((S-X-Y) <= K):
            res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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:
KS = input().split()
K,S = int(KS[0]), int(KS[1])
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:
        S_count += 1
print(S_count)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int, input().split())
count = 0
for i in range(a + 1):
  for j in range(a + 1):
    for k in range(a + 1):
      if i + j + k == b:
        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):
  if i+2*k-s >=0:
    for j in range(k+1):
      if (s-(i+j)<=k)&(s-(i+j)>=0):
        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):
  if i+2*k-s >=0:
    for j in range(k+1):
      if i+j+k-s>=0:
        for h in range(k+1):
          if i+j+h ==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 h in range(k+1):
      if i+j+h ==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:
    break
  for y in range(K+1):
    if y>S:
      break
    z=S-x-y
    if 0<=z and z<=K:
      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):
  if i>S:
    break
  for j in range(K+1):
    if j>S:
      break
    for k in range(K+1):
      if k>S:
        break
      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 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())
res = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if (x + y + z) == S:
                res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
count = 0
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())
p = 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:
        p+=1
      if (x+y+z) >= s:
        break
print(p)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
p = 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:
        p+=1
print(p)

Submission status: Time Limit Exceeded

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

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

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            # print(x,y,z)
            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(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())
print([x+y+z == S for x in range(K+1) for y in range(K+1)
       for z in range(K+1)].count(True))

Submission status: Time Limit Exceeded

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

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

print(ways)

Submission status: Time Limit Exceeded

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

ways = 0

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


print(ways)

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:
import itertools
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:
li = list(map(int,input().split()))
K, S = li[0], li[1]

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 = [int(n) for n in input().split()]

def main():
    ns = set()
    for x in range(K + 1):
        for y in range(x + 1):
            z = S - x - y
            if z < 0:
                continue
            if K < z:
                continue
            t = tuple(sorted([x, y, z]))
            ns.add(t)

    ans = 0
    for t in ns:
        x = t[0]
        y = t[1]
        z = t[2]
        if x == y == z:
            ans += 1
        elif x != y != z:
            ans += 6
        else:
            ans += 3
    print(ans)

if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
k, s = map(int, input().split())
numbers = list(product([i for i in range(k+1)], repeat=2))
ans = 0
for x, y in numbers:
    if x + y > s:
        continue
    if x + y == s:
        ans += 1
    elif x + y < s:
        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())
cnt = 0
lst = []

for i in range(k+1):
    for j in range(k+1):
        lst.append(i+j)

for i in range(len(lst)):
    for j in range(k+1):
        if lst[i]==s-j:
            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 l in range(k+1):
            if i+j+l==s:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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