Problem:


Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?  

Constraints

2≤K≤2500 

0≤S≤3K 

K and S are integers.  

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2 

X = 0, Y = 2, Z = 0 

X = 2, Y = 0, Z = 0 

X = 0, Y = 1, Z = 1 

X = 1, Y = 0, Z = 1 

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.



Sample input:
2 2


Sample output:
6

Submission status: Time Limit Exceeded

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

count=0

for i in range(K+1):
    for j in range(i+1):
        for k in range(j+1):
            if i+j+k==S:
                #print(i,j,k)
                if i==j and j==k:
                    count+=1
                elif i==j or j==k or i==k:
                    count+=3
                else:
                    count+=6
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 = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

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:
# -*- coding: utf-8 -*-

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:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    k, s = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

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

    print(cnt)


resolve()

Submission status: Time Limit Exceeded

Solution code:

def solve(K, S):
    import bisect
    count = 0
    z_array = [i for i in range(K+1)]
    for x in range(K+1):
        for y in range(K+1):
                z = S - x - y
                index = bisect.bisect_left(z_array, z)
                if(index != K+1 and z_array[index] == z):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))
#print(solve(2, 2))
#print(solve(5, 15))
main()

Submission status: Time Limit Exceeded

Solution code:

def solve(K, S):
    count = 0
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if(x+y+z == S):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))

main()

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

list = [[x,y,z] for x in range(K+1) for y in range(K+1) for z in range(K+1)]

for XYZ in list:
    if sum(XYZ) == S:
        res += 1

print(res)

Submission status: Time Limit Exceeded

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
k,s=map(int,input().split())
cnt=0
for p in range(k+1):
  for q in range(k+1):
    for r in range(k+1):
      if p+q+r==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 X+Y+Z == S:
                res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
K,N=map(int,input().split())
cnt=0
for i in  range(K+1):
    for j in range(K+1):
        if i+j>=N+1:
            break
        else:
            for k in range(K+1):
                if i+j+k==N:
                    cnt+=1
                elif i+k+j>=N+1:
                    break
                else:
                    pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K,N=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==N:
                cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k, s = 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 += 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):
    if s - x > k * 2:
        continue
    for y in range(k + 1):
        if s - x - y > k:
            continue
        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())

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) = 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())
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:
import itertools
k, s = map(int, input().split())
ans = 0
for i in list(itertools.product(range(k + 1), repeat=3)):
    if sum(i) == s:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, S = MAP()

cnt = 0

A = [1]*(S+2)
for i in range(S+1):
	for j in range(1, S+2-i):
		if sum(A[:i]) <= K and sum(A[i+1:i+j]) <= K and sum(A[i+j+1:]) <= K:
			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(k+1):
        if((y+x) > s):
            break
        for z in range(k+1):
            nsum = x+y+z
            if(nsum==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 s==x+y+z:
                cnt=cnt+1
            else:
                continue
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(k+1):
    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())

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:
#2020-04-29
k, s = map(int,input().split())
cou = 0
for i in range(k + 1):
    for j in range(k + 1):
        for t in range(k + 1):
            if s == i + j + t:
                cou += 1
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import itertools

k,s=map(int,input().split())
K=list(range(k+1))
ans=0
for team in itertools.product(K,repeat=3):
    if sum(team)==s:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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


cnt = 0

if S <= K:
    for x in range(S+1):
        for y in range(S+1):
            for z in range(S+1):
                if x + y + z == S:
                    cnt += 1
else :
    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 = [int(i) for i in input().split()]

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

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = []
for a in range(K+1):
  for b in range(K+1):
    if S-a-b>=0 and S-a-b<=K:
      cnt.append(S-a-b)
        
print(len(cnt))

Submission status: Time Limit Exceeded

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

cnt =0
for a in range(K+1):
  for b in range(min(S+1-a,K+1)):
    for c in range(min(S+1-a-b,K+1)):
      if a+b+c == S:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

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

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)

Submission status: Time Limit Exceeded

Solution code:
line = input()
data = line.split()
import math
import itertools
out =0
pair =list(itertools.combinations_with_replacement(range(0,int(data[0])+1), 3))


for i in range(len(pair)):
  if sum(pair[i]) == int(data[1]):
    clear_data =list(pair[i])
    if clear_data[0] <=int(data[0]) or clear_data[1] <=int(data[0]) or clear_data[2] <=int(data[0]):
      if clear_data[0] ==clear_data[1] and clear_data[0] ==clear_data[2] and clear_data[1] ==clear_data[2]:
        out +=1
      elif clear_data[0] !=clear_data[1] and clear_data[0] !=clear_data[2] and clear_data[1] !=clear_data[2]:
        out +=6
      else:
        out +=3

print(out)

Submission status: Time Limit Exceeded

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

def binaly_serch(ls,k):#lsはリスト、kが求めたいもの
    ls.sort()
    n = len(ls)
    s = 0
    e = n#あえてls から一つ出たのにしておく。このおかげでk = ls[n-1]の時でも探索できる
    while int(e - s) >= 1:#intでcastして繰り下がった方を見て、e = bという条件にしてるからこれで全部探せる
        b = int((s+e)/2)
        if ls[b] == k:
            return True
        elif ls[b] < k:
            s = b + 1
        else:
            e = b
    return False
ans = 0
kls = [i for i in range(K+1)]
for i in range(K+1):
    for j in range(K+1):
        if S-(i+j) > K:
            continue
        else:
            if binaly_serch(kls,S-(i+j)):
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

def binaly_serch(ls,k):#lsはリスト、kが求めたいもの
    ls.sort()
    n = len(ls)
    s = 0
    e = n#あえてls から一つ出たのにしておく。このおかげでk = ls[n-1]の時でも探索できる
    while int(e - s) >= 1:#intでcastして繰り下がった方を見て、e = bという条件にしてるからこれで全部探せる
        b = int((s+e)/2)
        if ls[b] == k:
            return True
        elif ls[b] < k:
            s = b + 1
        else:
            e = b
    return False
ans = 0
kls = [i for i in range(K+1)]
for i in range(K+1):
    for j in range(K+1):
        if binaly_serch(kls,S-(i+j)):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int, input().split())
count = 0
for x in range(min([K+1,S+1])):
  for y in range(min([K+1,S+1-x])):
    for z in range(min([K+1,S+1-x-y])):
      if x+y+z == S:
        count = 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 = 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 s == x + y + z:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
ans = 0
k, s = map(int, input().split())
sa = [int(i) for i in range(k+1)]

c = itertools.product(sa,repeat=3)

for i in c:
  if i[0] + i[1] + i[2] == s:
      ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k, s = map(int, input().split())
i = 0
x = 0
for x in range(0,k+1):
    for y in range(0,min(s-x,k)+1):
        if  0 <= s-x-y <= k:
            for z in range(0,s-x-y+1):
                if x+y+z == s : i += 1 
#        if s-x-y <= k & x+y <= s: i += 1 
#            if x+y+z == s: i += 1
print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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
                break

print(ans)

Submission status: Time Limit Exceeded

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

print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

li = [1 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]
print(len(li))

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 x+y+z ==S and 0<=z<=K:
      #print(x,y,z) 
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline

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

Submission status: Time Limit Exceeded

Solution code:
K, S = map(int, input().split())
count = 0
for i in range(K+1):
    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())
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:
def ABC051B(k, s):
    count = 0
    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if x + y + z == s:
                    count += 1

    print(count)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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 S==(x+y+z):
                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=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):
        for Z in range(K+1):
            if X+Y+Z==S:
                count+=1
                
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc051/tasks/abc051_b
# -*- coding: utf-8 -*-
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):
    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)

if __name__ == '__main__':
    K, S = map(int, input().split())
    solve(K, S)

Submission status: Time Limit Exceeded

Solution code:
K,S = input().split()
count = 0

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S = input().split()
count = 0

# O(K^3)になるため間に合わない
# for x in range(int(K)+1):
#   for y in range(int(K)+1):
#     for z in range(int(K)+1):
#       if x+y+z== int(S):
#         count+=1

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
K,S = input().split()
count = 0

for x in range(int(K)+1):
  for y in range(int(K)+1):
    for z in range(int(K)+1):
      if x+y+z== int(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())

result = 0

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

print(result)

Submission status: Time Limit Exceeded

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

result = 0

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

print(result)

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(i, K + 1):
    for k in  range(j, K + 1):
      if i + j + k == S:
        if i == j == k:
          cnt += 1
        elif i == j or j == k or i == k:
          cnt += 3
        else:
          cnt += 6
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K,S=map(int,input().split())
cnt=0
for X in range(K+1):
  for Y in range(K+1):
    Z=S-X-Y
    if Z in range(K+1):
      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:
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 (0 <= z <= k) and type(z) == int:
            cnt += 1
            
print(cnt)

Submission status: Time Limit Exceeded

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

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:
X = [int(e) for e in input().split()]
ans = 0
for i in range(0,X[0]+1):
    for k in range(0,X[0]+1):
        for j in range(0,X[0]+1):
            if(i + k + j)==X[1]:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-GuessTheNumber.py
#
k, s = map(int, input().split())
pattern = 0

for x in range(min(k+1, s+1)):
    x_tmp = x
    for y in range(min(k+1, s+1-x_tmp)):
        y_tmp = y
        for z in range(min(k+1, s+1-x_tmp-y_tmp)):
            if x_tmp + y_tmp + z == s:
                pattern += 1

print(pattern)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-GuessTheNumber.py
#
k, s = map(int, input().split())
pattern = 0

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

print(pattern)

Submission status: Time Limit Exceeded

Solution code:
import itertools
K,S=map(int,input().split())
lst=[num for num in range(K+1)]
ans=0
for i in itertools.product(lst,repeat=3):
  if sum(i)==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:
def resolve():
    K, S = map(int, input().split())
    print(
        len(
            [
                (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 and max(x, y, z) <= K
            ]
        )
    )


if __name__ == "__main__":
    resolve()

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):
          if ((x + y + (s-x-y)) == s) and (0 <= s-x-y <= k):
              ans+=1

print(ans)

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

if s==3*k:
    print(1)
else:
    ans=0
    for i in range(k+1):
        if i>s:
            break
        for j in range(k+1):
            if i+j>s:
                break
            for jj in range(k+1):
                if i+j+jj==s:
                    ans+=1
                elif i+j+jj>s:
                    break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

p=[]
for i in range(k+1):
    p.append(i)

ans=0
for x in range(k+1):
    for y in range(k+1):
           if p[bisect.bisect_right(p,s-x-y)-1]==s-x-y:
                ans+=1
print(ans)