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>
using namespace std;

int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};

int main(){
  int h,w;
  int k;
  cin>>h>>w>>k;
  vector<string> a(h);
  for(int i=0;i<h;i++) cin>>a[i];
  pair<int,int> s;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='S'){
	s.first=i;
	s.second=j;
	i=h;
	j=w;
      }
    }
  }
  auto isrange=[&h,&w](int i,int j){return 0<=i && i<h && 0<=j && j<w;};

  queue<pair<pair<int,int>,int>> que;
  vector<vector<int>> reach(h,vector<int>(w,0));
  que.push(make_pair(s,k));
  while(!que.empty()){
    auto st=que.front();
    que.pop();
    auto p=st.first;
    int step=st.second;
    if(reach[p.first][p.second]) continue;
    reach[p.first][p.second]=true;
    if(step==0) continue;
    for(int i=0;i<4;i++){
      int toh=p.first+dh[i];
      int tow=p.second+dw[i];
      if(isrange(toh,tow) && !reach[toh][tow] && a[toh][tow]!='#'){
	reach[toh][tow]=1;
	que.push(make_pair(make_pair(toh,tow),step-1));
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(reach[i][j]) que.push(make_pair(make_pair(i,j),k));
    }
  }
  while(!que.empty()){
    auto st=que.front();
    que.pop();
    auto p=st.first;
    int score=st.second;
    if(p.first==0 || p.first==h-1 || p.second==0 || p.second==w-1){
      cout<<score/k+((score%k)!=0)<<endl;
      return 0;
    }
    for(int i=0;i<4;i++){
      int toh=p.first+dh[i];
      int tow=p.second+dw[i];
      if(!reach[toh][tow]){
	reach[toh][tow]=1;
	que.push(make_pair(make_pair(toh,tow),score+1));
      }
    }

  }
  return 1;
}