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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cnt = 0
l = []
l = input().split()
k = int(l[0])
s = int(l[1])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

print(count)

Submission status: Accepted

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

count = 0

x = 0
while (x <= K):
    y = 0
    while (y <= K):
        if 0 <= S - (x + y) <= K:
            count += 1
        y += 1
    x += 1



print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def SumofThreeIntegers():
    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 <= S and z <= K:
                count += 1
    print(count)

if __name__ == "__main__":
    SumofThreeIntegers()

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

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 k>=z>=0:
            ans+=1
            #print(i,j,z)
print(ans)

Submission status: Accepted

Solution code:
import sys

data=input().split(' ')
k=int(data[0])
data_1sub=k+1
s=int(data[1])
d=0
e=0
for i in range(data_1sub):
    for j in range(data_1sub):
        d=s-i-j
        if (0 <= d) and (d <= k):
            e=e+1
        else:
            pass
print(e)

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

print(len(ans))

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
k, s = na()

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:
# ABC051B - Sum of Three Integers
def main():
    K, S = tuple(map(int, input().split()))
    ans = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if z < 0:
                break
            if z <= K:
                ans += 1
    print(ans)


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)

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):
    yz = S - x
    if yz < 0:
        break
    elif yz <= K:
        count += yz + 1
    elif yz <= 2*K:
        count += K - (yz-K) + 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
import sys
k,s = map(int,input().split())
sum = 0
for i in range(k+1):
    for j in range(k+1):
        if i + j <= s and i + j + k >= s:
            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 0 <= z <= K:
            if x <= S or y <= S:
                count += 1
print(count)

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())
if 0 <= s <= k:
    ans = (s+1)*(s+2)/2
    print(int(ans))
elif k < s <= 2*k:
    ans = ((s+1)*(s+2)/2) - ((s-k)*(s-k+1)/2) - ((s-k)*(s-k+1))
    print(int(ans))
elif 2*k < s < 3*k:
    print(3)
else:
    print(1)

Submission status: Accepted

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

# 各ケースごとに格子点の個数を求める
if 0 <= S <= K:
    print(int((S+1)*(S+2)/2))
elif K < S <= 2*K:
    print(int((K+1)**2 - (2*K-S)*(2*K-S+1)/2 - (S-K)*(S-K+1)/2))
else:
    print(int((3*K-S+1)*(3*K-S+2)/2))

Submission status: Accepted

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

# S-K<=X+Y<=S を満たすX,Yの組の数が答え
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:
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  
        #print(x,y,z)
        if z >=0 and s<=3*k 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 z<=k and z>=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):
        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):
        z = s - x - y
        if 0 <= 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)):
    if i > S:
        break
    for j in (range(K + 1)):
        if i + j > S:
            break
        elif S - i - j <= K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
t = S - K
r = S - 2*K
if t <= 0:
    answer = (S+2)*(S+1)/2
elif r <= 0:
    answer = (S+2)*(K-t+1)/2 + (S*2-t*3+1)*t/2
else:
    answer = (3*K-S+2)*(3*K-S+1)/2
    
print(int(answer))

Submission status: Accepted

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

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


#input
lines = [x.strip() for x in sys.stdin.readlines()]

def slv(lines):
    ans = 0
    s = int(lines[0].split()[1])
    k = int(lines[0].split()[0])

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

if __name__ == "__main__":
    print(slv(lines))

Submission status: Accepted

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

ans = 0
for a in range(K+1):
  for b in range(K+1):
    c = A-(a+b)
    if 0 <= c <= K:
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
K, S=map(int, input().split())
KK=2*K
counter=0
for x in range(K+1):
  yz=S-x
  if yz<0:
    pass
  else:
    if yz<=K:
      counter+=(yz+1)
    elif yz>KK:
      pass
    else:
      counter+=(KK-yz+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:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


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


# In[9]:


count = 0


# In[10]:


for_range = min(K+1, S+1)
for x in range(for_range):
    for y in range(for_range):
        if x+y >= S-K and x+y <= S:
            #print(x, y)
            count += 1


# In[11]:


print(count)


# In[ ]:

Submission status: Accepted

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

# In[1]:


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


# In[9]:


count = 0


# In[10]:


for x in range(K+1):
    for y in range(K+1):
        if x+y >= S-K and x+y <= S:
            #print(x, y)
            count += 1


# In[11]:


print(count)


# In[ ]:

Submission status: Accepted

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

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

# solve
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

# output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,S = map(int,input().split())
a = 0
 
for y in range(K + 1):
     for z in range(K + 1):
        if 0 <= S - y - z <= K:
            a += 1
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(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());print(sum(0<=S-X-Y<=K for X in range(K+1)for Y in range(K+1)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(K)
# print(S)

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

print(count)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
c=0
for i in range(a[1]-2*a[0] if a[1]-2*a[0] > 0 else 0, a[0]+1):
    for j in range((a[1]-i)-a[0] if (a[1]-i)-a[0] > 0 else 0, a[0] + 1):
        if i + j <= a[1]:
            c += 1

print(c)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(min(s + 1, k + 1)):
    # y + z = s - x, x is substituted by i,
    if k < math.ceil((s - i) / 2):
        continue
    else:
        ans += 2 * (min(k, (s - i)) - (s - i) // 2)
        if (s - i) % 2 == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ct)

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
k = i[0]
s = i[1]
#print("k=",k,"s=",s)
ans = 0
for x in range(k+1):
  for y in range(k+1):
    z = s-x-y
    #print("x=",x,"y=",y,"z=",z)
    if k >= z and z >=0:
        #print("clear!")
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
lis =[]
#k = int(stdin.readline().rstrip())
lis= stdin.readline().rstrip().split()
k = int(lis[0])
s = int(lis[1])
count = 0
x = 0
y = 0
z = 0
for x in range(k+1):
    y = 0
    for y in range(k+1):
        z = 0
        z = s - x - y
        if z <= k and z >= 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):
        if s-(i+j) <= k and s-(i+j) >= 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):
        temp = S-i-j

        if temp >=0 and temp <= K:
            count = count + 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

counter = 0
for z in range(0, k+1):
  if 2 * k < s - z:
    continue
  for y in range(0, k+1):
    if k + y + z < s:
      continue
    elif   s - y - z < 0:
      break
    else:
      counter += 1
print(counter)

Submission status: Accepted

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

print(sum(S-K <= i+j <= S for j in range(K+1) for i in range(K+1)))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

k = data[0]
s = data[1]

answer = 0;

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

minZ=max(S-2*K,0)
maxZ=min(S,K)

if minZ>=S-K:
  nZ=maxZ-minZ+1
  max_nY=S-minZ+1
  min_nY=S-maxZ+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)
elif maxZ>=S-K:
  nZ_u=maxZ-(S-K)
  max_nY_u=K
  min_nY_u=S-maxZ+1
  
  ans_u=((max_nY_u+min_nY_u)*nZ_u)//2
  
  nZ_l=(S-K)-minZ+1
  max_nY_l=K+1
  min_nY_l=2*K+minZ-S+1
  
  ans_l=((max_nY_l+min_nY_l)*nZ_l)//2
  
  print(ans_u+ans_l)
  
  
else:
  nZ=maxZ-minZ+1
  min_nY=2*K+minZ-S+1
  max_nY=2*K+maxZ-S+1
  ans=((max_nY+min_nY)*nZ)//2
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Accepted

Solution code:
import sys
import copy
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
K,S=map(int,input().split())
crt=0
for x in range(0,K+1):
  for y in range(0,K+1):
    z=S-x-y
    if 0<=z<=K:
      crt+=1
print(crt)

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  5 14:58:17 2019

@author: Owner
"""

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

cnt = 0

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

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
import itertools
count = 0
for pattern in itertools.product(range(K+1), repeat=2):
    #print(pattern)
    if S-K <= sum(pattern) <= S:
        
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ks = input()
k, s = [int(x) for x in ks.split(" ")]
comb = []
for x in range(min(k,s) + 1)[::-1]:
    for y in range(min(x + 1, s - x + 1))[::-1]:
        z = s - x - y
        if (x <= k and y <= k and z <= k and y <= x and z <= y):
            comb.append([x,y,z])
count = 0
for c in comb:
    l = len(set(c))
    if l == 1:
        count += 1
    elif l == 2:
        count += 3
    else:
        count += 6
print(count)

Submission status: Accepted

Solution code:
K, S = (int(x) for x in input().split())
if S <= K:
    print((S+1)*(S+2)//2)
elif 2*K <= S:
    print((3*K-S+2)*(3*K-S+1)//2)
else:
    print((3*K-S+2)*(S-K+1)//2+(2*K-S)*(S+1)//2)

Submission status: Accepted

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

Submission status: Accepted

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