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

ans = 0
for x, y in itertools.product(range(K + 1), range(K + 1)):
    z = S - (x + y)
    if z >= 0 and z <= K:
        # print('{} + {} + {} = {}'.format(x, y, z, S))
        ans += 1

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
k,s = map(int,input().split())
ret = 0
for i in range(k+1):
    bmax = min(k,s-i)+1
    bmin = max(0,s-i-k)
    if bmin < bmax : ret += bmax - bmin
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
u=min(k,s)
sum=0
if s-2*k>=0:
    for i in range(s-2*k,u+1):
        if s-i<2*k:
            sum+=2*k-s+i+1
        else:
            sum+=1
    print(sum)
elif s-k>=0:
    for i in range(u+1):
        if s-i<k:
            sum+=s-i+1
        else:
            sum+=2*k-s+i+1
    print(sum)
else:
    for i in range(u+1):
        if s-i<2*k:
            sum+=s-i+1
        else:
            sum+=1
    print(sum)

Submission status: Accepted

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

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 = [int(i) for i in 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())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
def main():
    """
    2 <= K <= 2500
    0 <= S <= 3K = 7500
    0 <= X,Y,Z <= K
    X+Y+Z=S

    2500**3: 15625 * (10^6) => 1.5625 * (10^10)
    Z = S - x - y
    x * y: 2500^2
    """
    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)

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 <= k:
            cnt+=1
print(cnt)

Submission status: Accepted

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

Ans = 0

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

print(Ans)

Submission status: Accepted

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

print(c)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
count = 0
li = []
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 = list(map(int,input().split()))

count = 0

if K>S: n=S
else: n=K
x=0
for i in range(n+1):
	if K>S-x: m=S-x
	else: m=K
	y=0
	for j in range(m+1):
		if S-x-y<=K: count +=1
		y+=1
	x+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0

if k < s <= 2*k:
    for i in range(k+1):
        ans += min(2*k-s+i, s-i)+1
else:
    ans = sum(range(min(3*k-s, s)+2))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

C=0

X=0
Y=0


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

print(C)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
input_line = map(int,raw_input().split(" "))
K = input_line[0]
S = input_line[1]
count = 0
for k in range(K+1):
	for kk in range(K+1):
		X = S - kk - k
		if 0 <= X <= 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:
            cnt+=1

print(cnt)

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(K+1):
    v = S - i
    for j in range(K+1):
        w = v - j
        if w >= 0 and w <= K:
            ans += 1
print ans

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def main():
    k, s = read_int_list()
    res = 0
    for x in range(0, k + 1):
        for y in range(0, k + 1):
            z = s - (x + y)
            if 0 <= z <= k:
                res += 1
    print(res)


main()

Submission status: Accepted

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

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

print(res)

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 z <= K and z >= 0:
      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:
a = input().split()
k = int(a[0])
s = int(a[1])
count = 0
for n1 in range(k+1):
    for n2 in range(k+1):
        if 0<=(s - n1 - n2)<=k:
            count += 1

print(count)

Submission status: Accepted

Solution code:
K,S = map(int, raw_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 = [int(i) for i in input().split()]

count = 0
m = K + 1


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

print(count)

Submission status: Accepted

Solution code:
K, S = map(int, raw_input().split())
ans = 0
for X in range(min(S, K)+1):
    for Y in range(min(S-X, K)+1):
        ans += int(0 <= S-X-Y <= K)
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, raw_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:
# -*- coding: utf-8 -*-
K, S = map(int, raw_input().split())
ans = 0
for X in xrange(0, K + 1):
    for Y in xrange(0, min(K + 1, S - X + 1)):
        if 0 <= S - (X + Y) <= K:
            ans += 1
print ans

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    inp = [int(i) for i in input().split()]
    K = inp[0]
    S = inp[1]
    c = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if z >= 0 and z <= K:
                c += 1
    print(c)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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


def main():
    k, s = map(int, input().split())
    answer = solve(k, s)
    return answer


def solve(k, s):
    count = 0
    for i in range(k + 1):
        for j in range(k + 1):
            z = s - i - j
            if 0 <= z and z <= k:
                count += 1
    return count

print(main())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    k,s=list(map(int,input().split()))
    sum=0
    for i in range(k+1):
        for j in range(k+1):
            if s-(i+j)>=0 and s-(i+j)<k+1:
                sum+=1
    print(sum)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
k, s = map(int, input().split())
result = 0
for z in range(max(s - 2 * k, 0), min(k + 1, s + 1)):
    xy = s - z
    result += len(range(max(xy - k, 0), min(k + 1, xy + 1)))
print(result)

Submission status: Accepted

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

for x in range(K + 1):
    S2 = S - x
    if S2 < 0:
        break
    elif S2 > 2*K:
        continue
    else:
        cnt += (S2 + 1) - 2*max(0, S2 - K)

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

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

Submission status: Accepted

Solution code:
ks = list(map(int, input().split()))
K = ks[0]
S = ks[1]

c = 0

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

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

Submission status: Accepted

Solution code:
from itertools import product as prod

k, s = [int(x) for x in input().split()]

x = range(k + 1)
y = range(k + 1)
c = 0
for x, y in prod(x, y):
    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])

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

print(a)

Submission status: Accepted

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

c = 0
for x in range(S//3 + 1):
    for y in range(x, (S-x)//2 + 1):
        z = S - (x + y)
        if z <= K:
            l = len(set((x,y,z)))
            if l == 1: c += 1
            elif l == 2: c += 3
            else: c += 6
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):
        tmp = S - x - y
        if tmp >= 0 and tmp <= K:
            ans += 1
print(ans)

Submission status: Accepted

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

ls = [i for i in range(k+1)]

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# http://abc051.contest.atcoder.jp/tasks/abc051_b
K,N=map(int,raw_input().split())
count=0
for i in range(K+1):
	for j in range(K+1):
		# print i,j,(N-(i+j))
		if 0<=(N-(i+j))<=K:
			count+=1
print count

Submission status: Accepted

Solution code:
K,S = map(int, raw_input().split())
ans = 0
for x in xrange(0,K+1):
    for y in xrange(0,K+1):
        if x + y <= S and 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(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:
#ARC051B

k,s=map(int,raw_input().split())
cnt=0
for x in xrange(k+1):
 for y in xrange(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())
total=0
for x in range(0,min(s,k)+1):
    for y in range(0,min(s-x,k)+1):
        if 0 <= s-x-y and s-x-y <= k:
            total+=1
print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
 
k, s = list(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 z>=0 and z<=K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
 
K_MAX = 2500
k, s = list(map(int, input().split()))
 
smz = [False] * (2 * K_MAX + 1)
 
for i in range(k + 1):
    if 0 <= s - i <= 2 * k: smz[s - i] = True
 
cnt = 0
for i in range(k + 1):
    for j in range(k + 1):
        if smz[i + j]:
            cnt += 1
 
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
k,s = map(int,stdin.readline().split())
ans = 0
for i in xrange(k+1):
 for j in xrange(k+1):
  x = s - i - j
  if x>=0 and x<=k:
   ans+=1
print ans

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print res

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    k,s = LI()
    r = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s-x-y
            if z > k:
                continue
            if z < 0:
                break
            r += 1

    return r


print(main())

Submission status: Accepted

Solution code:
K, S = map(int, raw_input().split())
ans = 0
for X in xrange(K+1):
    for Y in xrange(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(" "))
print(sum([max(0, min(K, S-X) - max(0, S-X-K) + 1) for X in range(min(K, S)+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):
        if s - x - y >= 0 and s - x - y <= k:
                count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

combo_count = 0
for X in range(max(0, S-K*2), min(S//3, K)+1):
    S2 = S-X
    for Y in range(max(X,S2-K), min(S2//2, K)+1):
        Z = S2 - Y
        if X == Y and Y == Z:
            combo_count += 1
        elif X == Y or Y == Z:
            combo_count += 3
        else:
            combo_count += 6
print(combo_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(wariate)

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 = list(map(int, input().split()))
z = min(k,s)
y = min(k,s-z)
xmax = min(y + z,k)
x = s-z-y
count = 0

while x <= xmax and z >= 0 :
    z0 = z
    y0 = y
    while z >= 0 and y<= k:
        z -= 1
        y += 1
        count+=1
    z = z0+1
    y = y0-1
    while y >= 0 and z<= k:
        y -= 1
        z += 1
        count+=1
    z = z0-1
    y = y0
    x +=1
print(count)

Submission status: Accepted

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

def count(k, s):
	x = 0
	res = 0
	for x in range(k+1):
		s_ = s - x
		if s_ < 0:
			return res
		for y in range(k+1):
			s__ = s_ - y
			if 0<= s__ <= k:
				res += 1
	return res

print(count(k, s))

Submission status: Accepted

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

ans=0
for i in range(K+1):
        M=min(S-i,K)
        m=max(0,S-i-K)
        if M>=m:
                ans += M-m+1

print(ans)

Submission status: Accepted

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

for i in range(k + 1):
    t = s - i
    if t >= 0:
        cnt += max(0, (t + 1) - 2 * (max(0, t - k)))
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

K,S = map(int, raw_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 and Z<=K):
   ans=ans+1
print ans

Submission status: Accepted

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

for x in range(k+1)[::-1]:
    yz = s - x
    if yz > k*2:
        break
    for y in range(k+1)[::-1]:
        z = yz - y
        if x >= y >= z >= 0:
            if len({x, y, z}) == 1:
                count += 1
            elif len({x, y, z}) == 2:
                count += 3
            else:
                count += 6

print(count)

Submission status: Accepted

Solution code:
def count(i, j, k):
    if i == j and j == k:
        return 1
    elif i == j or j == k or i == k:
        return 3
    else:
        return 6

def solve(K, S):
    ans = 0
    for i in range(K, -1, -1):
        for j in range(i, -1, -1):
            k = S - (i + j)
            if k >= 0 and k <= j:
                ans += count(i, j, S - (i + j))
    return ans

k, s = tuple(int(x) for x in input().split())
print(solve(k, s))

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

def nHr(n):
    return (n+2)*(n+1)//2
whole = nHr(S)
oneGreater = twoGreater = threeGreater = 0

if S >= K+1:
    oneGreater = nHr(S-(K+1))
    if S >= 2*(K+1):
        twoGreater = nHr(S-2*(K+1))
        """
        if S >= 3*(K+1):
            threeGreater = nHr(S-3*(K+1))
        """

ans = whole -(oneGreater*3 - twoGreater*3 + threeGreater)
print(ans)

Submission status: Accepted

Solution code:
k,s=map(int,raw_input().split())
cnt=0
for x in range(k+1):
    if 0<=(s-x)<k:cnt+=(s-x+1)
    if k<=(s-x)<=2*k:cnt+=(2*k-s+x+1)
print cnt

Submission status: Accepted

Solution code:
K, S = list(map(int, input().split()))
# ok_list = []
cnt = 0
for x in range(K + 1):
    if S - x > K:
        y_max = K + 1
    else:
        y_max = S - x + 1

    if S - x > 2 * K:
        continue
    else:
        # print(y_max, end=" ")
        pass

    for y in range(y_max):

        if S - (x + y) <= K:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:

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

for x in range(0, K + 1):
    if S - x <= K:
        wariate += max(S - x + 1, 0)
    else:
        wariate += max(0, 2 * K - (S - x) + 1)

print(wariate)

Submission status: Accepted

Solution code:
K, S = map(int, input().strip().split(' '))
cnt = 0
if S < K:
	for X in range(0, S+1):
		cnt += (S-X+1)
else:
	for X in range(0, K+1):
		if (S-X) <= (2*K):
			if (S-X) < K:
				cnt += (S-X+1)
			elif (S-X) > K:
				Z = S-X-K
				cnt += (K-Z+1)
			else:
				cnt += (K+1)
 
print(cnt)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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 x <= y <= z <= k:
            ans += [ None, 1, 3, 6 ][ len(set([ x, y, z ])) ]
print(ans)

Submission status: Accepted

Solution code:
k,s = input().strip().split(' ')
k,s = [int(k),int(s)]
cnt = 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:
			cnt+=1
print (cnt)