Arithmetic Sequence

AtCoder
IDarc123_a
Time2000ms
Memory256MB
Difficulty
Given is a sequence of three integers $A = (A_1, A_2, A_3)$. On this sequence, you can do the following operation any number of times: * choose $i\in {1,2,3}$ and add $1$ to $A_i$. Find the minimum number of operations needed to make $A$ arithmetic. Here, the sequence $A = (A_1, A_2, A_3)$ is arithmetic when $A_2 - A_1 = A_3 - A_2$ holds. ## Constraints * $1\leq A_1, A_2, A_3\leq 10^{15}$ ## Input Input is given from Standard Input in the following format: $A_1$ $A_2$ $A_3$ [samples]
Samples
Input #1
4 8 10
Output #1
2

One operation with $i = 1$ and then one operation with $i = 3$ yield an arithmetic sequence $(5, 8, 11)$.
Input #2
10 3 4
Output #2
4

Four operations with $i = 2$ yield an arithmetic sequence $(10, 7, 4)$.
Input #3
1 2 3
Output #3
0

The sequence $A$ is already arithmetic from the beginning, so we need zero operations.
Input #4
1000000000000000 1 1000000000000000
Output #4
999999999999999
API Response (JSON)
{
  "problem": {
    "name": "Arithmetic Sequence",
    "description": {
      "content": "Given is a sequence of three integers $A = (A_1, A_2, A_3)$. On this sequence, you can do the following operation any number of times: *   choose $i\\in {1,2,3}$ and add $1$ to $A_i$. Find the minimu",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc123_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a sequence of three integers $A = (A_1, A_2, A_3)$. On this sequence, you can do the following operation any number of times:\n\n*   choose $i\\in {1,2,3}$ and add $1$ to $A_i$.\n\nFind the minimu...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments