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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const int N = 808;

char c[N][N];
pair<int,int> dp[N][N];
int ans = 1e9;
int h, w, K;

queue<tuple<int,int,int>> q;

set<pair<int,int>> s;

int main() {
    cin >> h >> w >> K;
    int starti, startj;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> c[i][j];
            if(c[i][j] == 'S') {
                starti = i; startj = j;
            }
        }
    }
    q.push(make_tuple(starti,startj,K+1));
    while(!q.empty()) {
        
        tuple<int,int,int> t = q.front(); q.pop();
        int i = get<0>(t); int j = get<1>(t);
        s.insert(make_pair(i, j));
        int k = get<2>(t);
        k--;
        if(k == 0) continue;
        if(i-1 >= 0 && c[i-1][j] == '.' && s.find(mp(i-1,j)) == s.end()) q.push(make_tuple(i-1,j,k));
        if(i+1 < h && c[i+1][j] == '.' && s.find(mp(i+1,j)) == s.end()) q.push(make_tuple(i+1,j,k));
        if(j-1 >= 0 && c[i][j-1] == '.' && s.find(mp(i,j-1)) == s.end()) q.push(make_tuple(i,j-1,k));
        if(j+1 < w && c[i][j+1] == '.' && s.find(mp(i,j+1)) == s.end()) q.push(make_tuple(i,j+1,k));
    }
    for(auto it = s.begin(); it != s.end(); ++it) {
        ans = min(ans, (int)ceil(1.0*it->fi/K) + 1);
        ans = min(ans, (int)ceil(1.0*it->se/K) + 1);
        ans = min(ans, (int)ceil(1.0*(h-1 - it->fi)/K) + 1);
        ans = min(ans, (int)ceil(1.0*(w-1 - it->se)/K) + 1);
    }
    
    cout << ans;
    
	return 0;
}