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: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c = readInts()
s = a+b+c
k = max(a,b,c)*3 - s
if k%2 == 0:
    print(k//2)
else:
    print(k//2 + 2)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split(" "))
max_v = max(a, b, c)
sum_v = a + b + c
cc = 0
if max_v % 2 == sum_v %2:
    cc = (3 * max_v - sum_v) // 2
else :
    cc = (3 * (max_v + 1) - sum_v) // 2

print(cc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C = sorted(map(int, input().split()))
B, C = B-A, C-A
def calc(x):
  return (x+x%2)//2+x%2 if x>0 else -x
print(min(calc(i)+calc(i-B)+calc(i-C) for i in range(51)))

Submission status: Accepted

Solution code:
# 2020/07/18
# AtCoder Beginner Contest 093 - C

# Input
abc = list(map(int,input().split()))
abc.sort()

ans = 0

s1 = abc[2] - abc[0]
s2 = abc[2] - abc[1]

# Calc
if s1 > 0:
    # even & even
    if s1 % 2 == 0 and s2 % 2 == 0:
        ans = s1 // 2 + s2 // 2
        
    # odd & odd
    elif s1 % 2 > 0 and s2 % 2 > 0:
        s1 = s1 - 1
        s2 = s2 - 1
        ans = s1 // 2 + s2 // 2 + 1
    # odd & even(eg:5 2 3)
    else:
        ans = s1 // 2 + s2 // 2 + 2

# Output
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

v = inl()
v.sort()


def solve():
    k1 = (v[2] - v[0]) // 2
    v[0] += 2 * k1
    k2 = (v[2] - v[1]) // 2
    v[1] += 2 * k2
    if v[0] == v[1] == v[2]:
        return k1 + k2
    elif v[0] == v[1] == (v[2] - 1):
        return k1 + k2 + 1
    else:
        return k1 + k2 + 2


print(solve())

Submission status: Accepted

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

s = sum([i%2 for i in n])

if s == 0 or s == 3:
    m = max(n)
    res = 0
    for i in n:
        res += (m-i)//2
    print(res)
elif s == 1:
    for i in range(3):
        if n[i]%2 == 0:
            n[i] += 1
    res = 1
    m = max(n)
    for i in n:
        res += (m-i)//2
    print(res)
else:##s == 2
    for i in range(3):
        if n[i]%2:
            n[i] += 1
    res = 1
    m = max(n)
    for i in n:
        res += (m-i)//2
    print(res)

Submission status: Accepted

Solution code:
A = sorted(list(map(int,input().split())))
cnt = 0
n = (A[2]-A[0])//2
cnt += n
A[0] += 2*n
n = (A[2]-A[1])//2
cnt += n
A[1] += 2*n
A = sorted(A)
if A[0]<A[1]==A[2]:
    cnt += 2
elif A[0]==A[1]<A[2]:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
a = sorted(list(map(int, input().split())))
ans = 0
if (a[0]%2==0 and a[1]%2==0) or (a[0]%2!=0 and a[1]%2!=0):
    ans = a[2]-a[1] + (a[2]-(a[0]+a[2]-a[1]))//2
else:
    ans = 1
    a[1] += 1
    a[2] += 1
    ans += (a[1]-a[0])//2 + a[2]-a[1]
print(ans)

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
A.sort()
ans = (A[2]-A[1])+(A[1]-A[0])//2+((A[1]-A[0])%2)*2
print(ans)

Submission status: Accepted

Solution code:
a = sorted(list(map(int, input().split(" "))))
count = 0
a[0] += a[2] - a[1]
count += a[2] - a[1]

if (a[2] - a[0]) % 2 == 0:
  print(count +  ((a[2] - a[0]) // 2))
else:
  print(count +  ((a[2] - a[0]) // 2) + 2)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())

if a >= b and a >= c:
    if (2*a - b - c) % 2 == 0:
        print(int((2*a - b - c)/2))
    else:
        print(int((2*a - b - c)//2 + 2))
elif b >= a and b >= c:
    if (2*b -a -c) %2 == 0:
        print(int((2*b -a -c)/2))
    else:
        print(int((2*b -a -c)//2 +2))
else:
    if (2*c -b-a) % 2 ==0:
        print(int((2*c -b-a)/2))
    else:
        print(int((2*c -b-a)//2 +2))

Submission status: Accepted

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

ABC.sort(reverse = True)

step1 = ABC[0] - ABC[1]
step2 = ABC[0] - ABC[2] - step1

if step2 % 2 == 0:
    result  = int(step2 / 2) + step1
else:
    result = int(step2 / 2) + step1 + 2
print(result)

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())

abc = [a,b,c]
abcs = sorted(abc)

ac =abcs[2]-abcs[0]
bc =abcs[2]-abcs[1]

res = 0

res += ac//2
res += bc//2

dx = ac % 2
dy = bc % 2

if dx + dy ==0:
    print(res)
elif dx + dy ==2:
    print(res+1)
else:
    print(res+2)

Submission status: Accepted

Solution code:
abc = list(map(int, input().split()))
abc.sort()
ans = abc[2] - abc[1]
abc[0] += ans

if (abc[2]-abc[0]) % 2 == 0:
    ans += (abc[2]-abc[0]) // 2
else:
    ans += (abc[2]-abc[0]) // 2 + 2

print(ans)

Submission status: Accepted

Solution code:
nums = [int(w) for w in input().split()]

nums.sort()
ans = 0
if (nums[1]-nums[0]) % 2 == 1:
    nums[0] -= 1
    ans += 1

ans += (nums[1]-nums[0])//2
ans += nums[2]-nums[1]
print(ans)

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
s = sorted([A, B, C])
a = s[2] - s[0]
b = s[2] - s[1]

a_odd = a % 2 == 1
b_odd = b % 2 == 1

ans = a // 2 + b // 2

if a_odd and b_odd:
    ans += 1
elif a_odd and not b_odd:
    ans += 2
elif not a_odd and b_odd:
    ans += 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = list(map(int, input().split()))
X.sort()
ba = X[1] - X[0]
ca = X[2] - X[0]
cb = X[2] - X[1]
if ba % 2 == 0 and ca % 2 == 0:
    print((ca + cb) // 2)
elif ba % 2 == 0:
    print(1 + (ca - 1 + cb - 1) // 2)
else:
    print((cb + ca + 1) // 2 + 1)

Submission status: Accepted

Solution code:
def main():
    num = sorted(map(int, input().split()))

    cnt = 0
    a = num[2] - num[1]
    cnt += a
    num[0] += a

    if (num[2] - num[0]) % 2 == 0:
        cnt += (num[2] - num[0]) // 2
    else:
        cnt += (num[2] - num[0]) // 2 + 2

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    num_list = i_list()

    num_list.sort()

    diff = num_list[2] * 2 - num_list[1] - num_list[0]

    ans = diff / 2

    if diff % 2 == 1:
        ans += 2
    
    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    A = sorted([int(i) for i in input().split()])
    if max(A) * 3 % 2 == sum(A) % 2:
        print((max(A) * 3 - sum(A)) // 2)
    else:
        print(((max(A) + 1) * 3 - sum(A)) // 2)


resolve()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    A, B, C = map(int, input().split())
    ma, mi = max(A,B,C), min(A,B,C)
    if ma*3%2 != (A+B+C)%2:
        ma += 1
    ans = (ma*3-(A+B+C))//2 + (ma*3-(A+B+C))%2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print((a[2] - a[1]) + (a[1] - a[0]) // 2 + (a[1] - a[0]) % 2 * 2)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ABC = il()
    mx = max(ABC)
    sm = sum(ABC)
    m = mx * 3 - sm
    while m % 2 != 0:
        m += 3
    print(m//2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
s, m, b = sorted(a)
cnt = 0
m_s = m - s
cnt += b - m
cnt += m_s // 2

if m_s % 2 == 1:
    cnt += 2
print(cnt)

Submission status: Accepted

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

ans=0
ans+=C-B

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

if A%2 != B%2:
    ans+=2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C=map(int,input().split())
X,Y,Z=sorted([A,B,C])

K=0
while Y<Z:
    X+=1
    Y+=1
    K+=1

while X<Y:
    X+=2
    K+=1

if X!=Y:
    K+=1
print(K)

Submission status: Accepted

Solution code:
import numpy as np
 
L=np.array(list(map(int,input().split())))
ans=0
 
while True:
    if L[0]==L[1] and L[1]==L[2]:
        break
    L=sorted(L-max(L))
    if L[1]<L[2]:
        L[0]+=1
        L[1]+=1
        ans+=1
    else:
        L[0]+=2
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
A,B,C = [int(i) for i in input().split()]
if A%2 == B%2 == C%2:
    m = max(A,B,C)
    print((3*m - A - B - C)//2)
elif A%2 == B%2:
    A += 1
    B += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)
elif A%2 == C%2:
    A += 1
    C += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)
elif B%2 == C%2:
    B += 1
    C += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

a,b,c = sorted(I())
ans = 0
a += c-b
ans += c-b
if (c-a)%2==0:
    print(ans+(c-a)//2)
else:
    print(ans+(c-a)//2 +2)

Submission status: Accepted

Solution code:
a = sorted(list(map(int, input().split())))

s = sum(a)
if s%2==a[2]%2:
  if a[2]%2==a[1]%2:
    print((a[2]-a[1])//2+(a[2]-a[0])//2)
  else:
    a[1] += 1
    a[0] += 1
    print((a[2]-a[1])//2+(a[2]-a[0])//2+1)
else:
  a[2] += 1
  a[1] += 1
  if a[2]%2==a[1]%2:
    print((a[2]-a[1])//2+(a[2]-a[0])//2+1)
  else:
    a[1] += 1
    a[0] += 1
    print((a[2]-a[1])//2+(a[2]-a[0])//2+2)

Submission status: Accepted

Solution code:
import numpy as np

L=np.array(list(map(int,input().split())))
ans=0

while True:
  if L[0]==L[1] and L[1]==L[2]:
    break
  L=sorted(L-max(L))
  if L[1]<L[2]:
    L[0]+=1
    L[1]+=1
    ans+=1
  else:
    L[0]+=2
    ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
ABC = list(map(int, input().split()))
ABC.sort()
count = ABC[2] - ABC[1]
other = ABC[2] - ABC[0] - count

if other % 2 == 0:
    count += other / 2
else:
    count += other // 2 + 2

print(int(count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

hq = list(LI())
heapq.heapify(hq)

cnt = 0
while 1:
    if hq[1] == hq[0] and hq[0] == hq[2]:
        break
    else:
        i = heapq.heappop(hq)
        j = heapq.heappop(hq)
        if i == j:
            heapq.heappush(hq, i+1)
            heapq.heappush(hq, i+1)
        else:
            heapq.heappush(hq, i+2)
            heapq.heappush(hq, j)
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())

x = 3 * max(a, b, c) - a - b - c
if x % 2 == 0:
    print(x // 2)
else:
    print(x // 2 + 2)

Submission status: Accepted

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

A = sorted(list(map(int,input().split())))
subA = A[2]-A[1]+A[2]-A[0]
print(subA//2 + subA%2*2)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    L = list(map(int, input().split()))
    L.sort()
    a, b, c = L[0], L[1], L[2]
    ans = c - b
    a += ans
    if (c - a) % 2 != 0:
        ans += 1
        c += 1
    print(ans + (c - a) // 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    X = list(map(int, input().split()))
    X.sort()
    
    ans = X[-1] - X[1]
    if (X[-1]-X[0]-ans) % 2 == 0:
        ans += (X[-1] - X[0]-ans) / 2
    else:
        ans += 1
        ans += (X[-1] - X[0]-ans) / 2  + 1
    print(int(ans))

    return

resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
(*a, ) = map(int, input().split())
a.sort()
b = a[-1] - a[-2]
c = a[1] - a[0]
print(b + -(-c // 2) + c % 2)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

aa=sorted(nl())[::-1]

ans = 0
if(aa[1]-aa[2])%2==1:
  aa[0]+=1
  aa[1]+=1
  ans=1
ans+=(aa[1]-aa[2])//2
ans += aa[0]-aa[1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
nums.sort()
count = nums[2] - nums[1]
nums[0] += nums[2] - nums[1]
if (nums[2]-nums[0])%2 == 0:
  count += (nums[2]-nums[0])//2
else:
  count += (nums[2]-nums[0])//2 + 2
print(count)

Submission status: Accepted

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

if (abc[0]%2==0 and abc[1]%2==0) or (abc[0]%2==1 and abc[1]%2==1):
  ans = 0
  ans += abc[2]-abc[1]
  ans += (abc[1]-abc[0])//2
  print(ans)
else:
  count = 0
  for i in abc:
    if i%2 == 0: count+=1

  for i in range(len(abc)):
    if count == 2:
      if abc[i]%2 == 0: abc[i] += 1
    else:
      if abc[i]%2 == 1: abc[i] += 1
  ans = 1
  ans += abc[2]-abc[1]
  ans += (abc[1]-abc[0])//2
  print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    X = sorted(in_nl())

    A, B, C = X[0], X[1], X[2]

    t = (C - A) + (C - B)
    if t % 2 == 0:
        ans = t // 2
    else:
        C += 1
        A += 1
        ans = ((C - A) + (C - B)) // 2 + 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    nums = list(map(int, input().split()))

    M = max(nums)
    diff = 3 * M - sum(nums)

    print((diff) // 2) if diff%2 == 0 else print((3*M+3-sum(nums))//2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    nums = list(map(int, input().split()))

    # res = 0

    # while len(set(nums)) != 1:
    #     maxIdx = nums.index(max(nums))
    #     minIdx = nums.index(min(nums))

    #     if nums[maxIdx] - nums[minIdx] >= 2:
    #         nums[minIdx] += 2
    #         res += 1
    #     else:
    #         nums[minIdx] += 1
    #         nums[nums.index(min(nums))] += 1

    #         res += 1
    
    # print(res)
    M = max(nums)
    diff = 3 * M - sum(nums)

    print((diff) // 2) if diff%2 == 0 else print((3*M+3-sum(nums))//2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    nums = list(map(int, input().split()))

    res = 0

    while len(set(nums)) != 1:
        maxIdx = nums.index(max(nums))
        minIdx = nums.index(min(nums))

        if nums[maxIdx] - nums[minIdx] >= 2:
            nums[minIdx] += 2
            res += 1
        else:
            nums[minIdx] += 1
            nums[nums.index(min(nums))] += 1

            res += 1
    
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#n=int(input())
a,b,c=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mx=max(a,b,c)
dif=3*mx-(a+b+c)
if dif%2==0:
    ans=dif//2
else:
    ans=dif//2+2

print(ans)

Submission status: Accepted

Solution code:
ABC=list(map(int,input().split()))
ABC.sort()
mn=ABC[0]
md=ABC[1]
mx=ABC[2]
if (mx*2-md-mn)%2==0:
  print((mx*2-md-mn)//2)
else:
  print((mx*2-md-mn+3)//2)

Submission status: Accepted

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

    abc_sort = sorted(abc)
    min_num, mid_num, max_num = abc_sort
    Count = 0
    while(max_num - min_num > 1):
        diff = max_num - min_num
        Count += diff//2
        abc_sort[0] += (diff//2) * 2
        abc_sort = sorted(abc_sort)
        max_num = abc_sort[2]
        min_num = abc_sort[0]

    if (abc_sort[2] - abc_sort[1] == 1):
        Count += 1
    elif (abc_sort[2]-abc_sort[1] == 0 and abc_sort[1] - abc_sort[0] == 1):
        Count += 2
    print(Count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

M = max(nums)
while True:
    ans = 0
    for num in nums:
        ans += M - num
    if ans % 2 == 0:
        break
    M += 1

print(ans // 2)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
a = sorted(a)
i = (a[1] - a[0])//2
a[0] += i*2
i += a[2] - a[1]
if a[0] != a[1]:
  i += 2

print(i)

Submission status: Accepted

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

bc = abc[2] - abc[1]
ab = abc[1] - abc[0]

print(bc + ab//2 if ab%2==0 else bc + ab//2 + 2)

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
S = [A, B, C]
D = max(S)
less = [0, 0, 0]
for i in range(3):
  less[i] = D - S[i]
less = sorted(less)

ans = less[1]
remain = less[2] - less[1]
if remain % 2 == 0:
  ans += remain // 2
else:
  ans += (remain // 2) + 2

print(int(ans))

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ABC = il()
    if ABC[0] == ABC[1] == ABC[2]:
        print(0)
        exit()
    n = 1
    while True:
        if 3 * n >= sum(ABC) and n >= max(ABC) and (3 * n - sum(ABC)) % 2 == 0:
            print((3 * n - sum(ABC)) // 2)
            exit()
        else:
            n += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

diff = C - B
count += diff
A += diff
B += diff

if (B - A) % 2 == 0:
    count += (B - A) // 2
else:
    count += (B - A) // 2 + 2

print(count)

Submission status: Accepted

Solution code:
A,B,C = map(int,input().split())
a = max(A,B,C)
c = min(A,B,C)
b = A+B+C-a-c
ans = a-b
if (b-c)%2==0:
    print(ans + (b-c)//2)
else:
    print(2 + ans + (b-c)//2)

Submission status: Accepted

Solution code:
A,B,C=map(int,input().split())
M=max(A,B,C)
tmp=M*3
Sum=A+B+C
Check=tmp-Sum
if Check%2==0:
  ans=(tmp-Sum)//2
else:
  tmp2=(M+1)*3
  ans=(tmp2-Sum)//2
print(ans)

Submission status: Accepted

Solution code:
s=sorted(map(int,input().split()))
ans=0
while s[0]+2<=s[2]:
    s[0]+=2
    ans+=1
while s[1]+2<=s[2]:
    s[1]+=2
    ans+=1
    
s=sorted(s)
if s[0]==s[2]:
    print(ans)
elif s[0]==s[1]:
    print(ans+1)
else:
    print(ans+2)

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
num = [A, B, C]
cnt =0

for i in range(2):
    multi = (max(num)-min(num))//2
    num[num.index(min(num))] += 2*multi
    cnt += multi

if len([i for i in num if i==max(num)]) ==1:
    cnt += 1
elif len([i for i in num if i==max(num)]) ==2:
    cnt += 2
print(cnt)

Submission status: Accepted

Solution code:
l=list(map(int, input().split()))
l.sort()
base=l[2]-l[1]
if (l[1]-l[0])%2==1:
  base+=1
  l[1]+=1
ans=base+(l[1]-l[0])//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ABC = list(map(int, input().split()))
ABC.sort()
ans = 0

while ABC.count(min(ABC)) != 3:
    if ABC.count(min(ABC)) == 2:
        dif = ABC[2] - ABC[0]
        ABC[0] += dif
        ABC[1] += dif
        ans += dif
    else:
        ABC[0] += 2
        ans += 1
        ABC.sort()

print(ans)

Submission status: Accepted

Solution code:
lst = sorted(list(map(int, input().split())), reverse=True)
diff = lst[0] * 2 - lst[1] - lst[2]
if diff % 2 == 0:
  print(diff // 2)
else:
  print(diff // 2 + 2)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
a.sort()
d = a[2] * 2 - a[0] - a[1]
if d % 2 == 1:
  d += 4
print(d//2)

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
A.sort()
DifA = A[2] - A[1]
DifB = A[2] - A[0]
#print(DifA,DifB)
if DifA % 2 == 0 and DifB % 2 == 0:
    ans = ( DifA + DifB ) // 2
elif DifA % 2 == 1 and DifB % 2 == 1:
    ans = ( DifA + DifB ) // 2
else:
    ans = ( DifA + DifB + 3 ) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n=int(input())
a,b,c=map(int,input().split())
#t=int(input())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mx=max(a,b,c)
dif=3*mx-(a+b+c)
if dif%2==0:
    ans=dif//2
else:
    ans=dif//2+2
print(ans)

Submission status: Accepted

Solution code:
abc = list(map(int, input().split()))
abc.sort()
c = abc[2]
ab = abc[0] + abc[1]
if ab % 2 == 0:
    print((c * 2 - ab) // 2)
else:
    c += 1
    ab += 1
    print((c * 2 - ab) // 2 + 1)

Submission status: Accepted

Solution code:
A=list(map(int,input().split()))
A.sort()
a=A[2]-A[1]
b=A[2]-A[0]
if a%2==0 and b%2==0:
  print(a//2+b//2)
elif a%2==1 and b%2==1:
  print(a//2+b//2+1)
else:
  print(a//2+1+b//2+1)

Submission status: Accepted

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

x = num[2] * 3 - sum(num)

if x%2 == 0:
  ans = int(x/2)
else:
  ans = int(x//2 + 2)

print(ans)

Submission status: Accepted

Solution code:
a,b,c=map(int,sorted(list(map(int,input().split()))))
cnt=0
while True:
  if a==b==c:break
  elif a==b:
    cnt+=c-a
    break
  else:
    a,b,c=map(int,sorted([a+2,b,c]))
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    A, B, C = mi()
    m = max(A, B, C)
    s = sum([A, B, C])
    cnt = 0
    while True:
        if s%3==0 and s>=3*m:
            break
        s += 2
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
M = max(A, B, C)
s = 3 * M - A - B - C
if s % 2 == 0:
  ans = s // 2
else:
  ans = (s + 3) // 2
print(ans)

Submission status: Accepted

Solution code:
def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

ABC = LI()
ABC.sort()
ans = 0

if (ABC[1] - ABC[0]) % 2 == 0:
    ans = (ABC[1] - ABC[0]) // 2 + ABC[2] - ABC[1]
    print(ans)

else:
    ABC[0] += 1
    ABC[2] += 1
    ans = ans = (ABC[1] - ABC[0]) // 2 + ABC[2] - ABC[1] + 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

a,b,c=map(int,input().split())
ans=0
def dfs(x,y,z):
    global ans
    if x==y==z:
        print(ans)
    elif x==y and x<z:
        ans+=1
        dfs(x+1,y+1,z)
    elif y==z and y<x:
        ans+=1
        dfs(x,y+1,z+1)
    elif x==z and x<y:
        ans+=1
        dfs(x+1,y,z+1)
    elif x<y<=z or x<z<=y:
        ans+=1
        dfs(x+2,y,z)
    elif y<x<=z or y<z<=x:
        ans+=1
        dfs(x,y+2,z)
    elif z<x<=y or z<y<=x:
        ans+=1
        dfs(x,y,z+2)
dfs(a,b,c)

Submission status: Accepted

Solution code:
abc = [int(i) for i in input().split()]
abc.sort()
ab, bc = abc[2] - abc[1], abc[2] - abc[0]
cnt = 0
if ab % 2 == 0 and bc % 2 == 0:
    cnt += ab//2
    cnt += bc//2
elif ab % 2 != 0 and bc % 2 != 0:
    cnt += ab//2
    cnt += bc//2 + 1
else:
    cnt += ab//2
    cnt += bc//2 + 2
print(cnt)

Submission status: Accepted

Solution code:
z,y,x = sorted(list(map(int,input().split())))
print((3*x-(x+y+z))//2 if (3*x-(x+y+z))%2==0 else (3*x-(x+y+z))//2+2)

Submission status: Accepted

Solution code:
l = sorted(list(map(int,input().split())))
z = l[0]
y = l[1]
x = l[2]
# x > y > z

ans = 0

if (y-z) % 2 == 0:
    ans += (y-z)//2
    ans += (x-y)
else:
    x += 1
    z += 1
    ans += 1
    ans += (y-z)//2
    ans += (x-y)
print(ans)

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
a.sort()
x=(a[2]-a[1])+(a[1]-a[0])//2+((a[1]-a[0])%2)*2
print(x)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

A,B,C = I()
cnt = 0
for i in range(1000):
    if A != B and B != C and A != C:
        A += 1
        B += 1
        C += 1
        if max(A,B,C) == A:
            A -= 1
        elif max(A,B,C) == B:
            B -= 1
        else:
            C -= 1
        cnt += 1
    if A == B and B == C and A == C:
        print(cnt)
        exit()
    if A == B or B == C or A == C:
        d = abs(max(A,B,C)-min(A,B,C))
        if [A,B,C].count(max(A,B,C)) == 2:
            if d%2 == 0:
                print(cnt+d//2)
                exit()
            else:
                print(cnt+d//2+2)
                exit()
        else:
            print(cnt+d)
            exit()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = lr()
A.sort()
lack = A[2] - A[0] + (A[2] - A[1])
answer = lack // 2
if lack&1:
    answer += 2
print(answer)

Submission status: Accepted

Solution code:
abc = list(map(int,input().split()))
abc.sort()
a = abc[0]
b = abc[1]
c = abc[2]
count = 0
x = c-b
a += x
b += x
count += x
if not (b-a) % 2 == 0:
    b += 1
    c += 1
    count += 1
x = (b-a)//2
a += (b-a)
count += x
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

a, b, c = map(int, input().split())
m = max(a, b, c)

if (3*m-(a+b+c))%2 == 0:
    print((3*m-(a+b+c))//2)
else:
    print((3*(m+1)-(a+b+c))//2)