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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    k,s = map(int,readline().split())
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            if s-i-j <= k and i+j <= s:
                ans += 1
    print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
k,s = map(int,stdin.readline().rstrip().split())
point = 0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-(i+j) <= k:
            point += 1
print(point)

Submission status: Accepted

Solution code:
from sys import stdin
k,s = map(int,stdin.readline().rstrip().split())
point = 0
for i in range(k+1):
    for j in range(k+1):
        if i+j > s:
            continue
        elif s-(i+j) <= k:
            point += 1
print(point)

Submission status: Accepted

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

Submission status: Accepted

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

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

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 = list(map(int,input().split()))
ans = 0

for i in range(k+1):
    for j in range(k+1):
        if i+j > s:
            break
        if s-i-j <= k:
            ans += 1

print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    K,S = map(int, readline().split())

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

result = 0

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

print(result)

Submission status: Accepted

Solution code:
#ABC051

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

count = 0

for i in range(k+1):#x
    for j in range(k+1):#y
        #z = S-X-Y
        if 0 <= s - i - j <= k:
            count += 1
print(count)

Submission status: Accepted

Solution code:
K,S=map(int,input().split())
ans = 0
z = 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):
        z = S - (x + y)
        # print('x: {} | y: {} | z: {}'.format(x,y,z))
        if(z<0 or z>K):
            continue
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
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 = 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:
# ABC 051 B Sum of Three Integers

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

Submission status: Accepted

Solution code:
def solve():
    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:
                z = S-(x+y)
                if x+y+z == S:
                    c += 1
    return c

print(solve())

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
k, s = [int(i) for i in input().split()]
print([0 <= s-i-j <= k for i in range(k+1) for j in range(k+1)].count(True))

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

Submission status: Accepted

Solution code:
import itertools

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

X = range(K + 1)
Y = range(K + 1)
Z = range(K + 1)

count = 0
for i, j in itertools.product(X, Y):
  if S - i - j in Z:
    count += 1
print(count)

Submission status: Accepted

Solution code:
ks = input().split(' ')

k = int(ks[0])
s = int(ks[1])
cnt = 0

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



print(str(cnt))

Submission status: Accepted

Solution code:
def solve():
    K, S = [int(x) for x in 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
    return res

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

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(" "))
answer = 0

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

Submission status: Accepted

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

get = 0

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

Submission status: Accepted

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


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

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

way=0

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

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:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
x,y,z = k,k,k
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
input = sys.stdin.readline

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

# X + Y = A
# Z = S - A
ans = 0
for A in range(2*K+1):
    Z = S - A
    if 0 <= Z and Z <= K:
        for X in range(K+1):
            Y = A - X
            if 0 <= Y and Y <= 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):
        k = S - i -j
        if 0 <= k <= 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:
import sys
input = sys.stdin.readline

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

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

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
import sys


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

# min_num = s - k * 2
# if min_num <= 0:
min_num = 0

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys


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

min_num = s - k * 2
if min_num <= 0:
    min_num = 0

ans = 0

for x in range(min_num, k + 1):
    for y in range(min_num, k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        else:
            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 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(0,K+1,1):
    for y in range(0,K+1,1):
        if ((S-x-y)>=0)and((S-x-y)<=K):
            count=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):
        t = s-i-j
        if t <= k and t >= 0:
            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):
        t = s-i-j
        if t <= k and t >= 0:
            count += 1
        else:
            pass
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):
        if S - i - j < 0 or S - i - j > K:
            continue
        else:
            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+k >= s and s-i-j >= 0:
            count += 1
        else:
            continue

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

flg = 0

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

print(flg)

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    K, S = MI()
    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)


if __name__ == '__main__':
    main()

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

print(ans)

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):
    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())
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:
try:
    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)
except EOFError:
    pass

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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=map(int,input().split())

arr=[]
cnt=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:
        cnt+=1
      elif x==y or y==z or z==x:
        cnt+=3
      else:
        cnt+=6
print(cnt)

Submission status: Accepted

Solution code:
a,sums=list(map(int,input().split()))
if a*3==sums:
  print(1)
else:
  ret=0
  for x in range(a+1):
    if (sums-x <=2*a)&(sums>=x):
      for y in range(a+1):
        if (sums-x-y>=0)&(sums-x-y<=a):
          ret+=1
  print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
try:
    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)
except EOFError:
    pass

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k, s = [int(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        z = s - x - y
        if y <= z and z <= k:
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 6
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())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z >= 0 and z <= k:
            cnt += 1

print(cnt)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
ans = 0
for 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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import copy


def main():
    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 or z > K:
                continue
            else:
                result += 1

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(str(count))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
K,S = [int(i) for i 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())
list = []
for x in range(k + 1):
    for y in range(k - x + 1):
        z = s - (x + x + y)
        if x + y <= z <= k: list.append([x, y + x, z])
        y += 1
    x += 1

answer = 0
for id in list:
    if id[0] == id[1] == id[2]: answer += 1
    elif id[0] == id[1] or id[1] == id[2]: answer += 3
    else: answer += 6
print(answer)

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:
#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt=0
    x_max = S if K >= S else K
    for x in range(0, x_max+1):
        y_max = S-x if K >= S-x else K
        for y in range(0, y_max+1):
            z = S - x - y
            if z <= K:
                cnt+=1
    return cnt


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
    print(solve(K, S))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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