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



Sample input:
4 12 20


Sample output:
3

Submission status: Runtime Error

Solution code:
def log_2(n):
    t = 0
    while n:
        if n % 2 == 1:
            break
        t += 1
        n //= 2
    return t


def solve(A, B, C)->int:

    s = A+B+C
    odd = log_2(s-C)
    even = log_2(s+A)

    if odd == even:
        return odd
    else:
        return odd+1


A, B, C = map(int, input().split())
A, B, C = sort([A, B, C])

ans = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    ans = 0
elif A == B == C:
    ans = -1
else:
    ans = solve(A, B, C)
print(ans)

Submission status: Runtime Error

Solution code:
a = lma()
f = 1
c =0
while f:
    if (a[0] == a[1] and a[0] == a[2]) :
        c=-1
        break
    if a[0]%2==1 or a[1]%2==1 or a[2]%2 ==1:break
    a[0],a[1],a[2] = (a[1]+a[2])/2,(a[0]+a[2])/2,(a[1]+a[0])/2
    c+=1
print(c)

Submission status: Runtime Error

Solution code:
a,b,c = map(int, input().split())
d,e,f = abs(b-a),abs(c-b),abs(a-c)
ans = 0
if d == e and e == f:
  print(-1)
else:
  while d % 2 == 0 and e % 2 == 0 f % 2 == 0:
    ans += 1
    d //= 2
    e //= 2
    f //= 2
  print(ans)

Submission status: Runtime Error

Solution code:
a,b,c = map(int, input().split())
d,e,f = abs(b-a),abs(c-b),abs(a-c)
if d == e and e == f:
  print(-1)
ans = 0
else:
  while d % 2 == 0 and e % 2 == 0 f % 2 == 0:
    ans += 1
    d //= 2
    e //= 2
    f //= 2
  else:
    print(ans)

Submission status: Runtime Error

Solution code:
A, B, C = map(int, input().split())

if A == B == C and all(lambda x: x%2==0, [A, B, C]):
    print(-1)
else:
    ans = 0
    cookie = A+B+C
    while True:
        if all(map(lambda x: x%2==0, [A, B, C])):
            ans += 1
        else:
            print(ans)
            break
        A = (cookie-A) / 2
        B = (cookie-B) / 2
        C = (cookie-C) / 2

Submission status: Runtime Error

Solution code:
def isOdd(num):
	if num % 2 == 0:
		return False
	else:
		return True

A, B, C = map(int, raw_input().split())
ans = 0
while not isOdd(A) and not isOdd(B) and not isOdd(C):
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if set(A, B, C) == set(new1, new2, new3):
		print -1
	else:
		A, B, C = new1, new2, new3
print ans

Submission status: Runtime Error

Solution code:
import pdb
a,b,c = map(int, raw_input().strip().split(' '))
if a==b==c:
    if a%2==0:
        print '-1'
    else
        print '0'
elif a%2!=0 or b%2!=0 or c%2!=0:
    print '0'
else:
    Flag = True
    cnt = 0
    for i in range(100000):
        tmp1,tmp2=a,b
        a = b/2+c/2
        b = tmp1/2+c/2
        c = tmp1/2+tmp2/2
        cnt += 1
#         pdb.set_trace()
        if a%2!=0 or b%2!=0 or c%2!=0:
            Flag = False
            break
    if Flag:
        print '-1'
    else:
        print cnt

Submission status: Runtime Error

Solution code:
n = int(input())
p2 = [ int(i) for i in input().split() ]
ps = sorted(p2)

cnt=0
while True:
    if p2 == ps: break
    cnt += 1
    high = []
    low = []
    for i in range(len(p2)):
        if p2[i] == max(p2[0:i+1]):
            high.append(p2[i])
        else:
            low.append(p2[i])
    p2 = low + high

print(cnt)

Submission status: Runtime Error

Solution code:
# coding: utf-8

a, b, c = map(int, input().rstrip().split())
count = 0

while True:
    elif a == b and b == c and c == a :
        count = -1 if a % 2 == 1 else 0
        break
    if a % 2 == 0 and b % 2 == 0 and c % 2 == 0 :
        a, b, c = (b+c)/2, (c+a)/2, (a+b)/2
        count += 1
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
def dist(r, c):
    return min(r, H - r - 1, c, W - c - 1)

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

for r in range(H):
    for c in range(W):
        if A[r][c] == 'S':
            sr = r
            sc = c

dxy = [(1, 0), (0, -1), (-1, 0), (0, 1)]
pos = [(sr, sc)]
dic = {(sr, sc): K}
cnt = 0
ans = H * W
i = 0
while i < len(pos):
    r0, c0 = pos[i]
    d0 = dist(r0, c0)
    ans = min(ans, (d0 + K - 1) // K + 1)
    m0 = dic[(r0, c0)]
    if 0 < m0:
        m = m0 - 1
        for (dx, dy) in dxy:
            r = r0 + dy
            c = c0 + dx
            d = dist(r, c)
            if 0 <= r < H and 0 <= c < W and A[r][c] != '#' and (r, c) not in dic:
                pos.append((r, c))
                dic[(r, c)] = m
    i += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
# 整数の入力
N,M=list(map(int, input().split()))
p=[]
q=0
count=0
for i in range(0,M):
  p.append(list(map(int, input().split())))
for i in range(0,M):
  q+=p[i][0]-p[i][1]
if q%2==1:
  print("NO")
else:
  m=int(M/100)
  for j in range(0,M,m):
    for i in range(0,M):
      if p[i][0]==j or p[i][1]==j:
        count+=1
    if count%2==1:
      print("NO")
      sys.exit()
  else: 
    print("YES")

Submission status: Runtime Error

Solution code:
N,M = map(int,raw_input().split())
node_list = [0 for l in range(N)]
for i in range(M):
    items = map(int,raw_input().split())
    node_list[items[0]-1]+=1
    node_list[items[1]-1]+=1
flag=False
for n in range(N):
    if n%2==1:
        flag=True
        
if flag:
    print 'NO'
else:
    print 'YES'

Submission status: Runtime Error

Solution code:
N,M = map(int,raw_input().split())
node_list = [0 for l in range(N)]
for i in range(M):
    items = map(int,raw_input().split())
    node_list[items[0]-1]+=1
    node_list[items[1]-1]+=1
flag=False
for n in range(N):
    if n%2==1:
        flag=True
        
if flag:
    print 'NO'
else:
    print 'YES'

Submission status: Runtime Error

Solution code:

N,M = map(int,raw_input().split())
node_list = [0 for l in range(N)]
for i in range(M):
    items = map(int,raw_input().split())
    node_list[items[0]-1]+=1
    node_list[items[1]-1]+=1
flag=False
for i in range(N):
    if node_list[i]%2==1:
        flag=True
        
if flag:
    print 'YES'
else:
    print 'NO'

Submission status: Runtime Error

Solution code:
A=int(input()) 
B=int(input()) 
C=int(input())
time=0 
s=0
if A==B and B==C and A%2==0:
    print(-1)
else: 
    while(s==0): 
        if A%2==1 or B%2==1 or C%2==1: 
            print(time) 
            break; 
        else: 
            time+=1
            a=int(A/2)
            b=int(B/2) 
            c=int(C/2)
            A=b+c
            B=c+a
            C=a+b

Submission status: Runtime Error

Solution code:
def main():
    a, b, c = map(int, input().split())
    count = 0
    while (a | b | c) & 1 == 0:
        if a==b==c:
            print(-1)
            return
        a, b, c = (b + c) >> 1, (c + a) >> 1, (a + b) >> 1
        count += 1
        print(a,b,c)
    
    print(count)

while True:
    main()