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().strip().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(x,y,z)
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 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()))
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 = list(map(int, input().rstrip().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:
                break

            if (x + y + z) == S:
                n += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
K, S = list(map(int, input().rstrip().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:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


"""
https://beta.atcoder.jp/contests/abc009/tasks/abc51_2
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

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

count = 0
for X in range(0, min(S + 1, K + 1)):
    for Y in range(0, min(S + 1, K + 1)):
        for Z in range(0, min(S + 1, 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):
        z=(S-x-y)
        if 0 <= z <= K and x+y+z == S:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
line = input().split()
num = int(line[0]) + 1
sum = 0
for x in range(num):
    for y in range(num):
        if -1 < int(line[1]) - (x + y) < num:
            sum += 1          
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = input().split()
num = int(line[0]) + 1
sum = 0
for x in range(num):
    for y in range(num):
        leave = int(line[1]) - (x + y)
        if -1 < leave < num:
            sum += 1          
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = input().split()
num = int(line[0]) + 1
sum = 0
for x in range(num):
    for y in range(num):
        leave = int(line[1]) -(x + y)
        if leave >= 0 and leave <= num - 1:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = input().split()
num = int(line[0]) + 1
sum = 0
for x in range(num):
    for y in range(num):
        for z in range(num):
            if x + y + z == int(line[1]):
                sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
ans=0
for i in range(a[0]+1):
    for j in range(a[0]+1):
        if a[1]-i-j < a[0]+1 and a[1]-i-j > -1:
            ans+=1
print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
ans=0
for i in range(a[0]+1):
    for j in range(a[0]+1):
        if a[0]*2<a[1]-i:
            break
        if a[1]-i-j <= a[0] and a[1]-i-j >= 0:
            ans+=1
print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
ans=0
for i in range(a[0]+1):
    for j in range(a[0]+1):
        if a[1]-i-j <= a[0] and a[1]-i-j >= 0:
            ans+=1
print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
ans=0
for i in range(a[0]+1):
    for j in range(a[0]+1):
        for k in range(a[0]+1):
            if i+j+k==a[1]:
                ans+=1
print(str(ans))

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
L=0
for i in range(0,int(K)+1):
    X=i
    for j in range(0,int(K)+1):
        Y=j
        Z=int(S)-(X+Y)
        if 0<=Z<=int(K):
            L=L+1
        
print(L)

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
L=0
for i in range(0,int(K)+1):
    X=i
    if 0<int(S)-X<int(K)*2:
        for j in range(0,int(K)+1):
            Y=j
            Z=int(S)-(X+Y)
            if 0<=Z<=int(K):
                L=L+1
            else:
                L=L
    if int(S)-X==0 or int(S)-X==int(K)*2:
        L=L+1
    else:
        L=L
print(L)

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
L=""
for i in range(0,int(K)+1):
    X=i
    if 0<int(S)-X<int(K)*2:
        for j in range(0,int(K)+1):
            Y=j
            Z=int(S)-(X+Y)
            if 0<=Z<=int(K):
                L+="A"
            else:
                L=L
    if int(S)-X==0 or int(S)-X==int(K)*2:
        L+="A"
    else:
        L=L
print(L.count("A"))

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
L=""
for i in range(0,int(K)+1):
    X=i
    if 0<=int(S)-X<=int(K)*2:
        for j in range(0,int(K)+1):
            Y=j
            Z=int(S)-(X+Y)
            if 0<=Z<=int(K):
                L+="A"
            else:
                L=L
    else:
        L=L
print(L.count("A"))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# input
k, s = map(int, input().split())
# calc
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
# output
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 = (int(_) for _ in 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 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):
    for y in range(0, k+1):
        for z in range(0, k+1):
            sum = x+y+z
            if sum==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):
    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())

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:
a = input().split(" ")
count = 0
for x in range(int(a[0])+1):
    for y in range(int(a[0])+1):
        z = int(a[1]) - (x + y)
        if z >= 0 and z <= int(a[0]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
a = input().split(" ")
count = 0
for x in range(int(a[0])+1):
    for y in range(int(a[0])+1):
        if int(a[1]) - (x + y) <= int(a[0]) and int(a[1]) - (x + y) >= 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
a = input().split(" ")
count = 0
for x in range(int(a[0])+1):
    for y in range(int(a[0])+1):
        for z in range(int(a[0])+1):
            if x + y + z == int(a[1]):
                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 h in range(k+1):
        for j in range(k+1):
            if i+h+j==s:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(s-i+1):
        if s-i-j > k:
            continue
        elif j > k:
            break
        z = s - i - j
        if 0<= z <= k:
            n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(s-i+1):
        if s-i-j > k:
            continue
        elif j > k:
            break
        for l in range(s-i-j + 1):
            if i + j + l == s:
                n += 1
            elif i + j + l > s:
                break
print(n)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(k + 1):
        if s-i-j > k:
            continue
        elif j > s:
            break
        for l in range(k + 1):
            if i + j + l == s:
                n += 1
            elif i + j + l > s:
                break
print(n)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k or i > s:
        continue
    for j in range(k + 1):
        if s-i-j > k or j > s:
            continue
        for l in range(k + 1):
            if i + j + l == s:
                n += 1
            elif i + j + l > s:
                break
print(n)

Submission status: Time Limit Exceeded

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

print(ct)

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 h 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())
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
      else:
        continue
        
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):
      t = x+y+z
      if t == s:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int, input().split())
a = b = c = d = 0
for x in range(k+1):
    if 3*x == s:
        a += 1
        break

for x in range(k+1):
    for z in range(x):
        if 2*x + z == s:
            b += 1
b *= 3
for x in range(k+1):
    for y in range(x):
        if x + 2*y == s:
            c += 1
c *= 3

for x in range(k+1):
    for y in range(x):
        for z in range(y):
            if x+y+z == s:
                d += 1
d *= 6

print(a+b+c+d)

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:
# coding: utf-8
from __future__ import unicode_literals
from __future__ import print_function
import sys
import itertools

def main():
    k,s = map(int,sys.stdin.read().split())
    ans = []
    for x in xrange(k+1):
        for y in xrange(k+1):
            if x + y <= s:
                z = s - (x + y)
                if(z>=0 and z <= k):
                    ans.append([x,y,z])
            else:
                break
    sys.stdout.write("%d" % len(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from __future__ import unicode_literals
from __future__ import print_function
import os
import sys
import math
import itertools

def main():
    k,s = map(int,sys.stdin.read().split())
    ans = []
    for i in itertools.product(xrange(k+1), repeat=2):
        x, y = i
        z = s - sum(i)
        if(z >= 0 and z<=k and sum([x,y,z])==s):
            ans.append((x,y,z))
    sys.stdout.write("%d" % len(ans))

if __name__ == '__main__':
    main()

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 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 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(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 = list(map(int, input().split()))
count = 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:
                    count += 1
                elif x == y or y == z or z == x:
                    count += 3
                else:
                    count += 6
                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
                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(x+1):
        for z in range(y+1):
            if x+y+z == S:
                
                if x==y==z:
                    ans += 1
                elif x==y or y==z or x==z:
                    ans += 3
                else:
                    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 l in range(k+1):
            if i+j+l==s:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
total = 0
for i in range(a+1):
    for n in range(a+1):
        for m in range(a+1):
            if sum([i,n,m]) == b:
                total+=1
print(total)

Submission status: Time Limit Exceeded

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int,input().split())
counter = 0
x = 0
while x <= k and x <= s:
    y = 0
    while y <= k and x+y<= s:
        z = s-y-x
        if 0<=z<=k:
            counter += 1
        y += 1
    x += 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 i + j + k==S:
                count+=1
print(count)

Submission status: Time Limit Exceeded

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

xyz = [0, 0, 0]
index = 0
while min(k, s) != 0:
    xyz[index] = min(k, s)
    s = s - min(k, s)
    index = index + 1

count = 0

def cal(lis, n, m):
    lis[n] = lis[n] - 1
    lis[m] = lis[m] + 1

while xyz[0] >= 0:
    xyzCopy = list(xyz)

    while xyzCopy[1] >= 0 and xyzCopy[2] <= k:
        count = count + 1
        cal(xyzCopy, 1, 2)

    if xyz[1] == k:
        cal(xyz, 0, 2)
    else:
        cal(xyz, 0, 1)

print(count)

Submission status: Time Limit Exceeded

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

xyz = [s, 0, 0]

count = 0

def cal(lis, n):
    lis[n] = lis[n] - 1
    lis[n+1] = lis[n+1] + 1

while xyz[0] >= 0:
    xyzCopy = list(xyz)
    while xyzCopy[1] >= 0:
        if xyzCopy[0] <= k and xyzCopy[1] <= k and xyzCopy[2] <= k:
            count = count + 1
        cal(xyzCopy, 1)
    cal(xyz, 0)

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and 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):
    if S - x > 2 * K:
        continue
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K and x + y + z == S:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# vim: set fileencoding=utf-8 :
k, s = map(int, raw_input().split())
patterns = []

for x in range(k + 1):
    nokori = s - x
    for y in range(k + 1):
        if 0 <= nokori - y <= k:
            patterns.append([x, y, nokori - y])

ct = len(patterns)
print(ct)

Submission status: Time Limit Exceeded

Solution code:
# vim: set fileencoding=utf-8 :


def main():
    k, s = map(int, raw_input().split())
    patterns = []

    # 重複していいからとにかくpushする
    for x in range(k + 1):
        nokori = s - x
        for y in range(k + 1):
            if 0 <= nokori - y <= k:
                z = nokori - y
                patterns.append([x, y, z])

    ct = len(patterns)
    print(ct)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 文字列の入力
k, s = map(int, raw_input().split())

counter = 0

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

#counter=counter*3
# 出力
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys

K, S = map(int, sys.stdin.readline().split())
# 0<=X,Y,Z<=K, X+Y+Z=S

cnt = 0
for X in range(0, min(K, S) + 1):
    for Y in range(0, min(max(0, S - X), K) + 1):
        if S - X - Y >= 0 and S - X - Y <= min(S - X - Y, K):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

K, S = map(int, sys.stdin.readline().split())
# 0<=X,Y,Z<=K, X+Y+Z=S

cnt = 0
for X in range(0, min(K, S) + 1):
    for Y in range(0, min(max(0, S - X), K) + 1):
        for Z in range(0, min(max(0, S - X - Y), 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):
    if X > S:
        break
    for Y in range(min(K, S - X) + 1):
        if Y < 0:
            continue
        if X + Y > S:
            break
        Z = S - X - Y
        if X <= K and Y <= K and Z <= K:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S = [int(i) for i in input().split(" ")]

ans=0
tmp = 0 if S < 3*K else S - 3*K
for i in range(tmp, K+1):
    tmp = 0 if S < 2*K + i else S - 2*K - i
    for j in range(tmp, K+1):
        tmp = 0 if S < i+j else S - i - j
        for k in range(tmp, K+1):
            if i+j+k == 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):
    #print("i=" + str(i))
    x = i
    for j in range(k+1):
        #print("j=" + str(j))
        y = j
        for k in range(k+1):
            #print("k=" + str(k))
            z = k
            #print(x,y,z,s)
            #print("----------")
            if x + y + z == s:
                count += 1

        

print(count)

Submission status: Time Limit Exceeded

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

answer = 0
numbers = range(k+1)
for i in numbers:
    for j in numbers[i:]:
        for l in numbers[j:]:
            if i + j + l == s:
                if i == j and j == l:
                    answer += 1
                elif i == j or j == l or l == i:
                    answer += 3
                else:
                    answer += 6
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def main():
    K, S = map(int, raw_input().split())

    count = 0

    # X
    for i in range(K+1):
        # Y
        for j in range(K+1):
            # Z
            for k in range(K+1)[::-1]:
                if i + j + k == S:
                    count += 1
                if i + j + k < S:
                    break

    print count

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(min([S + 1, K + 1])):
    for j in range(min([S -i + 1, K + 1])):
        for k in range(min([S - i - j + 1, K + 1])):
            if i + j + k == S:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# input
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:
def solve():
    k, s = map(int, input().split())
    # 0<= x, y, z <= K
    # x + y + z = s
    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]
    print(len(a))
solve()

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int,input().split())
from itertools import product
ans = 0
for x,y,z in product(range(K+1),repeat=3):
    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(min(k, s-x)+1):
        for z in range(min(k, s-x-y)+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 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())
cnt=0
for x in range(K+1):
  for y in range(K+1):
    z=S-x-y
    if S==x+y+z and 0<=z and z<=K:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
x=y=z=0
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)

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 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:
def main():
    a = input().split(" ")
    K = int(a[0])
    S = int(a[1])
    X = Y = Z = count = 0
    for x in range(K + 1):
        for y in range(K + 1):
            for z in range(K + 1):
                xyz = x + y + z
                if xyz == S:
                    count += 1
    print(count)

if __name__ == '__main__':
    main()

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=[int(i) for i in 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=input().split()
K,S=[int(K),int(S)]
a=0
for X in range(K+1):
    for Y in range(K+1):
        Z=S-X-Y
        if 0<=Z<=K and X+Y+Z==S:
           a+=1 
print(a)

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
K,S=[int(K),int(S)]
a=[]
for X in range(K+1):
    for Y in range(K+1):
        Z=S-X-Y
        if 0<=Z<=K and X+Y+Z==S:
            a.append(S)
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
K,S=input().split()
K,S=[int(K),int(S)]
a=[]
for X in range(K+1):
    for Y in range(K+1):
        for Z in range (K+1):
            if X+Y+Z==S:
                a.append(S)
print(len(a))

Submission status: Time Limit Exceeded

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

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

# 絶対TLE…
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())
from itertools import product
counter = 0
a = list(product(list(range(K +1)), list(range(K +1)), list(range(K +1))))
for i in a:
    if sum(i) == S:
        counter += 1
    else:
        pass
print(counter)

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
import itertools
counter = 0
a = list(itertools.product(list(range(K +1)), list(range(K +1)), list(range(K +1))))
for i in a:
    if sum(i) == S:
        counter += 1
    else:
        pass
print(counter)

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
import itertools
counter = 0
temp_list = list(range(K +1))
for i in list(itertools.product(temp_list, temp_list, temp_list)):
    if sum(i) == S:
        counter += 1
    else:
        pass
print(counter )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
[k,s]=[int(i) for i in input().split()]
a=[]
for i in range(k+1):
    x=i
    for j in range(s-x+1):
        y=s-x-j
        z=s-x-y
        if y<=k and z<=k:
            a.append([x,y,z])
#print(a)
print(len(a))

Submission status: Time Limit Exceeded

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

count = 0

for i in range(k + 1):
  for j in range(k + 1):
    for l in range(k + 1):
      if i + j + l > s:
        break

      if i + j + l == s:
        count+= 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
[k,s]=[int(i) for i in input().split()]
a=[]
for i in range(k+1):
    x=i
    for j in range(s-x+1):
        y=s-x-j
        z=s-x-y
        if x<=k and y<=k and z<=k:
            a.append([x,y,z])
#print(a)
print(len(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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