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())
cnt=0
for x in range(k+1):
  if s-x<0:
    break
  elif s-x<=k:
    cnt+=(s-x)+1
  elif s-x>2*k:
    cnt+=0
  elif s-x>k:
    cnt+=2*k-(s-x)+1
print(cnt)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
x=0
b=0
while x<=k and x<=s//3:
  y=x
  while x+y<=s and y<=k and y<=(s-x)//2:
    z=s-x-y
    if z>=0 and z<=k:
      if x==y and y==z:
        b=b+1
      elif x==y:
        b=b+3
      elif y==z:
        b=b+3
      else:
        b=b+6
    y=y+1
  x=x+1
print(b)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
x=0
b=0
while x<=k and x<=s//3:
  y=x
  while x+y<=s and y<=k and y<=(s-x)//2:
    z=s-x-y
    if z>=0 and z<=k:
      if x==y and y==z:
        b=b+1
      elif x==y:
        b=b+3
      elif y==z:
        b=b+3
      else:
        b=b+6
    y=y+1
  x=x+1
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
x=0
b=0
while x<=k and x<=s//3:
  y=x
  while x+y<=s and y<=k and y<=(s-x)//2:
    z=s-x-y
    if z>=0 and z<=k:
      if x==y and y==z:
        b=b+1
      elif x==y:
        b=b+3
      elif y==z:
        b=b+3
      else:
        b=b+6
    y=y+1
  x=x+1
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = list(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):
        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):
    if i > S:
        break
    for j in range(K+1):
        if i + j > S:
            break
        elif 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(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())
ans  = 0
for i in range(0,k+1):
  for j in range(0,k+1):
    z = s-i-j
    if z >= 0 and z <= k:
      ans += 1
print(ans)

Submission status: Accepted

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

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

print(pattern)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 =[int(i) for i in input().split()]
C = 0
for X in range(K+1):
    for Y in range(K+1):
        if X+Y <= S <= X+Y+K:
            C += 1
print(C)

Submission status: Accepted

Solution code:
from sys import stdin
n = input().split(' ')
c = 0
K = int(n[0])
S = int(n[1])
for i in range(int(K)+1):
    for j in range(int(K)+1):
        if(S-(i+j) <= K and S>=i+j):
            c+=1
                
print(c)

Submission status: Accepted

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

for x in range(k+1):
    for y in range(k+1):
        if s-k <= x+y <= s:
            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 = 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):
        count+=X+Y<=S<=X+Y+K

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

Submission status: Accepted

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

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):
        d = s-x-y
        if 0 <= d and d <= 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:
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 K >= S - (X + Y):
            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 0 <= z <= k:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
K, S = [int(x) for x in input().split()]
count = 0
for x in range(K+1):
    # y + z = S - x
    if 0 <= S - x <= K: 
        count += S - x + 1 
        # yに選べるのは0から(y+z)までのy+z-0+1通りすなわちS-x+1
    elif K < S - x <= 2 * K:
        count += 2 * K - S + x + 1 
        # K - ((S - x) - K) + 1
        # excess = (S-x)-K
    else: 
        # S-x > 2Kだと、y+z > 2Kとなり、
        # こうなる組みは存在しない
        continue
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

result = 0

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

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(min(K,S)+1):
    for j in range(min(K,S-i)+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 i+j<=s:
            if i+j+k>=s:
                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= 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())
count = 0
for i in range(k+1):
    if (s - i) / 2 > k:
        continue
    for j in range(k+1):
        z = s - i - j
        if 0 <= z <= k:
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# abc051 b
#
import unittest
from io import StringIO
import sys


def input():
    return sys.stdin.readline().rstrip()


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


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 15"""
        output = """1"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
cnt=0
for i in range(k+1):
    for j in range(k+1):
        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):
        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 i in range(K + 1):
    if 0 <= S - i < K:
        count += S - i + 1
    elif K <= S - i <= 2 * K:
        count += 2 * K - S + i + 1
    else:
        continue
print(count)

Submission status: Accepted

Solution code:
import sys
import math

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

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


print(ans)

Submission status: Accepted

Solution code:
"""
AtCoder Beginner Contest 051
B - Sum of Three Integers
"""

if __name__ == "__main__":
    K, S = map(int, input().split())

    ans = 0
    A = [i for i in range(K+1)]
    for x in A:
        for y in A:
            if x + y > S or S - (x + y) > K:
                continue
            ans += 1

    print(ans)

Submission status: Accepted

Solution code:
"""
AtCoder Beginner Contest 051
B - Sum of Three Integers
"""

if __name__ == "__main__":
    K, S = map(int, input().split())

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

    print(ans)

Submission status: Accepted

Solution code:
k,s=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 = 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 = input().split()
K = int(K_S[0])
S = int(K_S[1])

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

print(count_pattern)

Submission status: Accepted

Solution code:
K_S = input().split()
ans = 0
for X in range(int(K_S[0]) + 1):
    for Y in range(int(K_S[0]) + 1):
        Z = int((K_S[1])) - X - Y
        if 0 <= Z & Z <= int(K_S[0]):
            ans += 1

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(K: int, S: int):
    answer=0
    for i in range(K+1):
        for j in range(K+1):

            if 0<=S-i-j<=K:
                answer+=1
                    
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

lst_temp = [ int(i) for i in range(K + 1)]

recCnt = 0
for x in lst_temp:
  for y in lst_temp:
    z = S - x - y 
    if z >= 0 and z <= K:
      recCnt += 1
      
print(recCnt)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
for i in reversed(range(K+1)):
    tmp = S - i
    for j in reversed(range(K+1)):
        tmp_tmp = tmp -j
        if tmp_tmp < 0 or tmp_tmp > K:
            continue
        else:
            # print(i, j, tmp_tmp)
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
K, S = map(int, input().split())
ans = 0
for z in range(0, min(S + 1, K + 1)):
    #print(z)
    if S - z <= 2 * K:
        x1 = min(K, S - z)
        y1 = S - z - x1

        y2 = min(K, S - z)
        x2 = S - z - y2

        ans += gcd(abs(x1 - x2), abs(y1 - y2)) + 1
        #print(ans)
print(ans)

Submission status: Accepted

Solution code:
KS = list(map(int,input().split()))
sum =0
K = KS[0]
S = KS[1]
N=K+1
for i in range(N):
	if(S-i) > 2*K:
		continue
	for m in range(N):
		if(i+m) > S:
			break
		if (S -m-i) <= K:
			sum+=1
print(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 >=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(0, K+1):
    for y in range(0, K+1):
        if s - (x + y) <= K and s - (x + y) >= 0 :
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# ABC051 B - Sum of Three Integers
K,S = map(int,input().split())
ans = 0
for i in range(0,K+1):
    for j in range(0,K+1):
        k = S-i-j
        if 0<=k<=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 not (0 <= z <= k):
            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):
        t = s - (i + j)
        if 0 <= t <= k:
            count += 1
print(count)

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

Submission status: Accepted

Solution code:
import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__main__":
    k, s = map(int, input().split())
    res = 0
    mi = min(k, s)
    ma = max(k, s)
    for i in range(mi + 1):
        for j in range(mi + 1):
            if 0 <= s - i - j and s - i - j <= k:
                res += 1
    print(res)

Submission status: Accepted

Solution code:
import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__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)

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

Submission status: Accepted

Solution code:
# N^2
K, S = map(int, input().split())

K+=1

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

print(count)

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    k, s = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(k + 1):
        for j in range(k + 1):
            n = s - i - j
            if 0 <= n <= k:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

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

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

Submission status: Accepted

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


OK = 0
for x in range(K+1):
    if(0<=S-x & S-x<=2*K): # 計算の成立条件
        if(S-x<=K): # yとzの和がk以下
            OK += S-x+1
        else: # yとzの和がk以上
            OK += (K-((S-x)-K))+1
print(OK)

Submission status: Accepted

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


def calc_xyz(target, limit):
    cnt = 0
    for x in range(min(limit, target) + 1):
        yz_sum = target - x
        for y in range(min(limit, yz_sum) + 1):
            if 0 <= target - x - y <= limit:
                cnt += 1
    return cnt


print(calc_xyz(s, k))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    k, s = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(k + 1):
        for j in range(k + 1):
            if i + j > s:
                break
            else:
                n = s - i - j
                if 0 <= n <= k:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
result = [i_1+i_2 for i_1 in range(k+1) for i_2 in range(k+1) if 0<=s-i_1-i_2<=k]
print(len(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(K, S):
    num=0
    for a in range(K+1):
      if S-a>=0 and S-a<=2*K:
        if S-a<=K:
          num+=S-a+1
        else:
          num+=(K-((S-a)-K))+1
    return num

  
K,S=(int(x) for x in input().split())
print(f(K,S))

Submission status: Accepted

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

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

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

print(res)

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:
K, S = map(int, input().split())
cnt=0
for X in range(K+1):
  for Y in range(K+1):
    if K>=S-(X+Y) and X+Y<=S:
      cnt=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())
cases = 0

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

print(cases)

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(min(K+1,S-x+1)):
        y = j
        z = S-x-y
        if x + y + z == S and z <= K:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import sys

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 i in range(min(S + 1, K + 1)):
    s = S - i
    if s > 2 * K:
        continue
    ans += min(K, s) - max(0, s - K) + 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 i in range(K + 1):
    if i > S:
        break
    for j in range(K + 1):
        s = i + j
        if s > S:
            break
        Z = S - s
        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):
    s = i
    if s > S:
        break
    for j in range(K + 1):
        s = i + j
        if s > S:
            break
        Z = S - s
        if 0 <= Z <= K:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for x in range(K+1):
  if K<S-x<=2*K:
    a+=2*K-S+x+1
  elif 0<=S-x<=K:
    a+=S-x+1
  else:
    a+=0

print(a)

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:
def main():
    k, s = map(int, input().split())
    if s > 3*k:
        pass
    elif s == 3*k:
        ans = 1
    else:
        ans = 0
        for i in range(k+1):
            for j in range(k+1):
                    if 0<=s - (i + j)<=k:
                        ans += 1
    print(ans)
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):
        ans+=1 if k>=s-(x+y)>=0 else 0
print(ans)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
k,s=map(int,input().split())
cnt=0

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