Problem:


Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?  

Constraints

2≤K≤2500 

0≤S≤3K 

K and S are integers.  

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2 

X = 0, Y = 2, Z = 0 

X = 2, Y = 0, Z = 0 

X = 0, Y = 1, Z = 1 

X = 1, Y = 0, Z = 1 

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.



Sample input:
2 2


Sample output:
6

Submission status: Accepted

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

a = 0
for i in range(K + 1):
    r = S - i
    if i <= S and r <= K * 2:
        t = (r + 1) - max(0, r - K) * 2
        a += t

print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
inp=sys.stdin.readline()
K,S=map(lambda x: int(x), inp.split(' '))
K,S

if S<=K:
    ret=(S+1)*(S+2)/2
elif S>=K*2:
    S=K*3-S
    ret=(S+1)*(S+2)/2
else:
    ret=(S+1)*(S+2)/2-(S-K)*(S-K+1)/2*3
print(int(ret))

Submission status: Accepted

Solution code:
def count(k, s):
  h = min(k, s)
  l =  max(s - k, 0)
  return max(h - l + 1, 0)

k, s = map(int, input().split())
print(sum([count(k, s - x) for x in range(min(k, s)+1)]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

counter = 0


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


print(counter)

Submission status: Accepted

Solution code:
# your code goes here
[K, S] = raw_input().split()
K = int(K)
S = int(S)

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:
#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        k, s = line.rstrip("\n").split(" ")
        k = int(k)
        s = int(s)
        counter = 0
        for x in xrange(0, k + 1):
            for y in xrange(x, k + 1):
                if x + y <= s:
                    z = s - x - y
                    if z >= y and z <= k:
                        if (x+y+z) == s:
                            if x == y and y == z:
                                counter += 1
                            elif x == y or y == z or x == z:
                                counter += 3
                            else: 
                                counter += 6
        print counter

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
from sys import stdin

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

result = 0


def get_variants(target, maximum):
    result = 0
    for x in range(maximum, -1, -1):
        y = target - x
        if 0 <= y <= maximum:
            result += 1
    return result

for z in range(k+1):
    variants = get_variants(s - z, k)
    result += variants

print(result)

Submission status: Accepted

Solution code:
k,s=[int(i) for i in input().split()]
ans=0
chk=set([])
for i in range(k+1):
    for j in range(i,k+1):
        tmp=s-i-j
        if 0<=tmp<=k and i<=j<=tmp:
            if i==j==tmp:
                ans+=1
            elif i==j or i==tmp or j==tmp:
                ans+=3
            else:
                ans+=6
print(ans)

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

Submission status: Accepted

Solution code:
[K,S]=[int(i) for i in input().split()]
c=0
for i in range(K+1):
 a=S-i
 for i in range(K+1):
  if a-i>K or a-i<0:
    c+=1
print((K+1)**2-c)

Submission status: Accepted

Solution code:
k,s=map(int,input().split())
res=0
for x in range(k+1):
    t=s-x
    if t<0:
        continue
    ymin=max(t-k,0)
    ymax=min(t,k)
    res+=max(ymax-ymin+1,0)
print(res)

Submission status: Accepted

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

print(total)

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: continue
    if Z <= K : ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def func(k, n):
    if n <= k:
        return n + 1
    elif n <= 2 * k:
        return 2 * k - n + 1
    else:
        return 0

K,S = map(int,input().split())
ans = 0
for a in range(K+1):
    if S-a >= 0:
        ans += func(K, S-a)
print(ans)

Submission status: Accepted

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

    count = 0
    for x in range(max(0,S - 2*K), K + 1):
        for y in range(max(0,S - x - K), K + 1):
            if 0 <= S - x - y <= 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(K+1):
	if i > S:
		break
	if i + 2*K < S:
		continue
	for j in range(K+1):
		t = S - i - j
		if 0 <= t and t <= K:
			ans += 1 
print(ans)

Submission status: Accepted

Solution code:
K, S = map(int, input().split())
count = 0
x_min = max(0, S-K*2)
x_max = min(K, S)
for x in range(x_min, x_max+1):
	rest = S-x
	if rest<K:
		count = count+rest+1
	else:
		count = count+K*2-rest+1
print(count)

Submission status: Accepted

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

ans = 0
for x in range(k + 1):
    yz = s - x
    ans += max(0, min(yz + 1, 2 * k - yz + 1))

print ans

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 z > k or z < 0:
            continue
        ans += 1
print ans

Submission status: Accepted

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

Submission status: Accepted

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

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

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

import sys
stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()

def main():
    ct = 0
    k,s = na()
    for i in range(0, k+1):
        for j in range(0, k+1):
            if 0 <= s-(i+j) <= k:
                ct += 1
    print(ct)
    pass


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

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

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


prod = itertools.product(lst, repeat=3)

frame = pd.DataFrame(list(prod))

frame['ans'] = frame[0]+frame[1]+frame[2]

s_bool = (frame['ans'] ==s)

ans = 0
ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

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

import pandas as pd

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

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



ans = 0
ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

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




ans = 0
ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

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


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

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


ans = 0
ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

Submission status: Runtime Error

Solution code:

import itertools
import pandas as pd

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

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

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




ans = 0
ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

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

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


prod = itertools.product(lst, repeat=3)

frame = pd.DataFrame(list(prod))

frame['ans'] = frame[0]+frame[1]+frame[2]

s_bool = (frame['ans'] ==s)

ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

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

lst = [i for i in range(k)]

prod = itertools.product(lst, repeat=3)

frame = pd.DataFrame(list(prod))

frame['ans'] = frame[0]+frame[1]+frame[2]

s_bool = (frame['ans'] ==s)

ans = s_bool.sum()

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
import pandas as pd

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

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

prod = itertools.product(lst, repeat=3)

frame = pd.DataFrame(list(prod))

frame['ans'] = frame[0]+frame[1]+frame[2]

s_bool = (frame['ans'] ==s)

ans = s_bool.sum()
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K,S = map(int,input().split())
import math
if K>=S:
  print(math.factorial(S+1))
else:
  count=0
  for i in range(0,K+1):
    for j in range(0,K+1):
      for h in range(0,K+1):
        if i+j+h==S:
          count+=1
print(count)