Quadruple

AtCoder
IDarc107_b
Time2000ms
Memory256MB
Difficulty
Given are integers $N$ and $K$. How many quadruples of integers $(a,b,c,d)$ satisfy both of the following conditions? * $1 \leq a,b,c,d \leq N$ * $a+b-c-d=K$ ## Constraints * $1 \leq N \leq 10^5$ * $-2(N-1) \leq K \leq 2(N-1)$ * All numbers in input are integers. ## Input Input is given from standard input in the following format: $N$ $K$ [samples]
Samples
Input #1
2 1
Output #1
4

Four quadruples below satisfy the conditions:

*   $(a,b,c,d)=(2,1,1,1)$
*   $(a,b,c,d)=(1,2,1,1)$
*   $(a,b,c,d)=(2,2,2,1)$
*   $(a,b,c,d)=(2,2,1,2)$
Input #2
2525 -425
Output #2
10314607400
API Response (JSON)
{
  "problem": {
    "name": "Quadruple",
    "description": {
      "content": "Given are integers $N$ and $K$. How many quadruples of integers $(a,b,c,d)$ satisfy both of the following conditions? *   $1 \\leq a,b,c,d \\leq N$ *   $a+b-c-d=K$",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc107_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given are integers $N$ and $K$. How many quadruples of integers $(a,b,c,d)$ satisfy both of the following conditions?\n\n*   $1 \\leq a,b,c,d \\leq N$\n*   $a+b-c-d=K$\n\n## Constraints\n\n*   $1 \\leq N \\leq 1...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments