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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Collections;

namespace DivideChocolate
{
    class Program
    {
        static long H;
        static long W;
        static long K;
        static string[] S;
        static void Main(string[] args)
        {
            var ABC = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = ABC[0];
            var B = ABC[1];
            var C = ABC[2];

            if(A < B)
            {
                Swap(ref A, ref B);
            }
            if(B < C)
            {
                Swap(ref B, ref C);
            }
            if (A < B)
            {
                Swap(ref A, ref B);
            }

            var ans = A - B;
            C += (A - B);

            if ((A-C)%2 == 0)
            {
                ans += (A - C) / 2;
            }
            else
            {
                ans += ((A - C) / 2) + 2;
            }
            Console.WriteLine(ans);
        }
        static void Swap<T>(ref T a, ref T b)
        {
            var tmp = a;
            a = b;
            b = tmp;
        }

        static long Culculate(int i)
        {
            long ans = 0;
            var sum = new long[H];

            for (int j = 0; j < W; j++)
            {
                var tmp = new long[H];

                for (int k = 0; k < H;)
                {
                    long white = 0;
                    var st = k;
                    while (k < H)
                    {
                        if (S[k][j] == '1')
                        {
                            white++;
                            if(white > K)
                            {
                                return long.MaxValue;
                            }
                        }

                        if ((i & (int)Pow(2, k)) == 1)
                        {
                            for (int w = st; w <= k; w++)
                            {
                                tmp[w] = white;
                            }
                            white = 0;
                            k++;
                            break;
                        }
                        else
                        {
                            k++;
                        }
                    }


                    for (int w = st; w < H; w++)
                    {
                        tmp[w] = white;
                    }
                }

                for (int k = 0; k < H; k++)
                {
                    if(sum[k]+tmp[k] <= K)
                    {
                        sum[k] += tmp[k];
                    }
                    else
                    {
                        Array.Copy(tmp, sum,sum.Length);
                        ans++;
                        break;
                    }
                }
            }
            return ans;
        }
    }


    public class PriorityQueue<T> : IEnumerable<T>
    {
        private readonly List<T> _data = new List<T>();
        private readonly IComparer<T> _comparer;
        private readonly bool _isDescending;

        public PriorityQueue(IComparer<T> comparer, bool isDescending = true)
        {
            _comparer = comparer;
            _isDescending = isDescending;
        }

        public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
            : this(Comparer<T>.Create(comparison), isDescending)
        {
        }

        public PriorityQueue(bool isDescending = true)
            : this(Comparer<T>.Default, isDescending)
        {
        }

        public void Enqueue(T item)
        {
            _data.Add(item);
            var childIndex = _data.Count - 1;
            while (childIndex > 0)
            {
                var parentIndex = (childIndex - 1) / 2;
                if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
                    break;
                Swap(childIndex, parentIndex);
                childIndex = parentIndex;
            }
        }

        public T Dequeue()
        {
            var lastIndex = _data.Count - 1;
            var firstItem = _data[0];
            _data[0] = _data[lastIndex];
            _data.RemoveAt(lastIndex--);
            var parentIndex = 0;
            while (true)
            {
                var childIndex = parentIndex * 2 + 1;
                if (childIndex > lastIndex)
                    break;
                var rightChild = childIndex + 1;
                if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0)
                    childIndex = rightChild;
                if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
                    break;
                Swap(parentIndex, childIndex);
                parentIndex = childIndex;
            }
            return firstItem;
        }

        public T Peek()
        {
            return _data[0];
        }

        private void Swap(int a, int b)
        {
            var tmp = _data[a];
            _data[a] = _data[b];
            _data[b] = tmp;
        }

        private int Compare(T a, T b)
        {
            return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
        }

        public int Count => _data.Count;

        public IEnumerator<T> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }


}