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 bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K, S = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# B - Sum of Three Integers

k,s = map(int,input().split())
c = 0
min_limit = s - k

for i in range(k+1):
    for j in range(k+1):
        if i + j <= s and i + j >= min_limit:
            c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

K,S = mint()
ans = 0
for X in range(K+1):
    for Y in range(K+1):
        if S-X-Y in range(K+1):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

cnt = 0

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

      ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
url = "https://atcoder.jp//contests/abc057/tasks/abc057_a"

def main():
    k, s = list(map(int, input().split()))
    count = 0
    for x, y in itertools.product(range(k+1), range(k+1)):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
    print(count)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
from decimal import Decimal

input = sys.stdin.readline
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:
# 各桁の数値の総和を計算する.
def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


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

cnt = 0
for idx1 in range(0, k+1):
    for idx2 in range(0, k+1):
        current = s - (idx1 + idx2)
        if 0 <= current <= k:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
a,b=input().split()
a=int(a)
b=int(b)
c=0
for i in range(a+1):
  for k in range(a+1):
    if b-a<=i+k<=b:
      c=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):
    Z=S-X-Y
    if 0<=Z<=K:
      ans+=1
print(ans)

Submission status: Accepted

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

def main():
    stdIn1, stdIn2 = map(int, input().split())
    stdOut = solve(stdIn1, stdIn2)
    print(stdOut)


"""
方針
x,y,zそれぞれを3重ループで0からkまで回す
(O(N^3)だが、k<=2500なので気にならない)
x+y+zが等しければパターンを1追加

TLEになったので、もう少し節約するパターンを考える必要あり
ひとまずx,x+y,x+y+zがsより大きなった場合はbreakさせてループを抜ける処理にしてみる
まだTLEになるので、もう少し考える
実はzはループする必要はなく z = s - (x + y) <= k であれば +1, > k であれば continueでよい
これでO(N^2)に計算量を抑えられる

"""


def solve(k, s):
    pattern = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            z = s - x - y
            if z <= k:
                pattern += 1

    return pattern


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


K,S = MI()

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

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

print(cnt)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def LI():
    return list(map(int, input().split()))


K, S = LI()
ans = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S-(i+j) <= K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


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

Submission status: Accepted

Solution code:
import sys

K, S = map(int, sys.stdin.readline().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        if 0 <= S - (x + y) <= K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  K,S=map(int,pin().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)
  return 
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):
        z = s -x- y 
        if 0<=z and z<=k:
            cnt+=1

print(cnt)

Submission status: Accepted

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

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

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


K,S = MI()

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

print(ans)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
cnt = 0
from itertools import product as prd
for x, y in prd(range(K+1),range(K+1)):
    if 0 <= S-x-y <= K:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
cnt = 0
for 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:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    k,s = LI()
    ans = 0
    for x in range(k+1):
        for y in range(k+1):
            if s-k<=x+y and x+y<=s:
                ans += 1

    print(ans)
main()

Submission status: Accepted

Solution code:
k, s = list(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 in range(0, k+1):
            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 i in range( k + 1 ):
        if i > s:
            break
        if s - i > 2 * k:
            continue
        for j in range( k + 1 ):
            if i + j > s:
                break
            if s - i - j > k:
                continue
            ans += 1

    print( ans )




main()

Submission status: Accepted

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

for p in range(k+1):
    for q in range(k+1):
        r = s-p-q
        if r>=0 and r<=k:
            count += 1

print(count)

Submission status: Accepted

Solution code:
k,s = map(int, input().split(" "))
count = 0
for i in range(max(0, s-2*k), min(s, k)+1):
  count += min(k, s-i) - max(0, s-i-k) + 1
  #print(count)
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())
t=0

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

Submission status: Accepted

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

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

print(str(answer))

Submission status: Accepted

Solution code:
import sys

(K, S) = (int(x) for x in input().split())
comb = 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:
#      print("%d %d %d" % (x, y, z))
      comb+=1

print(comb)

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:
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 and z<=K):
            if(x == y and y == z):
                ans += 1
            elif(x != y and y != z and z != x):
                ans += 1
            else:
                ans += 1
                
                
                
print(ans)

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 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())
a = 0
for X in range(K+1):
    for Y in range(K+1):
        if 0<=S-X-Y<=K:
            a += 1
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(k+1):
    for j in range(k+1):

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

Submission status: Accepted

Solution code:
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_range=min(K,S)
cnt=0
for x in range(max_range+1):
    for y in range(min(max_range,max(0,S-x-max_range)),min(max_range,S-x)+1):
        z= S-x-y
        if 0 > z:
            break
        if z <= max_range:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_loop=min(K,S)+1
cnt=0
for x in range(max_loop):
    for y in range(max_loop):
        z= S-x-y
        if 0 > z:
            break
        if z <= K:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    k,s = i_map()
    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())
dp=[0]*(3*k+4)
dp[0]=1
dp[k+1]=-3
dp[2*k+2]=3
dp[-1]=-1
from itertools import accumulate
dp=list(accumulate(list(accumulate(list(accumulate(dp))))))
print(dp[s])

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:
# vim: fileencoding=utf-8


def main():
    k, s = map(int, 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)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    K, S = map(int, open(0).read().split())
    # n = 0
    # for X in range(K + 1):
    #     for Y in range(S - X + 1):
    #         if (Y <= K) & (S - X - Y <= K):
    #             n += 1
    # print(n)
    print(
        len(
            [
                0
                for X in range(K + 1)
                for Y in range(S - X + 1)
                if (Y <= K) & (S - X - Y <= K)
            ]
        )
    )


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 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 = [int(a) for a in input().split()]

cnt = 0
for x in range(0,K+1):
  if x > S:
    continue
  for y in range(0,K+1):
    if x+y > S:
      continue
    elif x+y+K < S:
      continue
    else:
      cnt +=1
        
print(cnt)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


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

if __name__ == "__main__":
    main()

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):
        l = s-i-j
        if 0 <= l <= 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())
x = y = S//3
z = S - x - y
if z < y:
    x = z
    z = y
ans = 0
while 0 <= x <= y and 0<= y <=K and z <= K:
    while 0 <= x and z <= K:
        if x == y == z:
            ans += 1
        elif x == y or y == z:
            ans += 3
        else:
            ans += 6
        x -= 1
        z += 1
    y -= 1
    x = y
    z = S - x - y
    if z < y:
        x = z
        z = y
x = y = S//3 + 1
z = S - x - y
if z < y:
    x = z
    z = y
while 0 <= x <= y and 0 <= y <= K and y <= z <= K:
    while 0 <= x and z <= K:
        if x == y == z:
            ans += 1
        elif x == y or y == z:
            ans += 3
        else:
            ans += 6
        x -= 1
        z += 1
    y += 1
    x = y
    z = S - x - y
    if z < y:
        x = z
        z = y
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 X + Y + Z == S and 0 <= Z <= K:
            ans += 1

print(ans)

Submission status: Accepted

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

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):
        z=S-x-y
        if z <= K and z >= 0:
            ans+=1
#             print(x,y,z)
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 = (int(x) for x in input().split())
count = 0
for x in range(K+1):
  for y in range(K+1):
    remain = S-x-y
    if 0 <= remain and remain <= 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())
cnt=0
for X in range(K+1):
    for Y in range(K+1):
        Z=S-X-Y
        if 0<=Z<=K:
            cnt+=1
print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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


print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

K, S = map(int, input().split())
AB = []
ret = 0
for i in range(K+1):
    for j in range(K+1):
        AB.append(i+j)

for i in range(len(AB)):
    if 0 <= S - AB[i] <= K:
        ret += 1

print(ret)

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:
            #print(i,j,s-i-j)
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

for x in range(max(0, S - 2 * K), min(K, S) + 1):
    ans += min(K, S - x) - max(0, S - x - K) + 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 + 1:
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

ans = 0

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

print(ans)

Submission status: Accepted

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