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:
#import
#import math
#import numpy as np
#= int(input())
#= input()
K, S = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= {i:[] for i in range(N)}

r = 0

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

print(r)

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

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

X_m = max(0, S - 2*K)
X_M = min(K, S)

ans = 0

for i in range(X_m, X_M+1):
    Y_m = max(0, S - i - K)
    Y_M = min(K, S - i)
    ans += Y_M - Y_m + 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(S-x+1, K+1)):
        if S - x - y <= 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 <= K:
            count += 1

print(count)

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=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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math

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

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

print(result)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    k, s = map(int, readline().split())
    ans = 0

    for x in range(k + 1):
        if s - x > 2 * k or s - x < 0:
            continue
        for y in range(k + 1):
            z = s - x - y
            if z > k or z < 0:
                continue
            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())
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())
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):
    if K < 1/2 * (S - x):
        continue
    for y in range(min(S - x + 1, K + 1)):
        if K < (S - x - y):
            continue
        else:
            count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc051/tasks/abc051_b
from collections import defaultdict
k, s = map(int, input().split())

d = defaultdict(int)
for x in range(k + 1):
    for y in range(k + 1):
        d[x + y] += 1

ans = 0
for z in range(k + 1):
    ans += d.get(s - z, 0)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5)


readline =sys.stdin.readline

def process():
    k,s = map(int,readline().rstrip().split())
    cnt=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:
                cnt+=1
    
    return cnt


print(process())

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K, S = map(int, readline().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)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    k, s = [int(x) for x in 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)

    


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


print(ans)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
 
c=0
m=min(s,k)
for x in range(m+1):
  for y in range(m+1):
    if s<x+y:
      break
    elif s>x+y+k:
      continue
    else:
      c+=1
print(c)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5)

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w') 

readline =sys.stdin.readline

# time - O(n2)
def process():
    k,s = map(int,readline().rstrip().split())
    cnt=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:
                cnt+=1
    
    return cnt



# for _ in range(int(readline().rstrip())):
print(process())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
from collections import defaultdict

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

cnt = defaultdict(int)
for x in range(k+1):
    for y in range(k+1):
        cnt[x+y] += 1

ans = 0
for key, value in cnt.items():
    if 0 <= s - key <= k:
        ans += value

print(ans)

Submission status: Accepted

Solution code:
MM = input().split()
K = int(MM[0])
S = int(MM[1])
count = 0
for a in range(K+1):
  for b in range(K+1):
    z = S-a-b
    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):
        z = S - x - y
        if 0 <= z <= K:
            ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def actual(K, S):
    count = 0

    for x in range(K + 1):
        for y in range(K + 1):
            z = S - (x + y)

            if 0 <= z <= K:
                count += 1

    return count

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

Submission status: Accepted

Solution code:
def actual(K, S):
    count = 0

    for x in range(K + 1):
        for y in range(K + 1):
            z = S - (x + y)

            cond1 = (0 <= x <= K) and (0 <= y <= K) and (0 <= z <= K)
            cond2 = (x + y + z) == S

            if cond1 and cond2:
                count += 1

    return count

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

Submission status: Accepted

Solution code:
ans = 0
k,s = map(int, input().split())
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 = [int(w) for w in input().split()]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = input().split()

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

x = -1
y = -1
z = 0
answer = 0

for num in range(k+1):
    x += 1
    y = -1
    for n in range(k+1):
        y += 1
        z = s - x - y
        if 0 <= z and z <= k:
            answer += 1
 



print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    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)            

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,S = map(int,input().split())
if S == 0:
  print(1)
  exit()
z = 0
o = 0
t = 0
start = min(S,K)
for i in reversed(range(start+1)):
  if i < (S-1)//3 + 1:
    break
  else:
    num = min(S-i,i)-(S-i+1)//2 + 1
    z += num
    if num == 1:
      if (S-i) % 2 == 0 or min(S-i,i) == i:
        z -= 1
        o += 1
    else:
      if (S-i) % 2 == 0:
        z -= 1
        o += 1
      if min(S-i,i) == i:
        z -= 1
        o += 1
        
      
if S % 3 == 0:
  t += 1
  o -= 1
print(z*6 + o*3 + t)

Submission status: Accepted

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

ans = 0
for i in range(K+1):
  mod = S - i
  if mod-K <= K:
    up = min(i+K+1, S+1)
    down = max(i, S-K)
    if up > down:
      plus = up - down
      ans += plus
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):
    #print(i, j)
    if 0 <= S - i - j <= K:
      ans += 1
      
      
print(ans)

Submission status: Accepted

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    k,s = map(int, stdin.readline().rstrip().split())
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    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__':
    solve()

Submission status: Accepted

Solution code:
a = input()
k, s = a.split(' ')
K = int(k)
S = int(s)
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 z in range(K+1):
    tmp=S-z
    for x in range(K+1):
        if x+K<tmp:
            continue
        if x>tmp:
            break
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
K, S = map(int, input().split())
ans = 0

for i in itertools.product(range(K+1), repeat=2):
    if 0 <= (S - sum(i)) <= K:
        ans += 1
print(ans)

Submission status: Accepted

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

res = 0

for X in range(min(S, K), -1, -1):
    for Y in range(min(K, S - X), -1, -1):
        if 0 <= S - X - Y <= K:
            res += 1
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect
k, s = map(int, input().split())
ans = 0
rekkyo = []
for i in range(0,k+1):
    for j in range(0,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())
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 i in range(k+1):
    for j in range(k+1):
        l = s-(i+j)
        if i+j+l == s and l >= 0 and l <= k and i <= k and j <= k:
            #print("解：",i,j,l)
            count += 1
print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans = 0
x_min = max(0, s - k - k) 
x_max = min(k, s)
for x in range(x_min, x_max + 1):
    y_min = max(0, s - x - k)
    y_max = min(k, s - x)
    ans += y_max - y_min + 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
from numba import jit

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

@jit
def main():
	k, s = LI()
	cnt = 0
	for x in range(k+1):
		for y in range(k+1):
			if 0 <= s - x - y <= k:
				cnt += 1
	print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
k, s = map(int, input().split())

ans = 0

for i in range(k + 1):
    for j in range(k + 1):
        a = s - i - j
        
        if a >= 0 and a <= 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):
        #print(i,j)
        Z = S-i-j
        #print(Z)
        if Z <= K and Z >= 0:
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
K, S = map(int, input().split())
ans = 0
if K*3 < S:
    print(0)
else:
    for i in range(K+1):
        for j in range(K+1):
            if S-i-j < 0: break
            elif S-i-j <= K: ans += 1
    print(ans)

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools

def solve():
    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)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
k, s = map(int,input().split())
ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        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 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())
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):
    tmp=s-i
    if tmp<0:
        continue
    if tmp<=k:
        ans+=tmp+1
    elif 2*k<tmp:
        pass
    else:
        tmp1=2*k-tmp
        ans+=tmp1+1
    # print(tmp)
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())
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(k+1):
  for j in range(k+1):
    if max(0, s-k) <= i+j <= s:
      cnt += 1
    elif i + j > s:
      break
print(cnt)

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K, S = read_ints()
    # X+Y+Z = S
    # 0 <= X,Y,Z <= K
    total = 0
    for X in range(K+1):
        if S-X < 0:
            break
        # Y+Z=S-X
        Y_min = max(S-X-K, 0)
        Y_max = min(S-X, K)
        if Y_min <= Y_max:
            total += Y_max-Y_min+1
    return total


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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(t)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

result = 0

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

Submission status: Accepted

Solution code:
import sys

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

result = 0

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

Submission status: Accepted

Solution code:
import sys

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

result = 0

for x in range(k+1):
    for y in range(min(s-x+1,k+1)):
        if (s-x-y)<=k:
            result+=1
        
print(result)

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

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

print(result)

Submission status: Accepted

Solution code:
k,s = map(int, input().split())
count = 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 and y==z:
                count += 1
            elif x==y or y==z or z==x:
                count += 3
            else:
                count += 6
        
print(count)
print("\n")