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

# arr = []
# for i in range(0,k+1):
#     arr.append(i)

# def binary_search(arr,i):
#     x = arr
#     low = 0
#     high = len(x)-1
#     t = (low + high) // 2 
#     # 探索の下限のlowが上限のhighになるまで探索
#     # lowがhighに達すると数は見つからなかったということ
#     while (low<=high):
#         if (i==x[t]):
#             break
#         elif (i > x[t]):
#             low = t + 1
#         elif (i < x[t]):
#              high = t - 1
#         t = (low + high) // 2

#     if (i==x[t]):
#         return t
#     else:
#         return -1




# for i in range(0,k+1):
#         l = s - i - j
#         arr = arr[]
#         answer = binary_search(arr,l)
#         # print(i,j,l)
#         if(answer!=-1):
#             # print('clear',i,j,l)
#             count += 1

for i in range(0,k+1):
    for j in range(i,k+1):
        l = s-i-j
        if l>=j and l <= k:
            if i!=j and j != l and i!=l:
                # print(i,j,l)
                count += 6
            elif i == j and j == l and i == l:
                # print(i,j,l)
                count += 1
            else:
                # print(i,j,l)
                count += 3

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

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
res = 0
for x in range(k+1):
  if 3 * x == s:
    res += 1
for x in range(k+1):
  for y in range(k+1):
    if x == y:
      continue
    if 2 * x + y == s:
      res += 3
for x in range(k+1):
  for y in range(x+1, k+1):
    d = s - x - y
    if d > y and d <= k:
      res += 6

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

print(ans)

Submission status: Accepted

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

count = 0

if s > 3 * k:
    print(count)

else:
    for i in range(k + 1):
        x = i
        if x < s:
            for j in range(k + 1):
                y = j
                if s - (x + y) <= k and x + y <= s:
                    count = count + 1
                elif x + y > s:
                    break
        elif x == s:
            count = count + 1
        else:
            break

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
temp = list(map(int,input().split()))
K = temp[0]
S = temp[1]
newK = K+1
cnt = 0
minlim = S-K
maxlim = S
for x in range(0, newK):
    for y in range(0, newK):
        if minlim <= x+y and x+y <= maxlim:
            cnt += 1
print(str(cnt))

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

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
cnt=0
for l in range(k+1):
    for m in range(k+1):
        #2つが定まるともう一つの値は一意に定まる
        if 0<=s-l-m and s-l-m<=k:
            cnt+=1
            #print(l,m,n)
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S - i > 2 * K:
        continue
    elif S - i < 0:
        break
    if S - i > K:
        ans += 2 * K + 1 - S + i
    else:
        ans += S - i + 1
print(ans)

Submission status: Accepted

Solution code:
k,s = [int(i) for i in 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())
s=0
for i in range(K+1):
    for j in range(K+1):
        t=S-i-j
        if 0<=t and K>=t:
            s+=1
print(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):
        ans += 1 if 0 <= S - x - y <= K else 0
print(ans)

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)<=K:
                c += 1

print(c)

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-k<=i+j<=s):
            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(x, k+1):
        z = s-x-y
        if y <= z <= k:
            if x == y == z:
                c += 1
            elif x == y or y == z:
                c += 3
            else:
                c += 6

print(c)

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):
        z = S-x-y
        if 0 <= z <= K:
            c += 1

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
limit, target = map(int, input().split(" "))
answer = 0
for i in range(limit + 1):
    for j in range(limit + 1):
        if 0 <= target - i - j <= limit:
            answer += 1
            # print(i, j, target - i - j)

print(answer)

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())
X = range(K + 1)
Y = range(K + 1)
Z = range(K + 1)

count = 0

for i in X:
    for p in Y:
        if (S - (i + p)) in Z:
            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 z < 0 or z > K:
            pass
        else:
            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):
        if x + y <= s <= x + y + k:
            cnt += 1

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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
        ans += 0 <= z <= K

print(ans)

Submission status: Accepted

Solution code:
def main():
    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
            ans += 0 <= z <= K

    print(ans)

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

Submission status: Accepted

Solution code:
"""AtCoder"""

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

ans = 0

for i in range(K+1):
  for j in range(K+1):
    if i + j <= N and i + j + K >= N:
      ans += 1



print(ans)

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

Submission status: Accepted

Solution code:
#051B
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(k<=K and 0<=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):
        if 0 <= s-x-y <=k:
            cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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 = 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):
        #print(i,j)
        if 0<=S-i-j<=K:
            cnt=cnt+1
            #print(cnt)
print(cnt)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
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())
p=0
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-x-y<=k:
            p+=1
print(p)

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:
K, S = map(int, raw_input().split())

ans = 0
for X in range(K+1):
  ans += max(0, min(K, S-X) - max(0, S-X-K) + 1)
print ans

Submission status: Accepted

Solution code:
K, S = [int(x) for x in 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())
Xm = k
Ym = k
Zm = k #使わない
count = 0
for i in range(Xm+1):
  for j in range(Ym+1):
    if 0<= s - (i+j) <= k:
        count += 1
print(count)

Submission status: Accepted

Solution code:
# B - Sum of Three Integers
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:
            # print(x,y,z)
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 051 B - Sum of Three Integers　
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
i = list(range(k+1))

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

Submission status: Accepted

Solution code:
#k,sを入力から取得する
k,s = map(int, input().split())

#2重forでx,y,zを探索する。組み合わせを見つけるたびにcntを+1していく
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,-1):
    if s-x > k*2:
        break
    if s < x:
        continue
    for y in range(k,-1,-1):
        if s-x-y > k:
            break
        if 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(max(0,S-K-x), min(K+1,S-x+1)):
    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 += 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+=1
    else:pass
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(0<=(S-x-y)<=K):
      count+=1
    else:pass
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

result = 0

for x in range(K + 1):
    c = max(K - abs(S - K - x) + 1, 0)
    # print("*", x, c)
    result += c

print(result)

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] = [int(i) for i in input().split()]
count = 0
for x in range(k+1):
  for y in range(min(s-x+1,k+1)):
      if 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):
    if 0 <= s - (x + y) <= k:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
# Sum of Three Integers
import sys

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

def getAns(k, s) :
    cnt = 0
    for x in range(k + 1) :
        for y in range(k + 1) :
            z = s - x - y
            if 0 <= z <= k :
                cnt += 1
    return cnt
print(getAns(K, S))

Submission status: Accepted

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

n = 0

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

                
print(n)

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

Submission status: Accepted

Solution code:
#1-6-1  #ABC051B
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())

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:
# https://atcoder.jp/contests/abc051/tasks/abc051_b

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


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

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
way = 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):
            way += 1
print(way)

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 s-i-j<=k and s-i-j>=0:
      c+=1

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for z in range(min(k, s)+1):
    ans += max(0, min(s-z, k)+1-(max(0, s-z-k)))
print(ans)

Submission status: Accepted

Solution code:
l     = input().split()
K, S  = map(int, l)
max   = K+1
count = 0
z     =	0

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

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

Submission status: Accepted

Solution code:
import itertools

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

count = 0
for x in range(max(0, s - 2 * k), min(k + 1, s + 1)):
    count += min(s - x, 2 * k - (s - x)) + 1

print(count)

Submission status: Accepted

Solution code:
import itertools

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

count = 0
for x, y in itertools.product(range(k + 1), repeat = 2):
    if x + y <= s <= x + y + k:
        count += 1

print(count)

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):
        if x + y <= 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
        if S-i-j < 0: break
    if i > S: break

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(x, K + 1):
        z = S - (x + y)
        if y <= z and z <= K:
            if x == y and y == z:
                ans += 1
            elif x == y or y == z or z == x:
                ans += 3
            else:
                ans += 6

print(ans)

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

Submission status: Accepted

Solution code:
k,s=[int(i) for i in input().split()]
count=0
for y in range(k+1):
 for x in range(k+1):
   if s>=x+y and s<=k+x+y:
      count=count+1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s=map(int, input().split())
r=range
ans=[1 for x in r(k+1) for y in r(k+1)if x+y<=s and s-x-y<=k]
print(sum(ans))

Submission status: Accepted

Solution code:
import sys

"""テンプレ"""

# 高速
input = sys.stdin.readline

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


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


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


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

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

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

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

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


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

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

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

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

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




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

k, s = intline()
r = range
ans = 0
for x in r(k+1):
    for y in r(k+1):
        if x + y <= s and 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)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

counter = 0

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

print(counter)

Submission status: Accepted

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

print(len(res))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
for i in range(a+1):
    if b-i<1:
        c+=1
        break
    elif b-i<=2*a:
        if b-i<a:
            c+=b-i+1
        else:
            c+=2*a+1-b+i
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

#フラグ設定
flag = 0

#全探索
for x in X:
    for y in Y:
        #条件に合うzの値を算出
        z = S - x - y
        if z<=K and z>=0:  #上で求めたzの値に問題文からFilterを掛ける
            flag += 1

#出力
print(flag)

Submission status: Accepted

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

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

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

print(ANS)

Submission status: Accepted

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

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

print(r)

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

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