Sum of Three Integers

AtCoder
IDabc051_b
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
2 2
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$
Input #2
5 15
Output #2
1

The maximum value of $X + Y + Z$ is $15$, achieved by one triple of $X, Y$ and $Z$.
API Response (JSON)
{
  "problem": {
    "name": "Sum of Three Integers",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc051_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given two integers $K$ and $S$.  \nThree variable $X, Y$ and $Z$ takes integer values satisfying $0≤X,Y,Z≤K$.  \nHow many different assignments of values to $X, Y$ and $Z$ are there such that $X...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments