Problem:
Score : 300 points

Problem Statement

Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:

Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.

This action will be repeated until there is a person with odd number of cookies in hand.

How many times will they repeat this action?
Note that the answer may not be finite.

Constraints

1 ≤ A,B,C ≤ 10^9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times the action will be performed by the three people, if this number is finite.
If it is infinite, print -1 instead.

Sample Input 1

4 12 20

Sample Output 1

3

Initially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,

After the first action, they have 16, 12 and 8.

After the second action, they have 10, 12 and 14.

After the third action, they have 13, 12 and 11.

Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.

Sample Input 2

14 14 14

Sample Output 2

-1

Sample Input 3

454 414 444

Sample Output 3

1

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            AGC014.A();
        }

        class AGC014
        {
            public static void A()
            {
                var A = Read.Long();
                var B = Read.Long();
                var C = Read.Long();
                if (A == B && B == C) { Console.WriteLine(-1); return; }
                int max = 1;
                var d1 = A - B;
                var d2 = A - C;
                for (int i = 0; i < 30; ++i)
                {
                    var n = 1L << i;
                    if (d1 % n == 0 && d2 % n == 0)
                    {
                        max = i;
                    }
                }
                Console.WriteLine(max);
            }
            public static void B()
            {
                var N = Read.Int();
                var M = Read.Int();
                var AB = Read.TupleInt(M);
                int[] count = new int[N + 1];
                foreach(var ab in AB)
                {
                    count[ab.Item1]++;
                    count[ab.Item2]++;
                }
                Console.WriteLine(count.Count(x => x % 2 == 1) == 0 ? "YES" : "NO");
            }
            public static void C()
            {
                var H = Read.Int();
                var W = Read.Int();
                var K = Read.Int();
                var A = new bool[H + 2, W + 2];
                int Sh = -1, Sw = -1;
                for (int h = 0; h < H; ++h)
                {
                    var str = Read.Str();
                    for (int w = 0; w < W; ++w)
                    {
                        switch (str[w])
                        {
                            case '.': A[h + 1, w + 1] = true; break;
                            case 'S': A[h + 1, w + 1] = true; Sh = h + 1; Sw = w + 1; break;
                        }
                    }
                }
                var dist = new int[H + 2, W + 2];
                for (int h = 0; h < H + 2; ++h)
                {
                    for (int w = 0; w < W + 2; ++w)
                    {
                        dist[h, w] = -1;
                    }
                }
                var dx = new int[] { 0, 1, 0, -1 };
                var dy = new int[] { 1, 0, -1, 0 };
                Queue<Tuple<int, int>> queue = new Queue<Tuple<int, int>>();
                queue.Enqueue(new Tuple<int, int>(Sh, Sw));
                dist[Sh, Sw] = 0;
                while (queue.Count > 0)
                {
                    var t = queue.Dequeue();
                    if (dist[t.Item1, t.Item2] >= K) { continue; }
                    for(int i = 0; i < 4; ++i)
                    {
                        var x = t.Item1 + dx[i];
                        var y = t.Item2 + dy[i];
                        if(A[x,y] && dist[x, y] < 0)
                        {
                            dist[x, y] = dist[t.Item1, t.Item2] + 1;
                            queue.Enqueue(new Tuple<int, int>(x, y));
                        }
                    }
                }
                var min = 100000000;
                for (int h = 0; h < H + 2; ++h)
                {
                    for (int w = 0; w < W + 2; ++w)
                    {
                        if(dist[h, w] >= 0)
                        {
                            var d = Math.Min(h - 1, Math.Min(H - h, Math.Min(w - 1, W - w)));
                            min = Math.Min(min, d);
                        }
                    }
                }
                Console.WriteLine(1 + (min + K - 1) / K);
            }
            public static void D()
            {
                var N = Read.Int();
                var Adj = Read.AdjacencyList(N, N - 1);
                var dist = Graph.CalcDistance_OnTree(Adj, N, 1);
                var order = Enumerable.Range(1, N).OrderBy(i => -dist[i]).ToArray();
                var delete = new bool[N + 1];
                foreach(var v in order)
                {
                    if (delete[v]) { continue; }
                    delete[v] = true;
                    bool ok = false;
                    foreach(var w in Adj[v])
                    {
                        if (!delete[w])
                        {
                            ok = true;
                            delete[w] = true;
                            break;
                        }
                    }
                    if (!ok)
                    {
                        Console.WriteLine("First"); return;
                    }
                }
                Console.WriteLine("Second");
            }
        }

        class Graph
        {
            public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start)
            {
                var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
                dist[start] = 0;
                Queue<int> queue = new Queue<int>();
                queue.Enqueue(start);
                while (queue.Count > 0)
                {
                    var v = queue.Dequeue();
                    foreach (var w in adj[v])
                    {
                        if (dist[w] < 0)
                        {
                            dist[w] = dist[v] + 1;
                            queue.Enqueue(w);
                        }
                    }
                }
                return dist;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}