100 atcoder#ABC051B. [ABC051B] Sum of Three Integers

[ABC051B] Sum of Three Integers

Score : 200200 points

Problem Statement

You are given two integers KK and SS. Three variable X,YX, Y and ZZ takes integer values satisfying 0X,Y,ZK0 \leq X,Y,Z \leq K. How many different assignments of values to X,YX, Y and ZZ are there such that X+Y+Z=SX + Y + Z = S?

Constraints

  • 2K25002 \leq K \leq 2500
  • 0S3K0 \leq S \leq 3K
  • KK and SS are integers.

Input

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

KK SS

Output

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

2 2
6

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

  • X=0,Y=0,Z=2X = 0, Y = 0, Z = 2
  • X=0,Y=2,Z=0X = 0, Y = 2, Z = 0
  • X=2,Y=0,Z=0X = 2, Y = 0, Z = 0
  • X=0,Y=1,Z=1X = 0, Y = 1, Z = 1
  • X=1,Y=0,Z=1X = 1, Y = 0, Z = 1
  • X=1,Y=1,Z=0X = 1, Y = 1, Z = 0
5 15
1

The maximum value of X+Y+ZX + Y + Z is 1515, achieved by one triple of X,YX, Y and ZZ.