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: Runtime Error

Solution code:
K = int(input())
S = int(input())
counter = 0

for X in range(0,K+1):
    for Y in range(0,K+1):
        for Z in range(0,K+1):
            if X + Y + Z == S:
                counter += 1
print(counter)

Submission status: Runtime Error

Solution code:
2 2

Submission status: Runtime Error

Solution code:
k,s = map(int,input().split())
ans = 0
debug = []
for i in range(k+1):
    for l in range(k+1):
        if (s-i-l) >= 0 and (s-i-l) <= k:
            if i+l+(s-i-l) == s:
                ans += 1
                debug.append(str(i)+"+"+str(l)+"+"+str(s-i-l))
                print(debug)
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
K, S = map(int,input().split())
from itertools import product
ans = 0
for x,y,z in product(range(K+1),3):
  if x + y + z == S:ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
K = input()
count = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def check(x, y, S):

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

Submission status: Runtime Error

Solution code:
def check(x, y, S):

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

Submission status: Runtime Error

Solution code:
def check(x, y, K, S):
  for z in range(K+1):
    if x + y + z == S:
      return true
  return false

K, S = list(map(int, input('').split()))
count = 0
for x in range(K+1):
  for y in range(K+1):
    if check(x, y, K, S):
      count += 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
    for i3 in range(k+1):
      if i+i2+i3i==s:
        c+=1
print(c)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
K, S = map(int,input())
print(S//K)

Submission status: Runtime Error

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: Runtime Error

Solution code:
N = int(input())
cards = []
for i in range(N):
	cards.append(list(map(int,input().split())))

points = []
for i in range(N):
	points.append(0)

for i in range(3):
	for j in range(N):
		flag = 0
		for k in range(j):
			if cards[j][i] == cards[k][i]:
				flag = 1
				break
		if j+1<N:
			for k in range(j+1,N):
				if cards[j][i] == cards[k][i]:
					flag = 1
					break
		if flag==0: points[j] += cards[j][i]

for i in range(N):
	print(points[i])

Submission status: Runtime Error

Solution code:
k,s=[int(i) for i in input().split()]
count = 0
for y in range(k+1):
 if i < s - k * 2 or s - i < 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: Runtime Error

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

x, y, z = 0, 0, 0

an = s - (k * 2)
bn = s - k

if an >= 0:
    x = k - an + 1
    step = 1
    start = 0
    for i in range(x):
        start += step
        step += 1
elif bn >= 0:
    step = 1
    start = 0
    for i in range(k+1):
        start += step
        step += 1

print(start)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
S = int(input())

for x in range(0, K):
    for y in range(0,K):
        for z in range(0,K):
            print(x,y,z)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

and = 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: Runtime Error

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 s - i >= 0: 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: Runtime Error

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

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
k, s = map(int, input_file[0].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: Runtime Error

Solution code:
import numpy as np
import scipy.misc as scm

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

allp = scm.comb(K+2,2)
partp = scm.comb(K-S,2)

ans = allp-3*partp
if ans < 0:
    ans=0

if S<3K:
    ans =0

print int(ans)

Submission status: Runtime Error

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

import numpy as np
import scipy.misc as scm

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

allp = scm.comb(K+2,2)
partp = scm.comb(K-S,2)

ans = allp-3*partp
if ans < 0:
    ans=0

if S<3K:
    ans =0

print int(ans)
~

Submission status: Runtime Error

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

all = []
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:
				all.append(str(x)+str(y)+str(z))
		else:
			break

print(len(all))

Submission status: Runtime Error

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

all = []
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:
				all.append(str(x)+str(y)+str(z))
		else:
			break

print(len(set(all)))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int K, S;
int main(){
    ios::sync_with_stdio(false);
    cin >> K >> S;
    int ans = 0;
    REP(i,K+1) REP(j,K+1) {
        int z = S - i - j;
        if (0<=z&&z<=K) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
k,s=map(int,raw_input())
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: Runtime Error

Solution code:
k,s=map(int,raw_input())
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: Runtime Error

Solution code:
#include <iostream>

int k,s;

int main() {
	std::cin>>k>>s;
	int ans=0;
	for(int i=0;i<=k;++i) {
		for(int j=0;j<=k;++j) {
			int z=s-i-j;
			if(0<=z&&z<=k)
				++ans;
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
def getInput():
    input = input().split()
    k, s = input[0], input[1]
    return k, s

if __name__ == '__main__':
    k, s = getInput()
    count = 0
    for x in range(k):
        for y in range(k):
            for z in range(k):
                if (x + y + z) == s:
                    ++count
    print(count)

Submission status: Runtime Error

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

for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
if i + j + k == S:
cnt += 1

print cnt

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define USE1(T) template <typename T> inline
#define USE2(T, U) template <typename T, typename U> inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
template<typename T> using vec = std::vector<T>;
template<typename T> using withi = std::pair<T, int>;
using ll = long long;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=withi<T>)vec<U>zipi(const vec<T>&x,int s=0){int N=x.size();vec<U>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int K = in(), S = in();
  int ans = 0;
  rep(X, K + 1) rep(Y, K + 1) {
    int Z = S - X - Y;
    if (0 <= Z && Z <= K) ans++;
  }
  pr(ans);
  return 0;
}

Submission status: Runtime Error

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