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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

def main():

    ans = 0
    for x in range(K + 1):
        for y in range(x + 1):
            z = S - x - y
            if z < 0 or\
                K < z or\
                x < z or\
                y < z:
                continue
            if x == y == z:
                ans += 1
            elif x != y != z:
                ans += 6
            else:
                ans += 3
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ways)

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
# debug
# print([(A,B,S-A-B) for A in range(K+1) for B in range(K+1) if 0 <= S-A-B <= K])
print(sum(1 for A in range(K+1) for B in range(K+1) if 0 <= S-A-B <= K))

Submission status: Accepted

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

print(sum(min(K, S-x) - max(0, S-x-K) + 1 for x in range(max(0, S-2*K), min(K, S)+1)))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
ret = 0
for A in range(S+1):
    if A > K: continue
    for B in range(S+1-A):
        if B > K:continue
        # print(A,B,S-A-B)
        if S-A-B <= K: 
            # print(A,B,S-A-B)
            ret += 1
print(ret)

Submission status: Accepted

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

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

cnt = 0

for x in range(k+1):
    if 0 <= s-x <= k:
        cnt += s-x+1
    elif k < s-x <=2*k:
        cnt += 2*k - (s-x) +1
print(cnt)

Submission status: Accepted

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

ans = 0
for x in range(k+1)[::-1]:
    y = min(s-x, k)
    z = s-x-y
    if z > k:
        break
    if x >= 0 and y >= 0 and z >= 0:
        ans += y - z + 1

print(ans)

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
 
ans = 0
 
for X in range(K+1):
	S1 = S - X
	if S1 < 0:
		break
	else:
		if S1 <= K:
			ans += S1 + 1
		elif S1 <= 2 * K:
			ans += 2*K - S1 + 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):
         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())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

print(r)

Submission status: Accepted

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

#2 つの整数 K,S が与えられます。
#3 つの変数 X,Y,Z があり、0≦X,Y,Z≦K を満たす整数の値を取ります。
#X+Y+Z=S を満たす X,Y,Z への値の割り当ては何通りありますか。
ans = 0

for i in range(0,min(K,S)+1):
  # Y+Z = S - i
  # 0 <= Y <= S-i
  #print(i,S-i)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
print(sum(max(0, min(2*K-S+z+1, S-z+1)) for z in range(K+1)))

Submission status: Accepted

Solution code:
K,S = map(int, input().split())
ans = 0
for z in range(K+1):
    ans += max(0, min(2*K-S+z+1, S-z+1))
print(ans)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
ans = 0
for i in range(K+1):
    if min(S-i, K) == K:
        ans += max(2 * K - (S - i) + 1, 0)
    else:
        ans += max(S - i + 1, 0)
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())
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,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())
cnt=0

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc051/tasks/abc051_b

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

# initialize
ans = 0

# logic: 全探索: 基本形
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:
# n n,
k, s = map(int, input().split())

# initialize
ans = 0

# logic: 全探索: 基本形
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())
count=0
for a in range(k+1):
  for b in range(k+1):
    if 0<=s-a-b<=k:
      count+=1
print(count)

Submission status: Accepted

Solution code:
#083 b-some sums
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 k>=z:
            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())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# problem: https://atcoder.jp/contests/abc051/tasks/abc051_b

K, S = [int(i) for i in input().split()]
res = 0

for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if 0 <= k <= 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 reversed(range(k + 1)):
        sum = x + y
        if sum > s:
            continue
        if s - sum <= 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())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
K, S = map(int, input().split())
#A = str(input())

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

Submission status: Accepted

Solution code:
# WAになったのでシンプルな愚直法で解き直し

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

Submission status: Accepted

Solution code:
"""
Y+Z=S−X  が成り立つことは分かるものの1通りには決まりません。
満たすべき条件は 0≤Y,Z≤K と Y+Z=S−X なので、変数 Z を消去すると以下の不等式が得られます。

0≤Y≤K
0≤Z=S−Y−X≤K
変形して、Y≤S−X かつ S−X−K≤Y

つまり Y の下限は Ymin=max(0,S−X−K) 、
上限は Ymax=min(K,S−X) となります。

"""

K, S = map(int, input().split())
ans = 0
for x in range(K+1):
  mn = max(0, S-x-K)
  mx = min(K, S-x)
  ans += max(0, mx-mn+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())
cnt=0
l=[]
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 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:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

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

ans = 0
for i in range(K+1):
    if min(S-i, K) == K:
        ans += max(2 * K - (S - i) + 1, 0)
    else:
        ans += max(S - i + 1, 0)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
import fractions

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

Submission status: Accepted

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

Submission status: Accepted

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

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+1:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*c))

Submission status: Accepted

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

nums=list(map(int,input().split()))
k = nums[0]
s = nums[1]

sm = 0
upper = 0
lower = 0
left = max(s-k*2, 0)
right = min(s, k)

for x in range(left, right + 1):
    upper = min(s-x, k)
    lower = max(s-k-x, 0)
    sm += upper - lower + 1
    
print(sm)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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:
import sys
k,s = map(int, sys.stdin.readline().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 = input().strip().split()
K, S = int(K), int(S)

NUMS = list(range(K+1))

sums = {}

count = 0

for x in NUMS:
  for y in NUMS:
    if x+y not in sums:
      sums[x+y] = 0
    sums[x+y] += 1
for k, v in sums.items():
  z = S - k
  if z in NUMS:
    count += v
print(count)

Submission status: Accepted

Solution code:
k, s = list(map(int, input().split()))
count = 0
for i in range(0, k + 1):  # X value
    for j in range(0, k + 1):  # Y value
        if 0 <= s - i - j <= k:  # s - i - j = Z
            count += 1
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

k,s=map(int,input().split())
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 = 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 and Z <= K:
            answer += 1

print(answer)

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 sys
input = sys.stdin.readline

def main():
    K,S = [int(x) for x in 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)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    K,S = (int(x) for x in 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)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 入力
k,s=map(int,input().split())
b = [x for x in range(k+1) for y in range(k+1) if 0<=(s-x-y)<=k]
print(len(b))

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

cnt = 0
for i in range(k+1):
    if i > s:
        continue
    for j in range(k+1):
        if i + j > s or i + j + k < s:
            continue 
        cnt += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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):
        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 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:
import sys

k, s = map(int, sys.stdin.readline().split())

def main():
    cnt = 0
    for x in range(min(s, k) + 1):
        t = s - x
        if 0 <= t <= k:
            cnt += t + 1
        elif k < t <= k * 2:
            cnt += k + 1 - (t - k)
    return cnt

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

Submission status: Accepted

Solution code:
def solve():
    K, S = map(int, input().split())
    # print(K, S)

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = [int(i) for i in input().split()]
AA = [1 for X in range(K+1) for Y in range(K+1) if 0<=S-X-Y<=K]
print(len(AA))

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
cnt = 0
z = list(range(k+1))

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = [int(num) for num in 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(' '))
r = 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:
            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
x = range(k + 1)
y = range(k + 1)


for i in x:
	for j in y:
			if 0 <= s - i - j <= k:
				ans += 1

print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    k, s = list(map(int, readline().split()))
    cnt = 0
    for x in range(k + 1):
        for y in range(k + 1):
            ts = s - x - y
            if 0 <= ts <= k:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for X in range(K+1):
    for Y in range(K+1):

        Z = S-X-Y

        if 0<=Z and Z<=K:
            count = count + 1

print(count)

Submission status: Accepted

Solution code:
line = input().split(" ")
k = int(line[0])
s = int(line[1])
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:
# coding: utf-8


def solve(*args: str) -> str:
    k, s = map(int, args[0].split())

    ret = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s-(x+y)
            if z < 0:
                break
            elif z <= k:
                ret += 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0
for X in range(0, K+1):
    for Y in range(0, K+1):
        if S-(X+Y)>=0 and 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<0:
            break
        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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

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


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = [int(i) for i in 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())

range_x = range(K+1)
range_y = range(K+1)

counter = 0
for x in range_x:
	for y in range_y:
		z = S - x - y
		if 0 <= z <= K:
 			counter += 1
print(counter)

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

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

cnt = 0

for i in range(min(k,s)+1):
    for j in range(min(k,s)+1):
        memo = s-i-j

        if 0<=memo and memo<=k:
            cnt += 1
            

print(cnt)

Submission status: Accepted

Solution code:
def main():
    k, s = map(int, input().split())
    ans = 0
    for z in range(s//3, k+1):
        for y in range((s-z)//2, s-z+1):
            x = s-z-y
            if x <= y and y <= z:
                if x == y and y == z:
                    ans += 1
                elif x == y or y == z:
                    ans += 3
                else:
                    ans += 6
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    K,S=list(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(i) for i in input().split()]
def a(n):
  return int(n * (n + 1) / 2)
  
if s <= k:
  print(a(s + 1))
elif s >= 2 * k and s <= 3 * k:
  print(a(3 * k - s + 1))
elif s > k and s < 2 * k:
  print(a(s + 1) - 3 * a(s - k))
else:
  print(0)