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 = list(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())
Xm = k
Ym = k
Zm = k
count = 0
for i in range(Xm+1):
  for j in range(Ym+1):
    for m in range(Zm+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())
combi=[]
num=0
for i in range(K+1):
    for j in range(K+1):
        if 0<=S-i-j<=K:
            combi=[i,j,S-i-j]
            #print(combi)
            #print(set(itertools.permutations(combi)))
            num+=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools

K,S=map(int,input().split())
combi=[]
num=0
for i in range(K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i+j+k==S:
                combi=[i,j,k]
                #print(combi)
                #print(set(itertools.permutations(combi)))
                t=set(itertools.permutations(combi))
                #print(len(t))
                num+=len(t)
print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools

K,S=map(int,input().split())
a=list(range(K+1))
#print(a)
combi=list(itertools.product(a,repeat=3))
#print(combi)
print([sum(combi[i]) for i in range(len(combi))].count(S))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
li = list(map(int,input().split()))
k = li[0]
s = li[1]
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:
k,s=map(int,input().split())
ans=0

for x in range(k,-1,-1):
    if s-x > k*2:
        break
    if s < x:
        continue
    for y in range(k,-1,-1):
        if s-x-y > k:
            break
        if s < x+y:
            continue
        for z in range(k,-1,-1):
            if s-x-y-z > 0:
                break
            if x+y+z==s:
                ans +=1

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
k,e=map(int,input().split())
ans=0
s=[i for i in range(k+1)]
q=list(sum(u) for u in itertools.product(s, repeat=3) if sum(u)==e)
print(len(q))

Submission status: Time Limit Exceeded

Solution code:
k,e=map(int,input().split())
ans=0
for s in range(k+1):
  for t in range(k+1):
    for r in range(k+1):
      if s+t+r==e:ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
k,s=map(int,input().split())
count=0
ans=list(itertools.product(list(range(k+1)),repeat=3))
for i in ans:
    if sum(i)==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:
# Sum of Three Integers
import sys

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

def getAns(k, s) :
    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
    return cnt
print(getAns(K, S))

Submission status: Time Limit Exceeded

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

n = 0

for x in range(K+1) :
        if (S - x <= 2 * K):
                for y in range(K+1) :
                        if (K >= x) and (K >= y) and (S >= x + y) and (S-x-y <= K):
                                n = n + 1

                
print(n)

Submission status: Time Limit Exceeded

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

n = 0

for x in range(S+1) :
        if (S - x <= 2 * K):
                for y in range(S+1) :
                        if (K >= x) and (K >= y) and (S >= x + y) and (S-x-y <= K):
                                n = n + 1

                
print(n)

Submission status: Time Limit Exceeded

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

n = 0

for x in range(S+1) :
        for y in range(S+1) :
                if (K >= x) and (K >= y) and (S >= x + y) and (S-x-y <= K):
                       n = n + 1

                
print(n)

Submission status: Time Limit Exceeded

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

for idx_x in range(K+1):
    if idx_x > S:
        break
    for idx_y in range(K+1):
        if idx_x+idx_y > S:
            break
        for idx_z in range(K+1):
            if idx_x+idx_y+idx_z == S:
                cnt += 1
            elif idx_x+idx_y+idx_z > S:
                break

print(cnt)

Submission status: Time Limit Exceeded

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

for idx_x in range(K+1):
    for idx_y in range(K+1):
        for idx_z in range(K+1):
            if idx_x+idx_y+idx_z == S:
                cnt += 1
            elif idx_x+idx_y+idx_z > S:
                break

print(cnt)

Submission status: Time Limit Exceeded

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

for idx_x in range(K+1):
    for idx_y in range(K+1):
        for idx_z in range(K+1):
            if idx_x+idx_y+idx_z == S:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

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

            if a + b + c > s:
                break

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

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

            if a + b + c == k:
                break

print(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 q in range(K+1):
            if i+j+q == S:
                answer+=1
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

l     = input().split()
K, S  = map(int, l)
max   = K+1
sum   = 0
count = 0

#print('K= ', K)                                                                                                   
#print('S= ', S)                                                                                                   

for x in range(0, max):
    for y in range(0, max):
        for z in range(0, max):

            sum = x + y + z
            if sum == 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):
        if i + j + (s - i - j) == s and 0 <= s - i - j <= k:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
k, s = 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 i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S: ans += 1
            if i+j+k > S: break
        if i+j > S: break
    if i > S: break

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for x in range(K + 1):
    for y in range(x, K + 1):
        for z in range(y, K + 1):
            if x + y + z == S:
                if x == y and y == z:
                    ans += 1
                elif x == y or y == z or z == x:
                    ans += 3
                else:
                    ans += 6

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

"""テンプレ"""

# 高速
input = sys.stdin.readline

# 1行を空白でリストにする(int)
def intline():
    return list(map(int, input().split()))


# 上のstrヴァージョン
def strline():
    return list(map(str, input().split()))


# 1列に並んだ数
def intlines(n):
    return [int(input() for _ in range(n))]


# 上の文字列ヴァージョン
def lines(n):
    return [input() for _ in range(n)]
    

# Union-Find木  http://at274.hatenablog.com/entry/2018/02/02/173000
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


# 重み付きのUnion-Find木　http://at274.hatenablog.com/entry/2018/02/03/140504
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]




"""ここからメインコード"""

k, s = intline()
r = range
ans = 0
for x in r(k+1):
    for y in r(k+1):
        for z in r(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):
    if x==s:
        count+=1
    elif x+2*k>=s:
        for y in range(k+1):
            if x+y==s:
                count+=1
            elif x+y+k>=s:
                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())
count = 0
for x in range(max(0,s-2*k),k+1): 
    if x==s:
        count+=1
    else:
        for y in range(max(0,s-k-x),k+1):
            if x+y==s:
                count+=1
            else:
                for z in range(max(0,s-x-y),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())
count = 0
for x in range(max(0,s-2*k),k+1): 
    if x==s:
        count+=1
    else:
        for y in range(max(0,s-k-x),k+1):
            if x+y==s:
                count+=1
            else:
                for z in range(max(0,s-x-y),k+1):
                    if x+y+z == s:
                       count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
counter=0
index1=0
while index1 < k+1:
    index2=0
    while index2 < index1+1:
        index3=0
        while index3 < index2+1:
            if index1+index2+index3 == s:
                if index1 == index2 and index2 == index3:
                    counter+=1
                elif index1!=index2 and index2!=index3 and index3!=index1:
                    counter+=6
                else:
                    counter+=3
            index3+=1
        index2+=1
    index1+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
counter=0
index1=0
while index1 < k+1:
    index2=0
    while index2 < k+1:
        index3=0
        while index3 < k+1:
            if index1+index2+index3 == s:
                counter+=1
            index3+=1
        index2+=1
    index1+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

ans = 0
for i in itertools.combinations_with_replacement(range(k+1), 3):
    if sum(i) == s:
        n_unique = len(set(i))
        if n_unique == 1:
            ans += 1
        elif n_unique == 2:
            ans += 3
        elif n_unique == 3:
            ans += 6
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k,s = map(int, input().split())
a=0
for x in range(k+1):
    if x>s:
        continue
    else:
        for y in range(k+1):
            if x+y>s:
                continue
            elif s-x-y>=0 and s-x-y<=k:
                a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
k,s = (int(i) for i in 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().split()))

counter = 0

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

print(counter)

Submission status: Time Limit Exceeded

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

res = [(x,y,z) 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(res))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

kde = []
res = 0
for i in range(k+1):
    kde.append(i)

kcom = list(itertools.product(kde,repeat=3))
for j in kcom:
    kmatch = j[0]+j[1]+j[2]
    if kmatch == s:
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
k,s=[int(a) for a 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())

#問題文よりX, Y, Zの最大値はKである
X = range(K+1)
Y = range(K+1)
Z = range(K+1)

#フラグ設定
flag = 0

#全探索
for x in X:
    for y in Y:
        for z in Z:
            
            #条件
            if x+y+z==S:
                flag += 1

#出力
print(flag)

Submission status: Time Limit Exceeded

Solution code:
k,s = [int(i) for i in input().split()]
r=0

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

print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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:
n, m = map(int, input().split())
ans = 0
for x in range(n + 1):
    for y in range(n + 1):
        for z in range(n + 1):
            if x + y + z == m:
                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(min(s-x+1, k+1)):
        z = s - x - y
        if min(x, y, z) < 0 or z > k:
            continue
        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 min(x, y, z) < 0 or z > k:
            continue
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

ret = 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: ret += 1
        elif X != Y and Y != Z and Z != X: ret += 6
        else: ret += 3

print (ret)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain
# import numpy as np
# N = int(input())
# L,N = map(int,input().split())
# X = [list(map(int,input().split())) for x in range(N)]
K,S = map(int,input().split())
patterns = 0

arr = [[[x+y+z for z in range(min(S-x-y+1,K+1))] for y in range(min(S-x+1,K+1))] for x in range(K+1)]
farr = list(chain.from_iterable(arr))
farr = list(chain.from_iterable(farr))
# print(farr)
print(farr.count(S))
# print(patterns)

Submission status: Time Limit Exceeded

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

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

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:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


K, S = il()
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,n = map(int, input().split())
res = 0
for i in range(k+1):
    for j in range(k+1):
        if i + j > n : break
        h = n - i - j
        if h <= k:
            res +=1
            x =[i,j,h]
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count =  0
x, y, z = 0, 0, 0

if n > s:
  n = s

for i in reversed(range(n + 1)):
  x = i
  for j in reversed(range(n + 1)):
    if x > s or s - x > 2 * n:
      break
    y = j
    for k in reversed(range(n + 1)):
      if x + y > s or s - x - y > n:
        break
      z = k
      if x + y + z == s:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

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

count =  0
x, y, z = 0, 0, 0

for i in range(n + 1):
  x= i
  for j in range(n + 1):
    y = j
    for k in range(n + 1):
      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 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 _*_
#  Atcoder_Beginners_Contest051-B
#  https://atcoder.jp/contests/abc051/tasks/abc051_b
def  queueAnswer(maxValue,sumNumber):
	counter = 0
	for x in range(0,maxValue+1,1):
		for y in range(0,maxValue+1,1):
			for z in range(0,maxValue+1,1):
				thisSum = x+y+z
				if  thisSum==sumNumber:
					counter = counter + 1
	answer = counter
	return answer


if __name__ == '__main__':
	k,s = map(int,input().strip().split(' '))
	solution=queueAnswer(k,s)
	print(solution)

Submission status: Time Limit Exceeded

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest051-B
#  https://atcoder.jp/contests/abc051/tasks/abc051_b
from itertools import product
def  queueAnswer(maxValue,sumNumber):
	baseList = list(range(0,maxValue+1,1))
	pools = product(baseList,baseList,baseList)
	counter = 0
	for x,y,z in pools:
		checkSum = x + y + z
		if checkSum == sumNumber:
			counter = counter + 1
	answer = counter
	return answer


if __name__ == '__main__':
	k,s = map(int,input().strip().split(' '))
	solution=queueAnswer(k,s)
	print(solution)

Submission status: Time Limit Exceeded

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

if(3*K == S):
  print(1)
  exit()
cnt = 0
for i in range(K+1):
  for j in range(K+2):
    for k in range(K+3):
      if(i+j+k == S):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,raw_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 = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

Solution code:

from collections import Counter
from collections import defaultdict
from functools import lru_cache
import itertools
import random
import cProfile
import copy

N,M = map(int,input().split())

X = [i for i in range(N+1)]

count = 0
for i in itertools.product(X,X,X):
	if sum(i) == M:
		count += 1
print(count)

Submission status: Time Limit Exceeded

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

X = [i for i in range(N+1)]
Y = [i for i in range(N+1)]
Z = [i for i in range(N+1)]

count = 0
for x in X:
	for y in Y:
		for z in Z:
			if x+y+z == M :
				#print(x,y,z)
				count += 1
print(count)

Submission status: Time Limit Exceeded

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

for x in range(K+1) :
    x = int(x)
    for y in range(K+1) :
        y = int(y)
        z = S - x - y
        if (0 <= z and z <= K) :
            patterns += 1

print(patterns)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
li = []
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if z == s - (x + y):
                li.append('{} {} {}'.format(x, y, z))
li
print(len(set(li)))

Submission status: Time Limit Exceeded

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

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

                break

print(result)

Submission status: Time Limit Exceeded

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

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

print(result)

Submission status: Time Limit Exceeded

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

nums=[i for i in range(k+1)]

for i in range(len(nums)):
  for j in range(len(nums)):
    l = s-i-j
    if 0 <= l <=k:
      if i+j+l==s:
        count+=1
print((count))

Submission status: Time Limit Exceeded

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

nums=[i for i in range(k+1)]

for i in itertools.product(nums,repeat=3):
  if sum(i)==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(" "))
a = 0
ans = 0
while a <= K:
  b = 0
  while b <= K:
    c = S-a-b
    if c <= K and c >= 0:
       ans+=1
    b += 1
  a+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K,S = map(int,input().split(" "))
a = 0
ans = 0
while a <= K:
  b = 0
  while b <= K:
    if S-(a+b) <= K and S-(a+b) >= 0:
       ans+=1
    b += 1
  a+=1
print(ans)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
K, S = 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:
                break
            if X + Y + Z == S:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k,s = [int(x) for x in input().split()]
a = 0
n = 0
while a <= k:
  b = 0
  while b <= k:
    z = s-a-b
    if 0<=z and z <= k:
      n += 1
    b += 1
  a += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
k,s = [int(x) for x in input().split()]
a = 0
n = 0
while a <= k:
  b = 0
  while b <= k:
    c = 0
    while c <= k:
      if (a+b+c) == s:
        n += 1
      c += 1
    b += 1
  a += 1
print(n)