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:
#!/usr/bin/env python3
# B - Sum of Three Integers

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

Submission status: Time Limit Exceeded

Solution code:

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

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(x,k+1):
    for z in range(y,k+1):
      if x+y+z == s:
        if x != y and y != z and z != x:
          a += 6
        elif (x == y and y != z) or (x == z and z != y) or (z == y and y!= x):
          a += 3
        else:
          a += 1
        
print(a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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)

if __name__ == '__main__':
    main()

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

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

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:

def solve():
    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__":
    K, S = list(map(int, input().split()))
    solve()

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

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):
    if x+y > S:
      break
    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())
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())

z = list(range(0,K+1))
answer = []

for i in z:
  s_z = S - i
  if K < s_z:
    for x in list(range(s_z - K,K+1)):
      y = s_z - x
      answer.append([x, y, z])

  else:
    for x in list(range(0,s_z+1)):
      y = s_z - x
      answer.append([x, y, z])

print(len(answer))

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

Submission status: Time Limit Exceeded

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

ans=0
X=0
while X<=K:
    Y=0
    while Y<=K:
        Z=S-(X+Y)
        if 0<=Z and Z<=K:
            ans+=1
        Y+=1
    X+=1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
X=0
while X<=K:
    Y=0
    while Y<=K:
        Z=S-(X+Y)
        if 0<=Z<=K:
            ans+=1
        Y+=1
    X+=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())
c = 0
for x in range(K + 1):
    for y in range(x + 1):
        if x + y > S:
            break
        for z in range(y + 1):
            if x + y + z > S:
                break
            if x + y + z == S:
                if x != y and x!= z and y!= z:
                    c += 6
                elif x == y and x == z and y == z:
                    c += 1
                else:
                    c += 3
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for x in range(k+1):
    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())
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 x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1
            elif x + y + z > s:
                break
        if x + y > s:
            break
    if x > s:
        break
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:
limit, sum_xyz = map(int, input().split())

pair = list()

for x in range(limit + 1):
    for y in range(limit + 1):
        z = sum_xyz - x - y
        if z < 0 or z > limit:
            continue
        else:
            pair.append([x, y, z])
ans = len(pair)

print(ans)

Submission status: Time Limit Exceeded

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

pair = list()

for x in range(limit + 1):
    y_limit = 0
    for y in range(limit + 1):
        z = sum_xyz - x - y
        if z < 0 or z > limit:
            continue
        pair.append([x, y, z])
ans = len(pair)

print(ans)

Submission status: Time Limit Exceeded

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

pair = list()
x_bottom = sum_xyz - 2*limit
x_bottom = 0 if x_bottom < 0 else x_bottom

for i in range(limit, x_bottom - 1, -1):
    x = i
    y_limit = 0
    if sum_xyz - x >= limit:
        y_limit = limit
    else:
        y_limit = sum_xyz - x
    y_bottom = sum_xyz - x - limit
    y_bottom = 0 if y_bottom < 0 else y_bottom

    for j in range(y_limit, y_bottom - 1, -1):
        y = j
        z = sum_xyz - x - y
        pair.append([x, y, z])
ans = len(pair)

print(ans)

Submission status: Time Limit Exceeded

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

for X in range(K+1):
    for Y in range(K+1):
        Z = S - X - Y
        if X + Y > S:
            break
        elif Z > K:
            continue
        else:
            if X + Y + Z == S:
                cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

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

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

        if X + Y > S:
            break
        elif Z <= K:
            if X + Y + Z == S:
                cnt +=1
        else:
            continue

print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0

for a in range(0, k+1):
    for b in range(0, k+1):
        for c in range(0, k+1):
            if a+b+c == s:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

print(sum([1 for xyz in itertools.product(range(K + 1), repeat=3) if sum(xyz) == S]))

Submission status: Time Limit Exceeded

Solution code:
'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。

'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np


def main():
    '''メイン処理'''
    k, s = map(int, input().split())

    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        if x > s:
            # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
            break

        for y in range(k+1):
            if x+y > s:
                # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                break

            for z in range(k+1):
                if (x+y+z) == s:
                    counter += 1
                elif (x+y+z) > s:
                    # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                    break

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()

Submission status: Time Limit Exceeded

Solution code:
'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。

'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np


def main():
    '''メイン処理'''
    k, s = list(map(int, input().split()))

    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        for y in range(k+1):
            if x+y > s:
                # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                break

            for z in range(k+1):
                if (x+y+z) == s:
                    counter += 1
                elif (x+y+z) > s:
                    # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                    break

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()

Submission status: Time Limit Exceeded

Solution code:
'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。



'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np


def main():
    '''メイン処理'''
    k, s = list(map(int, input().split()))

    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if (x+y+z) == s:
                    counter += 1

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()

Submission status: Time Limit Exceeded

Solution code:
'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。



'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np

is_debug = False


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

def main():
    '''メイン処理'''
    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if (x+y+z) == s:
                    if is_debug:
                        print(x,y,z)
                    counter += 1

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
cnt=0
for i in range(K+1):
    for t in range(i,K+1):
        for s in range(t,K+1):
            if i+t+s==S:
                if i==t==s:
                    cnt+=1
                elif i==t or i==s or t==s:
                    cnt+=3
                else:
                    cnt+=6
            else:
                continue
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

pair = list()
for i in range(limit, -1, -1):
    x = i
    for j in range(limit, -1, -1):
        y = j
        if y < sum_xyz - limit - x or sum_xyz - x - y < 0:
            continue
        z = sum_xyz - x - y
        pair.append([x, y, z])

print(len(pair))

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

Submission status: Time Limit Exceeded

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

print(len(ans))

Submission status: Time Limit Exceeded

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

answer = 0

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

print(answer)

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

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

Submission status: Time Limit Exceeded

Solution code:
def actual(K, S):
    my_range = lambda n: range(n + 1)

    count = 0

    for x in my_range(K):
        for y in my_range(K):
            for z in my_range(K):
                if x + y + z == S:
                    count += 1

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

print(actual(K, S))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

k, s = map(int, input().split())
A = [i for i in range(k+1)]
ans = 0
for x,y,z in itertools.combinations_with_replacement(A, 3):
  if x+y+z == s:
    n = 0
    if len(set([x,y,z])) == 1:
      n = 1
    elif len(set([x,y,z])) == 2:
      n = 3
    elif len(set([x,y,z])) == 3:
      n = 6
    ans += n
print(ans)

Submission status: Time Limit Exceeded

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

res = 0

for x in range(K+1):
  if x > S: continue
  for y in range(K+1):
    if x+y > S: continue
    for z in range(K+1):
      if x+y+z > S: continue
      if x + y + z == S:
        res += 1

print(res)

Submission status: Time Limit Exceeded

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

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

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):
            d = i + j + l
            if d == s:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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 j+i+l == s:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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 math
K,S = map(int, input().split())
n = 0
up = math.floor(K)
for i in range(up+1):
    for j in range(i,up+1):
        for k in range(j,up+1):
            if i==j and j==k:
                same=1
            elif (i==j and j!=k)or(j==k and i!=j) or(k ==i and i!=j):
                same =3
            else:
                same =6
            if i+j+k ==S:
                n=n+same
            else:
                n =n

print(n)

Submission status: Time Limit Exceeded

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

for i in range(K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                same=1
            elif (i==j and j!=k)or(j==k and i!=j) or(k ==i and i!=j):
                same =3
            else:
                same =6
            if i+j+k ==S:
                n=n+same
            else:
                n =n

print(n)

Submission status: Time Limit Exceeded

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

print(n)

Submission status: Time Limit Exceeded

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


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

print(n)

Submission status: Time Limit Exceeded

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

from itertools import product

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

Submission status: Time Limit Exceeded

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

data = [i for i in range(k + 1)]
# print(data)
dd = itertools.product(data, repeat=3)
# print(dd)
dd = list(dd)

ans = 0
for i in dd:
    #print(sum(i))
    if (sum(i) == 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())

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

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split() )
cnt = 0
for x in range(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:
#!/usr/bin/env python3
import sys
 
 
def solve(K: int, S: int):
    cnt = 0
    for a in range(K + 1):
        for b in range(K + 1):
            for c in range(K + 1):
                if a + b + c == S:
                    cnt += 1
    print(cnt)
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt = 0
    for a in range(K + 1):
        for b in range(K + 1):
            for c in range(K + 1):
                if a + b + c == S:
                    cnt += 1
                if a + b + c > S:
                    break
            if a + b > S:
                break
        if a > S:
            break
            
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt = 0
    for a in range(K + 1):
        for b in range(K + 1):
            for c in range(K + 1):
                if a + b + c == S:
                    cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S = (int(x) for x in input().split())
count = 0

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


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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

X = []


def dfs(A):
    if len(A) == 3:
        if A[0] + A[1] + A[2] == S:
            X.append(A.copy())
        return
    for i in range(K + 1):
        A.append(i)
        dfs(A)
        A.pop()


dfs([])
print(len(X))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    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(S-x+1):
        if y <= K:
            z = S - x - y
            if z >= 0 and z <= K:
                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:
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):
            if i+j+m == s:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    memo = [[-1] * (S + 1) for _ in range(4)]

    def dfs(cur, s=0):
        if ~memo[cur][s]:
            return memo[cur][s]

        if cur == 3:
            ret = int(s == S)
            memo[cur][s] = ret
            return ret

        ret = 0
        for r in range(min(K, S - s) + 1):
            ret += dfs(cur + 1, s + r)
        memo[cur][s] = ret
        return ret

    ans = dfs(0)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    def dfs(cur, s=0):
        if cur == 3:
            return int(s == S)

        ret = 0
        for r in range(min(K, S - s) + 1):
            ret += dfs(cur + 1, s + r)
        return ret

    ans = dfs(0)

    print(ans)


if __name__ == '__main__':
    main()

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