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

cnt = 0

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

Submission status: Accepted

Solution code:
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

K,S = splitintinput()

time_sta = time.perf_counter()
ans = 0

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


time_end = time.perf_counter()
#print(time_end - time_sta)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    K,S=map(int,input().split())

    

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

    print(cnt)
resolve()

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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:
ans = 0
k, s = map(int, input().split())
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:
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 <= k and z >= 0:
      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:
vec = input().split(' ')
k = int(vec[0])
s = int(vec[1])
count = 0
for x in range(k + 1):
    if x <= s:
        for y in range(k + 1):
            if x + y <= s:
                z = s - x - y
                if z >= 0 and z <= k:
                    count += 1
            else: break
    else: break
print(count)

Submission status: Accepted

Solution code:
K, S = tmp = list(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())
c = 0

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

Submission status: Accepted

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

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

print(countPatterns(K, S))

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

Submission status: Accepted

Solution code:
K,S= input().split()
intK = int(K)
intS = int(S)
sum = 0
for X in range(intK+1):
    for Y in range(intK+1):
        Z = intS - (X+Y)
        if (Z < 0) or Z > intK:
            continue
        sum += 1
print(sum)

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:
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:
            # print(x)
            # print(y)
            # print(s - x - y)
            # print("------------------")
            cnt += 1

print(cnt)

Submission status: Accepted

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

x=0
j=0

for j in range(k+1):
	if s-j<=k and s-j>=0:
		x=x+s-j+1
	elif (s-j)<=2*k and s-j>=0:
		x=x+(2*k-(s-j)+1)

print(x)

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):
        l = s - i - j
        if l <= k and l >= 0:
            ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

K,S = list(map(int,input().split()))
l = set(range(K+1))
ans = 0

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

Submission status: Accepted

Solution code:
K,S = [int(i) for i in input().split()]
count = 0
for z in range(0,K+1):
	for y in range(0,K+1):
			if 0 <= S-y-z <= K:
				count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools

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

cnt = 0

l = list(range(K + 1))

for i, j in itertools.product(l, repeat=2):
    if 0 <= S - i - j <= K:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools

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

cnt = 0

# K = list(range(K + 1))

for i, j in itertools.product(list(range(K + 1)), repeat=2):
    if 0 <= S - i - j <= K:
        cnt += 1

print(cnt)

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):
        if 0 <= S - i - j <= K:
            cnt += 1

print(cnt)

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 i in range(0, k+1):
    for j in range(0, k+1):
        if 0 <= s - (i + j) <= k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
k,s = map(lambda x:int(x),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)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    K, S = MAP()
    
    ans = 0
    for x in range(K+1):
    	for y in range(K+1):
        	ans += 0 <= S - (x + y) <= K
            
    print(ans)
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import 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
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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, S = MAP()

ans = 0

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

Submission status: Accepted

Solution code:
# import bisect

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

ans = 0

if k * 3 == s:
    print(1)
    exit(0)
else:
    for v in range(k + 1):
        # bisect.bisect_left([i for i in range(2 * k + 1)], s - v)
        for x in range(k + 1):
            if v + x > s:
                continue
            else:
                targ = s - v - x
                # hoge = bisect.bisect_left([i for i in range(k + 1)], targ)
                if targ < 0 or targ > k:
                    pass
                else:
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(200000000)


# my functions here!

#入力

def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    K,S=pin()
    ans=0
    for x in range(K+1):
        for y in range(K+1):
            if S-(x+y)>=0 and S-(x+y)<=K:
                ans+=1
    print(ans)
    
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 2"""
        output = """6"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 15"""
        output = """1"""
        self.assertIO(input, output)
if __name__=="__main__":resolve()

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s = list(map(int, input().split(" ")))
n = s[0]
c = s[1]
ans = 0

for v in range(n+1):
    x = v
    for i in range(n+1):
        y = i
        if  0 <= (c - x - y) <= n:
                ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
#!/usr/bin/env python

def main():
    k, s = list(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 and z <= k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(K: int, S: int):
    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)
    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())

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:
k,s=map(int,input().split())
ret=0
k+=1
for i in range(k):
  for j in range(k):
    d=s-i-j
    if k>d>=0:
      ret+=1
print(ret)

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline

k,s = map(int,readline().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 sys import stdin


def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(K + 1):
        for Y in range(K + 1):
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(S + 1):
        if K < X:
            break
        for Y in range(S + 1):
            if K < Y:
                break
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)


if __name__ == "__main__":
    main()

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 K>=S-a-b and 0<=S-a-b:
            ans+=1
            
print(ans)

Submission status: Accepted

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

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):
        z = s-i-j
        if 0 <= z <= k:
            ans += 1
            #print(i, j, s-i-j)
print(ans)

Submission status: Accepted

Solution code:
import itertools
a,b=(int(x) for x in input().split())
l = range(a+1)
count = 0
m = [x+y for x,y in itertools.product(l,l) if (x+y)<=b]
for i in m:
  if b-i <= a:
    count+=1
print(count)

Submission status: Accepted

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

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)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def spline(func=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func, iter_)


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

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
K,S=map(int,input().split())
count=0
for a in range(K+1):
    b=S-a
    for c in range(K+1):
        d=b-c
        if d>=0 and d<=K:
            count+=1
        else:
            pass
print(count)

Submission status: Accepted

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

z = 0
count = 0

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

print(ans)

Submission status: Accepted

Solution code:
K,S = map(int,input().split(" "))
ans = 0
if S == 3*K:
  print(1)
  exit()
for z in range(K+1):
  tmp = S-z
  if tmp <= 2*K:
    for y in range(K+1):
      ttmp = tmp-y
      if 0 <= ttmp <= K:
        ans += 1
print(ans)

Submission status: Accepted

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

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 i in range(k + 1):
    for j in range(i, k + 1):
        if j <= s - i - j <= k:
            l = s - i - j
            if i == j == l:
                ans += 1
            elif i == j or j == l:
                ans += 3
            elif i != j != l:
                ans += 6
print(ans)

Submission status: Accepted

Solution code:
def main():
    k,s=map(int,input().split())
    
    cnt=0
    for i in range(k+1):
        for j in range(k+1):
            if 0<=s-i-j<=k:
                cnt+=1
    print(cnt)
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) and z <= K:
            ANS += 1

print(ANS)

Submission status: Accepted

Solution code:
import numpy as np

K, S = map(int, input().split())
fft_len = 1 << (K * 3).bit_length()

x = np.ones(K + 1)
Fx = np.fft.rfft(x, fft_len)
Fx3 = Fx * Fx * Fx
conv = np.fft.irfft(Fx3, fft_len)

ans = conv[S]
ans = int(ans + 0.5)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(K: int, S: int):
    ans = 0
    for x in range(K+1):
        for y in range(K+1):
            if 0 <= S-x-y <= K:
                ans += 1

    print(ans)
    return



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:
import sys
input = sys.stdin.readline
K, S = map(int, input().split())
table = [0] * (3 * K + 1)
for x in range(K + 1):
  for y in range(K + 1):
    table[x + y] += 1
res = 0
#print(table)
for z in range(3 * K + 1):
  if (S - z) in range(K + 1): res += table[z]
print(res)

Submission status: Accepted

Solution code:
K,N=map(int,input().split())
count=0
for i in range (K+1):
	for j in range (K+1):
		k=N-i-j
		if k>=0 and k<=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 i + j == s: ans += 1
    elif 0 <= s - (i + j) <= k:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

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 <= K and z >= 0:

            cnt += 1
print(cnt)

Submission status: Accepted

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

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())
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:
# Problem B - Sum of Three Integers

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

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

print(count_num)

Submission status: Accepted

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())
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:
import sys

def solve():
    input = sys.stdin.readline
    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)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
l = []
for i in range(k+1):
    for j in range(k+1):
        if s-i-j >= 0 and s-i-j <= k:
            x += 1
print(x)

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

Submission status: Accepted

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K, S = map(int, sys.stdin.readline().split())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
I = list(map(int, input().split()))
K, S = I[0], I[1]

print(len([0 for i in range(K+1) for j in range(K+1) if 0<=S-i-j<=K]))

Submission status: Accepted

Solution code:
def solve():
    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 or K < z:
                continue
            ans += 1

    print(ans)
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#051_B
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)]))