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())
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(" "))
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:
#ABC 051 B Sum of Three Integers　

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

Submission status: Accepted

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

count = int(0)

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == '__main__':
    AtCoder().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):
    z=s-i-j
    if 0<=z<=k:
      ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import random
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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

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

print(ans)

Submission status: Accepted

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

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
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:
def main():
    K, S = map(int, input().split())
    count = 0
    for a in range(K+1):
        for b in range(K+1):
            c = S - a - b
            if 0 <= c <= K:
                count += 1
    return count
if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
        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(min(k+1, s-x+1)):
        if k >=s - x - y >= 0:
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

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

print(cnt)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

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

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

Submission status: Accepted

Solution code:
import itertools
K,S = map(int, input().strip().split(' '))
ans = 0
for x,y in itertools.product(range(K+1), repeat=2):
  if 0 <= S-x-y <= K:
    ans += 1
print(ans)

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 0 <= z and z <= k:
            count += 1

print(count)

Submission status: Accepted

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

def main():
    K,S = map(int, input().split())
    n = 0
    for i in range(K+1):
        for j in range(K+1):
            if S-i-j >= 0 and S-i-j <= K:
                n += 1
    print(n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
total = 0
for i in range(k+1):
    for j in range(k+1):
        if (i+j > s) or (s-i-j > k):
            continue
        else:
            total += 1
print(total)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    K, S = (int(i) for i in input().split())
    ans = 0
    for i in range(K+1):
        for j in range(K+1):
            k = S - i - j
            if 0 <= k <= K:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
a=0
b=0
c=0
l=0
while l*2<=s and l<=k:
    if s-l*2<=k:
        b+=1
    l+=1
if s%3==0:
    a+=1
    b-=1
for x in range(k+1):
    for y in range(x+1,k+1):
        if k>=s-x-y>y:
            c+=1
print(a+3*b+6*c)

Submission status: Accepted

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

count = 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
        count += 1

print(count)

Submission status: Accepted

Solution code:
k,s=input().split()
k,s=int(k),int(s)
c=0
for i in range(k+1):
    s1=s-i
    if s1<0:
        break
    for j in range(k+1):
        s2=s1-j
        if s2<0:
            break
        if 0<=s2<=k:
            c+=1

print(c)

Submission status: Accepted

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

ans2()

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

print(cnt)

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 0 <= z <= k:
            count += 1

print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
# Sum of Three Integers
K, S = map(int, input().split())

ans = 0

for x in range(K+1): # xは0からKまで走る
	for y in range(K+1): # yは0からKまで走る
		z = S - x - y # zはこの時点で決まる
		if 0 <= z <= K:
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
###
#Sum of Three Integers
###
k, s = map(int, input().split())
count = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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 0<=S-X-Y<=K:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
K,S= list(map(int, input().split()))
ans=0
for i in range(S//3,K+1):
    for j in range(i+1):
        if i+j>S:
            break
        if i+j*2<S:
            continue
        if S-i-j<=j:
            k=S-i-j
            if i==j==k:
                ans+=1
            elif i==j or j==k:
                ans+=3
            else:
                ans+=6
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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:
ks = input().split()

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

ans = 0

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
K, S = [int(i) for i in stdin.readline().rstrip().split()]
output = 0
for x in range(K+1):
    for y in range(K+1):
        if (S - x - y >= 0) & (S - x - y <= K):
            output += 1

print(output)

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

Submission status: Accepted

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

print(ret)

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):
    Z = S-X-Y
    if 0 <= Z <= K:
      r += 1
print(r)

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 = [int(i) for i in input().split()]
xyzlist=[]
ct = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S-i-j and S-i-j <= K:
            ct += 1
print(ct)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
ans = 0
for z in range(K+1):
    if S - z > 2*K or S < z:
        continue
    elif K < S - z <= 2*K:
        ans += K - (S - z - K) + 1
    else:
        ans += S - z + 1
print(ans)

Submission status: Accepted

Solution code:
ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            z = ks[1] - (targetX + targetY)
            
            if 0 <= z and z <= ks[0]:
                count += 1
                
        
        
        
 
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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 <= K and S - i - j >= 0:
            counter += 1

print(counter)
print("\n")

Submission status: Accepted

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

counter = 0

#すべての値が等しい場合 i = j = k
if S%3 == 0:
    counter += 1

for i in range(K):
    yz = S - i
    #2つの値が等しい場合 i < j = k
    if yz%2 == 0 and yz/2 <= K and yz/2 > i:
        counter += 3
    # 2つの値が等しい場合 i = j < k
    if yz - i <= K and yz - i > i:
        counter += 3
    #すべての値が異なる場合 i < j < k
    for j in range(i+1, K):
        k = S - i - j
        if k > j and k <= K:
            counter += 6

print(counter)
print("\n")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

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

X=Y=Z=0
result = 0
for x in range(K+1):
    for y in range ( K+1 ):
        if 0 <= S-X-Y <=K:
            result +=1
        # Z = S-X-Y
        # # print("XYZ",X,Y,Z)
        # if X+Y+Z == S:
        #     if  Z<=K :
        #         result+=1 
        Y+=1
    Y=0
    X+=1

print(result)

Submission status: Accepted

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

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

# a = []
ans = 0
for i in range(K + 1):
    for j in range(i + 1):
        k = S - i - j
        if k >= 0 and k <= j:
            # print(i, j, k)
            if i == j and j == k:
                ans += 1
            elif i == j or j == k:
                ans += 3
            else:
                ans += 6

print(ans)

Submission status: Accepted

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

print(counter)

Submission status: Accepted

Solution code:
Num , Sum =  map(int,input().split())
count = 0
check = 0

for x in range(Num+1):
    for y in range ( Num+1 ):

        if 0 <= (Sum - x ) - y <= Num :
            count += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

L = [1 for z in range(K+1) for y in range(K+1) if 0 <= S-y-z <= K]
print (L.count(1))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

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

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

Submission status: Accepted

Solution code:
def count_patterns(K,S):
    count_result=0
    for i1 in range(K+1):
        resi1=S-i1
        if resi1<=2*K:
            for i2 in range(resi1+1):
                resi2=resi1-i2
                if i2<=K and resi2<=K:
                    #print(i1,i2)
                    count_result+=1
    return(count_result)

k,s=map(int,input().split(" "))
print(count_patterns(k,s))

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

print(count)

Submission status: Accepted

Solution code:
#ABC051b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

count = 0
for x in range(0, min(max_range + 1, sum_ + 1)):
    for y in range(0, min(max_range + 1, sum_ - x + 1)):
        if sum_ - x - y <= max_range:
            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 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:
import sys
def input(): return sys.stdin.readline().strip()
k,s=map(int,input().split())
c=0
for x in range(max(0,s-2*k),k+1):
    for y in range(max(0,s-x-k),min(k,s-x)+1):
        c += 1
print(c)