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

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for x in range(k+1):
    for y in range(k+1):
        if x + y <= s:
            if x + y + k >= s:
                res += 1
        else:
            break

print(res)

Submission status: Accepted

Solution code:
nyu = input()
nyu = nyu.split()

k = int(nyu[0])
s = int(nyu[1])

n = 0
for x in range(k+1):
  for y in range(k+1):
    if x+y > s:
      break
    elif s - (x+y) > k:
      #print(str(x) + " " + str(y))
      continue;
    else:
      n +=1;

print(n)

Submission status: Accepted

Solution code:
nyu = input()
nyu = nyu.split()

k = int(nyu[0])
s = int(nyu[1])

n = 0
for x in range(k+1):
  for y in range(k+1):
    if x+y > s or s - (x+y) > k:
      #print(str(x) + " " + str(y))
      continue;
    else:
      n +=1;

print(n)

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

print(cnt)

Submission status: Accepted

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

count= 0

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

Submission status: Accepted

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

Submission status: Accepted

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

#+++++
		
def main():
	k, s = map(int, input().split())
	c=0
	for x in range(k+1):
		for y in range(k+1):
			ccc=s-(x+y)
			c+=1 if ccc <= k and 0<= ccc else 0
	
	print(c)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in reversed(range(k + 1)):
    start = min(k, n - i)
    if n - i - start > k:
        continue
    for j in reversed(range(start + 1)):
        if(n - i - j <= k):
            # print(i, j, n - i - j)
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
ans=0
x=min(k+1,s+1)
y=max(0,s-k-k)
for i in range(y,x):
    for j in range(y,x):
        if i+j>s: break
        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(k+1):
		if 0 <= (s - i - j) <= k:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, stdin
K, S = [int(_) for _ in stdin.readline().rstrip().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:
#! /usr/bin/env python3

K, S = map(int, input().split())
c = 0
for i in range(max(0, S-K*2), min(K+1, S+1)):
    for j in range(max(0, S-i-K), min(K+1, S-i+1)):
       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):
        if x+y <= S and S -(x+y) <= K:
            count += 1
print(count)

Submission status: Accepted

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

K, S = list(map(int, input().split()))
K += 1
cnt = 0
for i in range(min(K, S+1)):
    if i+K*2<=S : continue
    for j in range(min(K, S-i+1)):
        if i+j+K<=S : continue
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
K, S = list(map(int, input().split()))
K += 1
cnt = 0
for i in range(K):
    if i+K*2<=S : continue
    if i>S : continue
    for j in range(min(K, S-i+1)):
        if i+j+K<=S : continue
        if i+j>S : break
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

print(n_combinations)

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):
        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());print(sum(max(0,min(2*k+i-s+1,s-i+1))for i in range(k+1)))

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
r=0
for i in range(k+1):
  r+=max(0,min(2*k+i-s+1,s-i+1))
print(r)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#xはmax(0,s-2*k)からmin(s,k)までの値をとる　min(s,k)+1-max(0,s-2*k)通り
#xを決めた時、yはmax(0,s-(x+k)からmin(s-x,k)までの値をとる　min(s-x,k)+1-max(0,s-(x+k))通り
#x,yを決めた時、zは一意　1通り


l=[]
for i in range(max(0,s-2*k),min(s,k)+1):
    l.append(min(s-i,k)+1-max(0,s-(i+k)))
    
print(sum(l))

Submission status: Accepted

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

l=[]

for i in range(max(0,s-2*k),min(s,k)+1):#xはmax(0,s-2*k)からmin(s,k)までの値をとる
    l.append(min(s-i,k)+1-max(0,s-(i+k)))
    #for j in range(max(0,s-(i+k)),min(s-i,k)+1):
        
#print(l)
print(sum(l))

Submission status: Accepted

Solution code:
import numpy as np
K,S = map(int,input().split())
x1 = np.ones(K+1, dtype=np.int32)
x2 = np.convolve(x1,x1)
x3 = np.convolve(x1,x2)
answer = x3[S]
print(answer)

Submission status: Accepted

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

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

print(counter)

Submission status: Accepted

Solution code:
k,s=map(int,input().split());k+=1;print(sum(k>s-I//k-I%k>=0for I in range(k*k)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


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


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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
print(sum([max(0,min(k,s-i)-max(0,s-i-k)+1) for i in range(k+1)]))

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:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    K,S=map(int,input().split())
    count=0
    for x in range(0,K+1):
        for y in range(0,K+1):
            if S-x-y<=K and S-x-y>=0:
                count+=1
    print(count)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())

Submission status: Accepted

Solution code:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    K,S=map(int,input().split())
    count=0
    for x in range(0,K+1):
        for y in range(0,K+1):
            if(x+y>S):break
            if S-x-y<=K and S-x-y>=0:
                count+=1
    print(count)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())

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

Submission status: Accepted

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


def read_h(typ=int):
    return map(typ, input().split())


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    K, S = read_h()
    cnt = 0
    for x in range(K + 1):
        for y in range(min(S - x, K) + 1):
            z = S - x - y
            if z <= 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):
        if S - (x + y) <= K and S - (x+y) >= 0:
            ans += 1 
print(ans)

Submission status: Accepted

Solution code:
k, s = [int(v) for v in input().split(" ")]
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 = count + 1

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
K,S = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for X in range(0,K+1):
    for Y in range(0,K+1):
            if 0 <= 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):
      if 0 <= s - (i + j) <= 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 0 <= (s - x - y) <= k:
            count += 1
print(count)

Submission status: Accepted

Solution code:
k,s = map(int, input().split())
a = (s+2)*(s+1)/2
b = (s-k+1)*(s-k)/2
c = (s-2*k)*(s-2*k-1)/2
 
if s <= k:
    print(int(a))
elif s <= 2*k:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*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:
n,s = map( int, input().split() )

count = 0
for i in range(n+1):
    for j in range(n+1):
        if s-i-j <= n and s-i-j >= 0:
            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())

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 <= 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):
    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
for x in range(0,k+1):
    for y in range(0, 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())
count = 0
for ai in range(k+1):
    remain = s - ai
    if remain > k * 2 or remain < 0:
        continue
    if remain <= k:
        count += remain + 1
    else:
        count += k * 2 - remain + 1
print(count)

Submission status: Accepted

Solution code:
row = input().split()
K = int(row[0])
S = int(row[1])
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 = [int(n) for n in input().split()]
print(sum([1 for 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())
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())
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())
c = 0

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

Submission status: Accepted

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

    pattern = 0

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

    # Wrong Anser
    # 
    # # 3,4 --> 0 start
    # # 3,5 --> 0 start
    # # 3,7 --> 1 start
    # # 3,8 --> 2 start
    # # 3,9 --> 3 start 
    # # 4,8 --> 0 start
    # # 4,9 --> 1 start
    # # 4,10 --> 2 start
    # # s // k * 2
    # 
    # for x in range(s // 3, k + 1):
    #     for y in range(s // 3, min(k + 1, s - x + 1)):
    #         for z in range(s // 3, min(k + 1, s - x - y + 1)):
    #             if x + y + z == s:
    #                 pattern += 1
    # 

    print(pattern)


if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

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

a = np.array(np.meshgrid(np.arange(K + 1), np.arange(K + 1))).sum(axis=0)
print(((S - K <= a) & (a <= S)).sum())

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

Submission status: Accepted

Solution code:
K, S = list(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 and S - i - j <= K:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
K, S = list(map(int, input().split(' ')))

ccc = 0

for i in range(S+1):
    #x = i のとき
    if i>K:
        break
    #print(f'x={i}')

    for j in range(S-i+1):
        #y = j のとき
        #z = S - i - j
        #print(f'y={j}')
        #print(f'z={S-i-j}')
        if (j<=K) and (S - i - j <= K):
            ccc += 1
        
print(ccc)

Submission status: Accepted

Solution code:
K,S = map(int,input().split())
one = 0
three = 0
six = 0
if S%3==0:
    one = 1
else:
    one = 0
for l in range(K+1):
    if (S-l)%2==0 and (S-l)//2 <= K and (S-l)>=0:
        three += 1
for m in range(K-1):
    for n in range(m+1,K):
        rest = S-(m+n)
        if rest>n and rest<=K:
          six += 1
print(one+3*(three-one)+6*six)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

K, S = LI()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k, s = [ int(v) for v in 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) <= k:
            ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
p=input().rstrip().split(' ')
k=int(p[0])
s=int(p[1])
G=0;
for i in range(0,k+1):
    for j in range(0,k+1):
        b=s-(i+j)
        if b>=0 and b<=k:
            if (i+j+b)==s:
                G+=1;
print(G)

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

K, S = nl()

count = 0
for k1 in range(K+1):
    for k2 in range(K+1):
        k3 = S - (k1 + k2)
        if k3 >= 0 and k3 <= K:
            count += 1

print(count)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
k = a[0]
s = a[1]
num=0
for l in range(k+1):
    for m in range(k+1):
        n = s-l-m
        if(n <= k and n >= 0):
            num+=1

print(num)

Submission status: Accepted

Solution code:
inputs= list(map(int,input().split()))
k = inputs[0]
s = inputs[1]
answer = 0
for i in range(k+1):
  x = i
  for l in range(k+1):
    y = l
    z = s-x-y
    if z >= 0 and z <= 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:
            break
        if (S - x - y) <= K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
inputs= list(map(int,input().split()))
k = inputs[0]
s = inputs[1]
answer = 0
for i in range(k+1):
  x = i
  for l in range(k+1):
    y = l
    z = s-x-y
    if z >= 0 and z <= k :
      answer += 1
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
l = [i for i in range(K+1)]
cnt = 0
for i in l:
    if i > S:
        break
    elif i == S:
        cnt += 1
        break
    elif i < S:
        tmp1 = S-i
        if K-tmp1 >= 0:
            cnt += tmp1 + 1
        else:
            tmp2 = 2*K + 1 - tmp1
            if tmp2 > 0:
                cnt += tmp2
                
print(cnt)

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

Submission status: Accepted

Solution code:
k, s = (int(x) for x in 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):
        z = s-x-y
        if (z>=0) and (z <= k):
            cnt +=1
            
            
print(cnt)

Submission status: Accepted

Solution code:
#ABC51-B

K,S=map(int,input().split())
sum=0
count=0
for i in range(K+1):
    sum+=i
    a=sum
    L=S-sum
    #print(L)
    LL=min(L,K)
    for j in range(LL+1):
        sum+=j
        if S-sum>=0 and S-sum<=K :
            count+=1
            #print(str(i)+" "+str(j))
        sum=a #jを足す前に戻す
    sum=0
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) :
            # print("{0} {1} {2}".format(x, y, s-x-y))
            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(min(K+1,S-x+1)):
        z=S-x-y
        if 0<=z<=K:
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

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

ans = 0
for x in range(K + 1):
    yz = S - x
    if yz < 0 or 2 * K < yz:
        continue
    ans += yz + 1
    ans -= max(0, yz - K) * 2
print(ans)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
ans=0
for x in range(k+1):
    if x>s:
        break
    for y in range(k+1):
        if y>s:
            break
        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(min(k+1,s+1-x)):
        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 = map(int, stdin.readline().rstrip().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)

input = lambda: stdin.readline()
main()

Submission status: Accepted

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

    print(count)