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: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def f():
  if K * 3 >= S:
    for x in range(min(K, S), -1, -1):
      if K * 2 >= S - x:
        for y in range(min(K, S - x), -1, -1):
          if K >= S - x - y:
            yield 1

print(sum(list(f())))

Submission status: Accepted

Solution code:
from sys import stdin
# import sys
# import itertools
# import math

K, S = [int(x) for x in stdin.readline().rstrip().split()]
# print(2500**2)
cnt = 0
for i in range(K+1):
    for k in range(K+1):
        Z = S-i-k
        if 0 <= Z and Z <= K:
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

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

# import numpy as np


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

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

        for y in range(k+1):
            if x+y > s:
                # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                break
            
            # 3重ループではTLEになる。x+y+z = s なので、z=s-x-yとなるzがあればカウントする
            z = s-x-y
            if z >= 0 and z <= k:
                counter += 1

    print(counter)


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

Submission status: Accepted

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

Submission status: Accepted

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

count=0
for x in range (k+1):
  for y in range(k+1):
    z = s - x - y
    if z < 0 or z > k:
      continue
    count+=1
        
print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    k, s = MI()

    cnt = 0
    for x in range(0, k + 1):
        for y in range(0, k + 1):
            z = s - x - y
            if z < 0 or z > k:
                continue
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

answer = 0

for i in range(K + 1):
    for j in range(K + 1):
        if 0 <= S - i - j <= K:
            answer += 1

print(answer)

Submission status: Accepted

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

for x in range(K+1):
    for y in range(K+1):
        if S - x - y < 0:
            break
        if K >= S - x - y >= 0:
            ans += 1
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

    count = 0

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

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

print(actual(K, S))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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 z % 1 == 0):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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:
            cnt += 1

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for right in range(max(s-k, 0), min(s+1, 2*k+1)):
  lower = max(0, right-k)
  upper = min(k, right)
  if right % 2 != 0:
    ans += upper - lower + 1
  else:
    ans += upper - lower + 1
print(ans)

Submission status: Accepted

Solution code:

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

count = 0
for i in range(K+1) :
    for j in range(K+1) :
        if S < i + j :
            break
        if S - i - j <= K :
            count += 1

print(count)

Submission status: Accepted

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

res = 0

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

print(res)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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:
                ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
K, S = list(map(int, input().split()))
count = 0
for x, y in product(range(K + 1), range(K + 1)):
    if 0 <= S - (x + y) <= K:
        count += 1
print(count)

Submission status: Accepted

Solution code:
K,S = map(int,input().split())
array = [i for i in range(K+1)]
cnt = 0

for i in array:
    for j in array:
        h = S-(i+j)
        if h >= 0 and h <= K:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline


K,S = map(int, input().split())
n = 0
up = math.floor(K)
for i in range(0,K+1):
    for j in range(0, K+1):
        if(0<= S-i-j <=K):
            n +=1
        else:
                n =n

print(n)

Submission status: Accepted

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

#data = [i for i in range(k + 1)]
# print(data)
#dd = itertools.product(data, repeat=3)
# print(dd)
#dd = list(dd)
#target = s / 3
ans = 0
if (k * 3 < s):

    pass
else:
    for x in range(0, k + 1):
        #temp = s - x
        # 2なら、（０、２）（１、１）（２、０）
        for y in range(0, k + 1):
            if (0 <= s - (x + y) <= k):
                ans += 1

print(ans)

'''
ans = 0
for i in dd:
    #print(sum(i))
    if (sum(i) == s):
        ans += 1

print(ans)
'''

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import product

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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 k >= z >= 0:
            ans += 1
print(ans)

Submission status: Accepted

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

cnt = 0
for x in range(0,k+1,1):
    for y in range(0,k+1,1):
        if s - x - y >= 0 and s - x - y <= k:
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - (i + j) <= K:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
num = min(k, s)

for i in range(num+1):
  for j in range(num+1):
    res = s - (i+j)
    if (res >= 0) and (res <= k):
      ans += 1
      
print(ans)

Submission status: Accepted

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 0 <= Z and Z <= K:
        count += 1
print(count)

Submission status: Accepted

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

for x in range(K+1):
    if x > S:
        break
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K:
            count += 1
        elif x + y > S:
            break


print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
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
import numpy as np
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()

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,M=list(map(int,input().split()))
ans = 0
for i in range(K+1):
    for j in range(min(K+1,M-i+1)):
        if M-i-j > K:
            continue
        else:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
import heapq

k, s = [int(x) for x in stdin.readline().rstrip().split()]

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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 0 <= z <= K:
            count = count + 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = list(map(int,input().split()))
count = 0
#ZはXとYが決まった時点で自動的に決まる。
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y 
#範囲が条件ないならOK
    if 0 <= Z and Z <= K:
        count += 1
print(count)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

k,s=MI()
count=0
for i in range(0,k+1):
    for j in range(0,k+1):
        if 0<=s-i-j<=k:
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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 0 <= z <=k:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

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

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

Submission status: Accepted

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 and z<=K:
            ans+=1
print(ans)

Submission status: Accepted

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

    ans = 0
    for x in range(min(K, S) + 1):
        for y in range(min(K, S - x) + 1):
            z = S - x - y
            if z < 0 or z > K: continue
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

t=0
for x in range(k+1):
    for y in range(k+1):
        if s-x-y >= 0 and s-x-y <= k: 
            t+=1
print(t)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    K,S = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    count=0
    for X in range(0,K+1):
        for Y in range(0,K+1):
            if 0<=S-X-Y<=K:
                count+=1
    print(count)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(K,S):
    ans = 0
    for i in range(K+1):
        if i>S:
            continue
        for j in range(K+1):
            if i+j>S or i+j<S-K:
                continue
            # print(i,j,S-i-j)
            ans += 1
    return ans
print(solve(K,S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
diff = 3 * k - s
ans = 0
low = max(0, k - diff)
for x in range(low, k + 1):
    for y in range(low, k + 1):
        if k >= s - x - y and s - x - y >= 0:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k, s = map(int, read().split())
cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            cnt += 1
print(cnt)

Submission status: Accepted

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

count=0

for x in range(K+1):
    for y in range(x+1):
        z=S-x-y
        if z<0 or z>y:
            pass
        else:
            #print(x,y,z)
            if x==y==z:
                count+=1
            elif x==y or x==z or y==z:
                count+=3
            else:
                count+=6
        
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(k+1):
    t = k - i
    if t < 0:
        break
    for j in range(k+1):
        if i+j <= s <= i+j+k:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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 z < 0:
            break
        if k < z:
            continue
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
ans = 0
for x in range(k+1):
    for y in range(x, k+1):
        z = s - x - y
        if y<=z and z<=k:
            tmp = set([x,y,z])
            if len(tmp)==3:
                ans += 6
            elif len(tmp)==2:
                ans += 3
            else:
                ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# 全通り調べる問題
K, S = read_ints()
X = list(range(K + 1))  # Kは2500なのでK^2は間に合う
# X,Yについて全探索してZについて二分探索すればよい #連続なので範囲に入ってれば良い（二分探索もいらない！）
ans = 0
for x in X:
    for y in X:
        z = S - x - y
        if 0 <= z <= K:
            ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 x + y + z == s and k >= z >= 0:
                res += 1

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

ans = 0
for i in range(K + 1):
    for j in range(K + 1):
        if 0 <= S - i - j <= K:
            ans += 1

print (ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,s = inpl()
res = 0
for i in range(n+1):
    for j in range(n+1):
        if 0 <= s - (i+j) <= n:
            res += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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):
        if i + j <= S and S-i-j <= K:
            count += 1
print(count)

Submission status: Accepted

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):
        if x == s:
            cnt += 1
            break
        for y in range(k+1):
            c = s - (x + y)
            if c <= k and c >= 0:
                cnt += 1

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

resolve()

Submission status: Accepted

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
                if(z >= 0 and z <= K):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: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    K, S = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for X in range(K+1):
        for Y in range(K+1):
            if 0<=S-X-Y<=K:
                cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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 z >= 0 and z <= k:
            count += 1
print(count)