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



Sample input:
2 5 4


Sample output:
2

Submission status: Runtime Error

Solution code:
num1, num2, num3 = input().split(" ")
numList = [int(num1),int(num2),int(num3)]
numList.sort(reverse=True)
maxNum = numList[0]
midNum = numList[1]
minNum = numList[2]

count = 0

def check():
    count += (midNum - minNum) // 2
    count += (maxNum - midNum)

if midNum % 2 == 0 and minNum % 2 == 0:
    #count += (midNum - minNum) // 2
    #count += (maxNum - midNum)
    check()
elif midNum % 2 == 1 and minNum % 2 == 1:
    if maxNum % 2 == 0:
        maxNum += 2
        midNum += 2
        midNum += 2
        #count += (midNum - minNum) // 2
        #count += (maxNum - midNum)
        check()
        count += 2
    else:
        check()
        #count += (midNum - minNum) // 2
        #count += (maxNum - midNum)
else:
    if midNum % 2 == 0:
        maxNum += 1
        minNum += 1
        check()
        #count += (midNum - minNum) // 2
        #count += (maxNum - midNum)
        count += 1
    else:
        maxNum += 1
        midNum += 1
        check()
        #count += (midNum - minNum) // 2
        #count += (maxNum - midNum)
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
import math

A, B, C = map(int, input().split())
maxN = max([A, B, C])
minN = min([A, B, C])
for n in [A, B, C]:
    if n != maxN and n != minN:
        midN = n
diff1 = maxN - midN
diff2 = maxN - minN

if (diff1 % 2 == 0 and diff2 % 2 == 0) or (diff1 % 2 != 0 and diff2 % 2 != 0):
    print((diff1 + diff2) // 2)
else:
    print(math.ceil((diff1 + diff2) / 2) + 1)

Submission status: Runtime Error

Solution code:
a,b,c=sorted(map(int,input().split()))
co=(b-a)//2
if (b-a)%2==1:counter+=1;c+=1
co+=c-b
print(co)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
def turn(n):
  global a,b,c
  def t(n,a):
    if n==a:return 0
    elif n<a:return a-n
    else:return (a-n+1)//2
  return t(n,a)+t(n,b)+(t,c)
mi=turn(0)
for i in range(1,51):mi=min(turn(i),mi)
print(mi)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
max_n=max(a,b,c)
diff=a+b+c-3*max_x
print((diff+1)//2)

Submission status: Runtime Error

Solution code:
A,B,C = map(int,input().split())
abc = [A,B,C]
Even = []
Odd = []
for i in range(3):
    if min(abc) == abc[i]:
        idx1 = i
    elif max(abc) == abc[i]:
        idx3 = i
    else:
        idx2 = i
    if abc[i]%2 == 0:
       Even += [i]
    else:
       Odd += [i]
       
#

if len(Even) == 3 or len(Odd) == 3:
    ans = (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 2:
    ans = 1
    abc[Even[0]] += 1
    abc[Even[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Odd) == 2:
    ans = 1
    abc[Odd[0]] += 1
    abc[Odd[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
    
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C = map(int,input().split())
abc = [A,B,C]
Even = []
Odd = []
for i in range(3):
    if min(abc) == abc[i]:
        idx1 = i
    elif max(abc) == abc[i]:
        idx3 = i
    else:
        idx2 = i
    if abc[i]%2 == 0:
       Even += [i]
    else:
       Odd += [i]
       
ans = 0

if len(Even) == 3 or len(Odd) == 3:
    ans = (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 2:
    ans += 1
    abc[Even[0]] += 1
    abc[Even[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Odd) == 2:
    ans += 1
    abc[Odd[0]] += 1
    abc[Odd[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
    
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C = map(int,input().split())
abc = [A,B,C]
Even = []
Odd = []
for i in range(3):
    if min(abc) == abc[i]:
        idx1 = i
    elif max(abc) == abc[i]:
        idx3 = i
    else:
        idx2 = i
    if abc[i]%2 == 0:
       Even += [i]
    else:
       Odd += [i]
       
ans = 0

if len(Even) == 3 or len(Odd) == 3:
    ans = (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 2:
    ans += 1
    abc[Even[0]] += 1
    abc[Even[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Odd) == 2:
    ans += 1
    abc[Odd[0]] += 1
    abc[Odd[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
    
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C = map(int,input().split())
abc = [A,B,C]
Even = []
Odd = []
for i in range(3):
    if min(abc) == abc[i]:
        idx1 = i
    elif max(abc) == abc[i]:
        idx3 = i
    else:
        idx2 = i
    if abc[i]%2 == 0:
       Even += [i]
    else:
       Odd += [i]
       
ans = 0

if len(Even) == 3 or len(Odd) == 3:
    ans = (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 2:
    ans += 1
    abc[Even[0]] += 1
    abc[Even[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
elif len(Even) == 1:
    ans += 1
    abc[Odd[0]] += 1
    ans[Odd[1]] += 1
    ans += (abc[idx3]-abc[idx2])//2 + (abc[idx3]-abc[idx1])//2
    
print(ans)

Submission status: Runtime Error

Solution code:
l=list(map(int(input().split())))
l=sorted(l)
a=l[0]
b=l[1]
c=l[2]
count=0
count+=c-b
if (b-a)%2==0:
  count+=(b-a)//2
else:
  count+=(b-a+1)//2+1
print(count)

Submission status: Runtime Error

Solution code:
L = list(map(int,input().split())).sort(reverse=True)
m = (L[0]-L[1]) % 2 - (L[0] - L[2]) % 2
if m == 0:
    print(L[0]+(-L[1]-L[2])//2)
else:
    print(L[0]+(-L[1]-L[2]+3)//2)

Submission status: Runtime Error

Solution code:
x=int(input())
y=sorted(x)
if (y[0]+y[1])%2==0:
  print((2*y[2]-y[1]-y[0])/2)
else :
  print((2*y[2]-y[1]-y[0]+3)/2)

Submission status: Runtime Error

Solution code:
A, B, C = LI()
X = max(A,B,C)
result1 = 3*X - (A+B+C)
result2 = 3*(X+1) - (A+B+C)
if result1%2 == 0:
    print(result1/2)
else:
    print(result2/2)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
a.sort()
diff1 = a[1] - a[0]
diff2 = a[2] - a[1]
diff3 = a[2] - a[0]
if diff1 % 2 == 0:
    if diff3 % 2 == 0:
        print((diff3 + diff2)//2)
    else:
        print(diff3//2 + diff2//2 + 1)
else:
    if diff3 % 2 == 0:
        print(diff3//2 + diff2//2 + 2)
    else:
        prnit(diff3//2 + diff2//2 + 2)

Submission status: Runtime Error

Solution code:
A, B, C = map(int, input().split())
cnt = 0
if A % 2 == B % 2 and B % 2 != C % 2:
  A += 1
  B += 1
  cnt += 1
elif A % 2 == C % 2  and C % 2 != B % 2 :
  A += 1
  B += 1
  cnt += 1
elif C % 2 == B % 2 and A % 2 != C %2 :
  C += 1
  B += 1
  cnt += 1
else :
  pass
L = [A, B, C]
L= soreted(L)
cnt += (L[2] - L [1])//2
cnt += (L[2] - L[0])//2
print(cnt)

Submission status: Runtime Error

Solution code:
a, b, c = sorted(map(int, input().split()))
diff = c - b
newa = a + diff
if (c - newa) % 2 == 0:
	print(d + (c - newa) // 2)
else:
	print(d + (c - newa + 3) // 2)

Submission status: Runtime Error

Solution code:
A = list(map(int, input().split()))
M = max(S)
r = sum(M - a for a in A)
print((r + 3 * (r % 2)) // 2)

Submission status: Runtime Error

Solution code:
n = map(int, input().split())
print((max(n)*3-sum(n))/2 if (sum(n)+max(n))%2 == 0 else ((max(n)+1)*3-sum(n))/2)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
if max(a) % sum(a) == 0:
  print((max(a)*3 - sum(a)) // 2)
else:
  print(((max(a)+1)*3 - sum(a)) // 2)

Submission status: Runtime Error

Solution code:
a, b = map(str, input().split())
c = int(a+b)
ans = 0
for i in range(c+1):
    if i ** 2 == c:
        ans +=1
        break
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
ds = [abs(e - max(a)) for e in a if e-max(a) != 0]

if ds:
    base = min(ds) - 1
    rem = max(ds) - base
    if rem == 1:
        print(base + 1)
    elif rem % 2 == 0:
        res = base + (rem - 2) // 2 + 3
    elif rem % 2 != 0:
        res = base + (rem - 1) // 2 + 1
else:
    res = 0

print(res)

Submission status: Runtime Error

Solution code:
mport sys
input=sys.stdin.readline

l=list(map(int,input().split()))
a,b,c=sorted(l)
#print(a,b,c)
if a%2==b%2 and a%2==c%2:
    print((2*c-a-b)//2)
elif a%2==b%2:
    print((2*c-2-a-b)//2+1)
else:
    print((2*c+1-a-b)//2+1)

Submission status: Runtime Error

Solution code:
a,b,c = map(int,input().input())
if max(a,b,c) % 2 == (a + b + c) % 2:
	print((3 * max(a,b,c) - (a + b + c)) // 2)
else:
	print((3 * (max(a,b,c) + 1) - (a + b + c)) // 2)

Submission status: Runtime Error

Solution code:
import math

def main():
    a, b, c = map(int, input().split())
    
    top = max([a, b, c])
    bot = min([a, b, c])
    global mid
    for x in [a, b, c]:
        if top != x and bot != x:
            mid = x
    count = 0
    
    count = top - mid
    bot += count
    mid += count
    
    if (top - bot) % 2 == 0:
        count += (top - bot) / 2 
    else:
        count += math.ceil((top - bot) / 2)+1
        
    print(int(count), end="")
    print()

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

def main():
    a, b, c = map(int, input().split())
    
    top = max([a, b, c])
    bot = min([a, b, c])
    for x in [a, b, c]:
        if top != x and bot != x:
            mid = x
    count = 0
    
    count = top - mid
    bot += count
    mid += count
    
    if (top - bot) % 2 == 0:
        count += (top - bot) / 2 
    else:
        count += math.ceil((top - bot) / 2)+1
        
    print(int(count), end="")
    print()

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
A, B, C = list(map(int, input().split()))
ABC = [A, B, C].sort()
A = ABC[0]
B = ABC[1]
C = ABC[2]

ans = 0

A = (C-A)//2
B =(C-B)//2

ans += (C-A)//2+(C-B)//2

if A == B == C:
    print(ans)
elif A ==C:
    print(ans+1)
else:
    print(ans+2)

Submission status: Runtime Error

Solution code:
abc = list(map(int, input().split(" ")))

only_num = get_only(abc, key=lambda x: x%2)
if only_num:
	abc.remove(only_num)
	abc = [only_num] + [abc_i+1 for abc_i in abc]
max_num = max(abc)
abc.remove(max_num)

print((max_num-abc[0] + max_num-abc[1])//2+bool(only_num))

Submission status: Runtime Error

Solution code:
N = list(map(int, input().split()))
N.sort()

for i in range(50):
    N[0] += 2
    if N[0] == N[1]:
        result = (i + 1) + (N[2] - N[1])
        break
        
    elif N[0] + 1 == N[1]:
        result = (i + 1) + (N[2] - N[1]) + 2

print(result)

Submission status: Runtime Error

Solution code:
T = list(map(int, input().split()))
T.sort()
T.reverse()

ope = 0

while T[1]!=T[0]:
    ope += 1
    T[1] += 1
    T[2] += 1
    
while T[2]<T[0]:
    ope += 1
    T[2] += 2

if T[0]==T[2]:
    print(ope)
    
else:print(ope+1)T = list(map(int, input().split()))
T.sort()
T.reverse()

ope = 0

while T[1]!=T[0]:
    ope += 1
    T[1] += 1
    T[2] += 1
    
while T[2]<T[0]:
    ope += 1
    T[2] += 2

if T[0]==T[2]:
    print(ope)
    
else:print(ope+1)

Submission status: Runtime Error

Solution code:
numList = input().split()
numList = list(map(int, numList))
commandList = [
	[2,0,0],
	[0,2,0],
	[0,0,2],
	[0,1,1],
	[1,0,1],
	[1,1,0]
]
numListList = [numList]

def search(depth):
	global numListList
	tmpList = []
	for numList in numListList:
		for command in commandList:
			sumedList = sumList(numList, command)
			if check(sumedList, depth+1):
				return
			tmpList.append(sumedList)
	numListList = tmpList
	search(depth+1)

def sumList(list1, list2):
	return [list1[0]+list2[0], list1[1]+list2[1], list1[2]+list2[2]]

def check(list1, count):
	if list1[0] == list1[1] and list1[1] == list1[2]:
		print(count)
		return True

	if list1[0] == list1[1]:
		if list1[0] > list1[2] and (list1[0]-list1[2])%2 == 0:
			print(int(count+(list1[0]-list1[2])/2))
			return True
		if list1[2] > list1[0]:
			print(int(count+(list1[2]-list1[0])))
			return True

	if list1[1] == list1[2]:
		if list1[1] > list1[0] and (list1[1]-list1[0])%2 == 0:
			print(int(count+(list1[0]-list1[2])/2))
			return True
		if list1[0] > list1[1]:
			print(int(count+(list1[0]-ist1[1])))
			return True

	if list1[0] == list1[2]:
		if list1[0] > list1[1] and (list1[0]-list1[1])%2 == 0:
			print(int(count+(list1[0]-list1[1])/2))
			return True
		if list1[1] > list1[0]:
			print(int(count+(list1[1]-list1[0])))
			return True

	

search(0)

Submission status: Runtime Error

Solution code:
numList = input().split()
numList = list(map(int, numList))
commandList = [
	[2,0,0],
	[0,2,0],
	[0,0,2],
	[0,1,1],
	[1,0,1],
	[1,1,0]
]
numListList = [numList]

def search(depth):
	global numListList
	tmpList = []
	for numList in numListList:
		for command in commandList:
			sumedList = sumList(numList, command)
			if check(sumedList, depth+1):
				return
			tmpList.append(sumedList)
	numListList = tmpList
	search(depth+1)

def sumList(list1, list2):
	return [list1[0]+list2[0], list1[1]+list2[1], list1[2]+list2[2]]

def check(list1, count):
	if list1[0] == list1[1] and list1[1] == list1[2]:
		print(count)
		return True

	if list1[0] == list1[1]:
		if list1[0] > list1[2]:
			print(int(count+(list1[0]-list1[2])/2)+1)
			return True
		if list1[2] > list1[0]:
			print(int(count+(list1[2]-list1[0])))
			return True

	if list1[1] == list1[2]:
		if list1[1] > list1[0]:
			print(int(count+(list1[0]-list1[2])/2)+1)
			return True
		if list1[0] > list1[1]:
			print(int(count+(list1[0]-ist1[1])))
			return True

	if list1[0] == list1[2]:
		if list1[0] > list1[1]:
			print(int(count+(list1[0]-list1[1])/2)+1)
			return True
		if list1[1] > list1[0]:
			print(int(count+(list1[1]-list1[0])))
			return True

	

search(0)

Submission status: Runtime Error

Solution code:
numList = input().split()
numList = list(map(int, numList))
commandList = [
	[2,0,0],
	[0,2,0],
	[0,0,2],
	[0,1,1],
	[1,0,1],
	[1,1,0]
]
numListList = [numList]

def search(depth):
	global numListList
	tmpList = []
	for numList in numListList:
		for command in commandList:
			sumedList = sumList(numList, command)
			if check(sumedList, depth+1):
				return
			tmpList.append(sumedList)
	numListList = tmpList
	search(depth+1)

def sumList(list1, list2):
	return [list1[0]+list2[0], list1[1]+list2[1], list1[2]+list2[2]]

def check(list1, count):
	if list1[0] == list1[1] and list1[1] == list1[2]:
		print(count)
		return True

	if list1[0] == list1[1]:
		if list1[0] > list1[2] and (list1[0]-list1[2])%2 == 0:
			print(int(count+(list1[0]-list1[2])/2))
			return True
		if list1[2] > list1[0]:
			print(int(count+(list1[2]-ist1[0])))
			return True

	if list1[1] == list1[2]:
		if list1[1] > list1[0] and (list1[1]-list1[0])%2 == 0:
			print(int(count+(list1[0]-list1[2])/2))
			return True
		if list1[0] > list1[1]:
			print(int(count+(list1[0]-ist1[1])))
			return True

	if list1[0] == list1[2]:
		if list1[0] > list1[1] and (list1[0]-list1[1])%2 == 0:
			print(int(count+(list1[0]-list1[1])/2))
			return True
		if list1[1] > list1[0]:
			print(int(count+(list1[1]-ist1[0])))
			return True

	

search(0)

Submission status: Runtime Error

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

is_odd_list = [A % 2 == 0, B % 2 == 0, C % 2 == 0]
if all(is_odd_list) or not any(is_odd_list):
    ans = 0
else:
    if sum(is_odd_list) == 1:
        is_odd_list = not is_odd_list
    A = A + is_odd_list[0]
    B = B + is_odd_list[1]
    C = C + is_odd_list[2]
    ans = 1

num_list = sorted([A, B, C])
ans += (num_list[2] - num_list[0]) / 2 + (num_list[2] - num_list[1]) / 2
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    #1. make master list
    N = int(input())
    A = list(map(int, input().split()))

    A.append(0)
    A.insert(0,0)

    A = np.array(A)
    
    cost = np.abs(A[1:] - A[:-1])    
    total = sum(cost)    
    #2. remove i-th componet
    for i in range(N):

        #3. output
        print(total - cost[i] - cost[i+1] + abs(A[i+2]-A[i]))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math

def main():
    a, b, c = map(int, input().split())
    
    top = max([a, b, c])
    bot = min([a, b, c])
    for x in [a, b, c]:
        if top != x and bot != x:
            mid = x
    count = 0
    
    count = top - mid
    bot += count
    mid += count
    
    if (top - bot) % 2 == 0:
        count += (top - bot) / 2 
    else:
        count += math.ceil((top - bot) / 2)+1
        
    print(int(count), end="")

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
lst = list(map(int, input().split()))
n = 0

while True:
    if lst[0] == lst[1] and lst[1] == lst[2]:
        break
    
    minimum = min(lst)
    maximum = max(lst)

    if maximum-minimum >= 2:
        idx = lst.index(minimum)
        lst[idx] += 2
        
    else:
        idx = lst.index(minimum)
        lst[idx] += 1
        idx = lst.index(minimum)
        lst[idx] += 1
    n += 1
print(n)

Submission status: Runtime Error

Solution code:
A,B,C = map(int,input().split())
max_val=(max([A,B,C]))
odd_chk =3 * max_val - A - B - C
if(odd_chk%2 == 0):
         print("{:.0f}".format(odd_chk/2))
else:
         print("{:.0f}".format(odd_chk+3)/2)

Submission status: Runtime Error

Solution code:
import numpy as np
A, B, C = map(int,input().split(' '))

Srt = np.sort([A,B,C])

if np.sum(Srt % 2) == (0 or 3): a = 0
elif np.sum(Srt % 2) == (1 or 2): a = 1

num = a + np.sum(Srt[2] // 2 - (Srt // 2))

print(num)

Submission status: Runtime Error

Solution code:
def main():
    A, B, C = map(int, input().split())
    m = max(A, B, C)
    d = sum(A, B, C) - m
    if d % 2 == 0:
        print(d//2)
    else:
        print((d//2)+2)

main()