Problem:
Score : 300 points

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

Choose two among A, B and C, then increase both by 1.

Choose one among A, B and C, then increase it by 2.

It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Constraints

0 \leq A,B,C \leq 50

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the minimum number of operations required to make A, B and C all equal.

Sample Input 1

2 5 4

Sample Output 1

2

We can make A, B and C all equal by the following operations:

Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.

Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.

Sample Input 2

2 6 3

Sample Output 2

5

Sample Input 3

31 41 5

Sample Output 3

23

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::stdin;
use std::str::FromStr;
use std::cmp::max;
use std::cmp::min;

fn main(){
    let (a, b, c): (i64, i64, i64) = get_triple();
    let mx = max(max(a, b), c);
    let mn = min(min(a, b), c);
    let md = a + b + c - mn - mx;
    let rem = 3*mx - (a+b+c);
    if rem % 2 == 0 {
        println!("{}", rem / 2);
    } else {
        if 0 == (mx+mn)%2 {
            let d = (mx-md)/2 + (mx-md)%2;
            let md2 = md + d*2;
            println!("{}", d + (2*md2 - (mx+mn))/2);
        } else {
            let d = (mx-mn)/2 + (mx-mn)%2;
            let mn2 = mn + d*2;
            println!("{}", d + (2*mn2 - (mx+md))/2);
        }
    }
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}