Under construction

Still being built. Things may change

King's Inspection

Interview

Time limit1sMemory limit512 MB

Summary
Given three coin counts, each second you add one coin to two different chests; find the minimum number of seconds to make all three equal.
Level

Medium4 of 10

Topics
Greedy, Math, Implementation, Brute force
Solved
No attempts yet

Problem

The treasury of the Far Far Away Kingdom is in trouble: the King is coming with an inspection. The King is known to like order, so the chief treasurer needs to put the three chests that store the Kingdom's gold coins in order. He looked into the chests and found that they contain aa, bb, and cc coins, respectively. But the King would certainly like the chests to contain the same number of coins each.

To make the number of coins equal, the chief treasurer started adding coins with both hands. Each second he chooses two distinct chests and adds one more coin to each of them.

Help the chief treasurer find how many seconds he needs to make the number of coins in the chests equal.

Input

The input contains three lines.

The first line contains an integer aa.

The second line contains an integer bb.

The third line contains an integer cc (1≤a,b,c≤5⋅1081 \le a, b, c \le 5\cdot 10^8).

Output

Output one integer: the minimum number of seconds the chief treasurer needs to make the number of coins in the chests equal.

Notes

One optimal strategy for the first test is the following: first, add a coin to chests 1 and 3, then add a coin to chests 1 and 2, and again to chests 1 and 2.

All chests in the second test already contain an equal number of coins.

Examples2

  1. Example 1

    Input
    1
    2
    3
    
    Expected output
    3
    
  2. Example 2

    Input
    2
    2
    2
    
    Expected output
    0