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:
import math
a=list(map(int,input().split()))
a.sort()
i,j=a[1]-a[0],a[2]-a[1]

if i%2==0: print(i//2+j)
else: print(i//2+j+2)

Submission status: Accepted

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


def solve(A: int, B: int, C: int):
    integers = sorted([A, B, C])
    midMinDiff = integers[1] - integers[0]  # 2つめと3つめの差。2の倍数の時、まず、この2つを揃えられる
    step = 0
    if midMinDiff % 2 == 0:
        step += midMinDiff // 2
        step += integers[2] - integers[1]
    else:
        # この時は、まず1番大きいものと、2番目におおきいものに1を足す
        step += 1
        step += (midMinDiff + 1) // 2
        step += integers[2] - integers[1]
    print(step)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019/04/15 
# AtCoder Beginner Contest 093 - C

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

# Sort(Desc)
abc.sort(reverse=True)

# Init
cnt = 0

wsa = abc[0] * 2 - abc[1] - abc[2]

if wsa > 0 and wsa % 2 == 0:
    cnt -= 1

# 0番目と1番目が等しい: 3番目を2足す
# Else:最大でない二つを1ずつ足す
while abc[0] != abc[1] or abc[0] != abc[2]:
    if abc[0] == abc[1]:
        abc[2] += 2
    else:
        abc[1] += 1
        abc[2] += 1
    cnt += 1

# 2番目が最大: 0と1を1足す
# カウントアップしてBreak
    if max(abc) == abc[2]:
        abc[1] += 1
        abc[0] += 1
        cnt += 1
        break
        
print(cnt)

Submission status: Accepted

Solution code:
t = list(map(int, input().split()))
s = [t[0] % 2 , t[1] % 2 , t[2] % 2]
if s[0] == s[1] and s[0] == s[2]:
    print(int((max(t[0] , t[1] , t[2]) *3 - (t[0] + t[1] + t[2])) / 2))
else:
    if s.count(0) > s.count(1):
        for i in range(3):
            if s[i] == 0:
                t[i] += 1
        print(int((max(t[0] , t[1] , t[2]) *3 - (t[0] + t[1] + t[2])) / 2) + 1)
    else:
        for i in range(3):
            if s[i] == 1:
                t[i] += 1
        print(int((max(t[0] , t[1] , t[2]) *3 - (t[0] + t[1] + t[2])) / 2) + 1)

Submission status: Accepted

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

    max_value = max(inputs)
    max_i = inputs.index(max_value)

    ct = 0
    total = 0
    for input_i in inputs:
        if input_i == max_value:
            continue
            
        total += int((max_value - input_i)/2)
        if (max_value - input_i) % 2:
            ct += 1
        
    
    if ct == 0:
        ans = total
    elif ct == 1:
        ans = total + 2
    elif ct == 2:
        ans= total + 1
    
    print(ans)


main()

Submission status: Accepted

Solution code:
abc=[int(i) for i in input().split()]
abcm=max(abc)
ans=list(map(lambda x: abs(x-abcm),abc))
if sum(ans)%2==0:
    print(sum(ans)//2)
else:
    print(sum(ans)//2+2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
nums = [A, B, C]
nums.sort()

ans = 0
while(nums[0]<nums[2]-1):
    ans += 1
    nums[0]+=2
while(nums[1]<nums[2]-1):
    ans += 1
    nums[1]+=2

if nums[0]==nums[1]==nums[2]:
    ans += 0
elif nums[0] == nums[1]:
    ans += 1
else: ans += 2


print(ans)

Submission status: Accepted

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

gap_1 = lst[2] - lst[1]
gap_2 = lst[2] - lst[0]

if (gap_1 - gap_2) % 2 == 0:
    print(gap_2 + (gap_1 - gap_2) // 2)
else:
    print(gap_2 + (gap_1 - gap_2) // 2 + 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C = map(int,input().split())
max_ABC = max(A,B,C)
dif = [max_ABC - A,max_ABC - B,max_ABC - C]
odd_dif = [i for i in dif if i % 2 == 1]
even_dif = [i for i in dif if i % 2 == 0] 

if len(even_dif) == 3:
	ans = sum(dif)/ 2
elif len(even_dif) == 2:
	ans = (sum(dif) + 3) / 2
else:
	ans = sum(dif) / 2
	
print(int(ans))

Submission status: Accepted

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

D.sort()

Ans = (D[2] - D[0]) // 2
Ans += (D[2] - D[1]) // 2

a = D[2] % 2
b = D[0] % 2 + D[1] % 2

if a == 0:
  if b == 1:
    Ans += 2
  elif b == 2:
    Ans += 1
else:
  if b == 0:
    Ans += 1
  elif b == 1:
    Ans += 2

print(Ans)

Submission status: Accepted

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

counter = 0

li_wk = sorted([a, b, c], reverse=True)

if (li_wk[0] - li_wk[1]) >= 2:
    add_1 = (li_wk[0] - li_wk[1]) // 2
    li_wk[1] += (add_1 * 2)
    counter += add_1

if (li_wk[0] - li_wk[2]) >= 2:
    add_2 = (li_wk[0] - li_wk[2]) // 2
    li_wk[2] += (add_2 * 2)
    counter += add_2

if li_wk.count(li_wk[0]) == 3:
    pass
elif li_wk.count(li_wk[0]) == 2:
    counter += 2
else:
    counter += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cal(x,y):
  if x>=y:
    return x-y
  else:
    a=y-x
    b=a//2
    if a%2!=0:
      b+=2
    return b
A,B,C=map(int,input().split())
ans=10**3

for i in range(51):
  kans=cal(A,i)+cal(B,i)+cal(C,i)
  ans=min(ans,kans)
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
a, b, c = map(int, input().split())

ma = max(a, b, c)

at = (ma - a) // 2 * 2 + a
bt = (ma - b) // 2 * 2 + b
ct = (ma - c) // 2 * 2 + c

ans = 0
ans += (ma - a) // 2
ans += (ma - b) // 2
ans += (ma - c) // 2

dif = abs(ma - at) + abs(ma - bt) + abs(ma - ct)

if dif == 0:
    print(ans)
elif dif == 1:
    print(ans + 2)
else:
    print(ans + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from collections import deque, defaultdict

X = sorted(list(map(int, input().rstrip().split(' '))))
X = [x - X[0] for x in X]

memo = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: -1)))
q = deque([X + [0]])
while True:
    if len(q) == 0:
        break
    values = q.popleft()
    values, depth = values[:3], values[3]
    
    if values[0] == values[1] and values[1] == values[2]:
        print(depth)
        break
    elif memo[values[0]][values[1]][values[2]] != -1:
        continue
    
    gaps = [
        [1, 1, 0],
        [1, 0, 1],
        [0, 1, 1],
        [2, 0, 0],
        [0, 2, 0],
        [0, 0, 2],
    ]
    for gap in gaps:
        new_values = sorted([v + g for v, g in zip(values, gap)])
        new_values = [v - new_values[0] for v in new_values]
        q.append(new_values + [depth + 1])
        
    memo[values[0]][values[1]][values[2]] = 1

Submission status: Accepted

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

M = max(A,B,C)
x= 3*M-(A+B+C)

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

print(ans)

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
s = sorted([A, B, C])
count = s[2] - s[1]
count += (s[1] - s[0] + 1) // 2
count += (s[1] - s[0]) % 2
print(count)

Submission status: Accepted

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

import re

n = input()
n = re.split(" ",n)
for i in range(3):
    n[i] = int(n[i])
n.sort()
a = int(n[2]) - int(n[0])
b = int(n[2]) - int(n[1])

#a,bともに奇数
if(a % 2 == 1 and b % 2 == 1):
    print(int(a/2)+int(b/2) + 1)
#a,bともに偶数
elif(a % 2 == 0 and b % 2 == 0):
    print(int(a/2) + int(b/2))
#それ以外
else:
    print(int(a/2) + int(b/2) + 2)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    c = s.count("0")
    print(2*min(c,len(s)-c))
    return

#B
def B():
    n = I()
    h = LI()
    ans = 0
    m = min(h)
    while m:
        ans += m
        k = max(h)
        for i in range(n):
            if h[i] >= m:
                h[i] -= m
                if h[i]:k = min(k,h[i])
            else:break
        m = k
    print(ans)
    return

#C
def C():
    n,k = LI()
    x = LI()
    ans = float("inf")
    j = bisect.bisect_left(x,0)
    if n == 1:
        print(abs(x[0]))
        quit()
    if j < n:
        if x[j] == 0:
            k -= 1
            x.pop(j)
            n -= 1
    for i in range(n):
        if i < j:
            if abs(i-j) > k:continue
            elif abs(i-j) == k:ans = min(ans,abs(x[i]))
            elif k+i-1 < n:
                ans = min(ans,abs(x[i])+x[k+i-1]-x[i])
        else:
            if abs(i-j)+1 > k:continue
            elif abs(i-j)+1 == k:ans = min(ans,x[i])
            elif i-k+1 >= 0:
                ans = min(ans,abs(x[i])+x[i]-x[i-k+1])

    print(ans)
    return

#D
def D():
    n = I()
    a = LI()
    ans = 0
    p = [1<<i for i in range(100)]
    for i in range(n):
        l = 0
        r = 100
        while r-l > 1:
            m = (l+r)//2
            if a[i]%p[m] == 0:
                l = m
            else:
                r = m
        ans += l
    print(ans)
    return

#E
def E():
    s = LI()
    s.sort()
    ans = s[2]-s[1]
    s[0] += s[2]-s[1]
    s[1] = s[2]
    if s[0]%2 != s[1]%2:
        ans += (s[1]+1-s[0])//2+1
    else:
        ans += (s[1]-s[0])//2
    print(ans)
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    E()

Submission status: Accepted

Solution code:
List = [int(i) for i in input().split()]
count = 0
flag = 0
while(flag == 0):
    List.sort()
    if (List[0]==List[1]==List[2]):
        flag = 1
       
    elif (List[2]-List[0]>0) and (List[2]-List[1]>0):
        List[0]+=1
        List[1]+=1
        count += 1
        
    else:
        List[0]+=2
        count += 1
       

print(count)

Submission status: Accepted

Solution code:
import numpy as np
nums = np.array(list(map(int, input().split())))



count = 0
while(True):
    min_num = nums.min()
    nums_count = (nums == min_num).sum()
    if nums_count == 3:
        break
    indx = np.where(nums == min_num)[0]
    count += 1
    if nums_count == 2:
        nums[indx] += 1
    if nums_count == 1:
        nums[indx] += 2

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
A, B, C = 0, 0, 0


def set_inputs():
    global A, B, C
    A, B, C = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    x, y, z = sorted([A, B, C])
    xd, xm = divmod(x, 2)
    yd, ym = divmod(y, 2)
    zd, zm = divmod(z, 2)
    m = xm + ym + zm
    if m == 0 or m == 3:
        print(zd - xd + zd - yd)
    elif m == 2:
        print(zd - xd + zd - yd + 2)
    else:
        print(zd - xd + zd - yd + 1)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
L = sorted(list(map(int,input().split())),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: Accepted

Solution code:
a,b,c=map(int,input().split())
ma=max(a,b,c)
co=0
l=[a,b,c]
l.sort()
co+=ma-l[1]
if (ma-(l[0]+co))%2==0:
  co+=(ma-(l[0]+co))//2
else:
  co+=(ma-(l[0]+co))//2+2
print(co)

Submission status: Accepted

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

count = 0

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

count += (C - A) / 2
count = int(count)

if (C - A) % 2 != 0 :
    count += 2

print(count)

Submission status: Accepted

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

a, b, c = nums
count = 0

while True:
  if b - a >= 2:
    a += 2
    count += 1
  elif c - b >=1:
    a += 1
    b += 1
    count += 1
  else:
    break
    
if a != b:
  count += 2
print(count)

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
evens = [A%2 == 0, B%2 == 0, C%2 == 0]
even_c = sum(evens)
if even_c == 3 or even_c == 0:
    m = max(A, B, C)
    print(((m-A)+(m-B)+(m-C))//2)
elif even_c == 2:
    a = A+1 if A%2 == 0 else A
    b = B+1 if B%2 == 0 else B
    c = C+1 if C%2 == 0 else C
    m = max(a, b, c)
    print((((m-a)+(m-b)+(m-c))//2)+1)
elif even_c == 1:
    a = A+1 if A%2 != 0 else A
    b = B+1 if B%2 != 0 else B
    c = C+1 if C%2 != 0 else C
    m = max(a, b, c)
    print((((m-a)+(m-b)+(m-c))//2)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
l = [int(_) for _ in stdin.readline().rstrip().split()]
x=max(l)
if 3*x%2 == sum(l)%2:
    print(int((3*x-sum(l))/2))
else:
    print((3*x-sum(l)+3)//2)

Submission status: Accepted

Solution code:
a, b, c = sorted([int(i) for i in input().split()])
if ((c - a) % 2 == 0) & ((c - b) % 2 == 0):
    ans = (2*c - a - b) // 2
elif ((c - a) % 2 == 1) & ((c - b) % 2 == 1):
    ans = (2*c - a - b - 1) // 2 + 1
else:
    ans = (2*c - a - b + 1) // 2 + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
count = max(a, b, c)*3 - a - b - c

if count%2 == 0:
    print(count//2)
else:
    print(count//2+2)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
r_a, r_b, r_c = a % 2, b % 2, c % 2
num = 0
if r_a == r_b and r_b == r_c:
    pass
elif r_a == r_b:
    a += 1
    b += 1
    num += 1
elif r_b == r_c:
    b += 1
    c += 1
    num += 1
else:
    a += 1
    c += 1
    num += 1
a, b, c = tuple(sorted([a, b, c], key=lambda x: -x))
num += (2 * a - b - c) // 2
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

magic = max(a,b,c)*3-a-b-c

if magic % 2 == 0:
    print(int(magic / 2))
else:
    print(int((magic + 1) / 2) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c = [int(i) for i in input().split(" ")]
mn, me, mx = sorted([a, b, c])

c = 0

if (me - mn) % 2 == 0:
    c += (me - mn) // 2
    mn = me
else:
    c += (me - 1 - mn) // 2 + 1
    mn = me
    mx += 1
    
c += mx - me

print(c)

Submission status: Accepted

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

_max = max([A,B,C])

answer = 0
answer += (_max-A)//2 + (_max-B)//2 + (_max-C)//2

_map = {0:0, 1:2, 2:1}
answer += _map[(_max-A)%2 + (_max-B)%2 + (_max-C)%2]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C = sorted(map(int, input().split()))
if (C-B) % 2 and (C-A) % 2 == 0:
    C += 1
    A += 1
    print((C-B)//2+(C-A)//2+1)
elif (C-B) % 2 and (C-A) % 2:
    B += 1
    A += 1
    print((C-B)//2+(C-A)//2+1)
elif (C-B) % 2 == 0 and (C-A) % 2:
    B += 1
    C += 1
    print((C-B)//2+(C-A)//2+1)
else:
    print((C-B)//2+(C-A)//2)

Submission status: Accepted

Solution code:
a,b,c=sorted([int(_) for _ in input().split(" ")])
d=2*c-a-b
if d%2==0:
  print(d//2)
else:
  print((d+3)//2)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


"""
解説を読んで

最終的に行き着く数をXとする
XはA,B,Cの最大値または最大値＋１のどちらかである。
そうすると、3X - (A+B+C)を2で割った時に余り0となるようなXを求めれば良い
それはA,B,Cの最大値またはそれにプラス１した値である。

"""
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(int(result1/2))
else:
    print(int(result2/2))

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

A, B, C = LI()

nums = sorted([A,B,C])
set_nums = list(set([A,B,C]))
result = 0
if len(set_nums) == 1:
    print(0)
elif len(set_nums) == 2:
    # 2種類は一緒
    #前２つが一緒かつはぐれが大きい
    if nums[0] == nums[1]:
        result += nums[2]-nums[1]
        print(result)
        exit()
    elif nums[1] == nums[2]:
        # 後ろ２つが等しく、はぐれが最小
        result += (nums[1] - nums[0])//2
        if (nums[1]-nums[0]) % 2 != 0:
            result += 2
        print(result)
        exit()
else:
    # 全数字が異なる
    result += nums[2]-nums[1]
    nums[0] += nums[2]-nums[1]
    result += (nums[2] - nums[0]) // 2
    if (nums[2] - nums[0]) % 2 != 0:
        result += 2

    print(result)

Submission status: Accepted

Solution code:
def solve(string):
    abc = sorted(map(int, string.split()))
    ans = 0
    oe = sum([_abc % 2 == 0 for _abc in abc])
    if 1 <= oe <= 2:
        for i, _ in enumerate(abc):
            if abc[i] % 2 == oe % 2:
                abc[i] += 1
        ans += 1
    return str(ans + (abc[-1] - abc[0]) // 2 + (abc[-1] - abc[1]) // 2)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lis = [int(x) for x in input().split()]
res = 0

lis.sort()
lis_dif = [x-lis[0] for x in lis]
res += (lis_dif[2]//2)*2 - (lis_dif[1]//2)
lis_bi = [x%2 for x in lis_dif]
res += lis_bi.count(1)

print(res)

Submission status: Accepted

Solution code:
import math
L=list(map(int,input().split()))
temp=0
count=0
for i in L:
    if i%2==0:
        temp+=1
if temp==0 or temp==2:
    #even is even
    for i in range(len(L)):
        if L[i]%2==0:
            L[i]+=1
            count+=1/2
    count//=1
    L.sort()
    count+=(L[1]-L[0])//2
    count+=(L[2]-L[1])
else:
    #even is odd
    for i in range(len(L)):
        if L[i]%2!=0:
            L[i]+=1
            count+=1/2
    count//=1
    L.sort()
    count+=(L[1]-L[0])//2
    count+=(L[2]-L[1])
print(math.ceil(count))

Submission status: Accepted

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

if (A%2) == (B%2) == (C%2):
    x, y, z = sorted([A,B,C])
    diff = z*2 - x - y
    print(diff//2)

else:
    count_odd = 0
    count_even = 0
    for n in [A,B,C]:
        if n%2==1:
            count_odd += 1
        else:
            count_even += 1
    
    if count_odd == 2:
        if A%2 == 1:
            A += 1
        if B%2 == 1:
            B += 1
        if C%2 == 1:
            C += 1        
    else:
        if A%2 == 0:
            A += 1
        if B%2 == 0:
            B += 1
        if C%2 == 0:
            C += 1

    x, y, z = sorted([A,B,C])
    diff = z*2 - x - y
    print(diff//2 + 1)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
# 最終的にa,b,c全てがなるべき値
# 2ずつ増えるから、(3X-(a+b+c)) / 2が答え
X = 0
# Xは必ずM以上になる
M = max(a, max(b, c))
if (3*M)%2 == (a+b+c)%2:
    X = M
else:
    X = M + 1

print(int((3*X - (a+b+c)) / 2))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    s = S()
    a = s.count("a")
    b = s.count("b")
    c = 3-a-b
    if a&b&c:
        print("Yes")
    else:
        print("No")
#B
def B():
    a,b,k = LI()
    ans = []
    for i in range(a,min(a+k,b+1)):
        ans.append(i)
    for i in range(max(a,b-k+1),b+1):
        ans.append(i)
    ans = list(set(ans))
    ans.sort()
    for i in ans:
        print(i)

#C
def C():
    a,b,c = LI()
    ans = 0
    if a%2:
        if b%2:
            if not c%2:
                ans += 1
                a += 1
                b += 1
        else:
            ans += 1
            if not c%2:
                b += 1
                c += 1
            else:
                a += 1
                c += 1
    else:
        if b%2:
            ans += 1
            if not c%2:
                a += 1
                c += 1
            else:
                b += 1
                c += 1
        else:
            if c%2:
                ans += 1
                a += 1
                b += 1
    ans += (3*max(a,b,c)-a-b-c)//2
    print(ans)
#D
def D():
    q = I()
    for i in range(q):
        a,b = LI()
        x = int((a*b)**0.5)
        y = math.ceil((a*b)/x)-1
        ans = x+y-2
        if a==b:
            ans += 1
        print(ans)

#E
def E():
    s = S()
    f = {"N":0,"W":0,"S":0,"E":0}
    for i in s:
        f[i] = 1
    if f["N"]^f["S"]:
        print("No")
    elif f["W"]^f["E"]:
        print("No")
    else:
        print("Yes")
#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
x=list(map(int,input().split()))
x=sorted(x)
s=0
for i in range(3):
    s+=x[-1]-x[i]
if s%2==0:
    print(s//2)
else:
    print((s+3)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L=sorted(list(map(int,input().split())))
print(L[2]-L[1]+(-(-(L[1]-L[0])//2))+(L[1]-L[0])%2)

Submission status: Accepted

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

Submission status: Accepted

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

if (a[2] - a[0]) % 2 == 1 and (a[2] - a[1]) % 2 == 1:
    print(str((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 1)) 
elif (a[2] - a[0]) % 2 != 0 or (a[2] - a[1]) % 2 != 0:
    print(str((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 2))
else:
    print(str((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2))

Submission status: Accepted

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

step = 0

if (3 * max(nums) % 2) != (sum(nums) % 2):
    nums[1] += 1
    nums[2] += 1 
    step += 1

d1 = (nums[2] - nums[1])
d2 = nums[2] - (nums[0] + d1)

if d2 % 2 == 0:
    d2 = d2 // 2
else:
    d2 =  d2 // 2 + 1
step += (d1 + d2)

print(step)

Submission status: Accepted

Solution code:
from math import ceil

l = list(map(int,input().split()))
l.sort()
a = l[0]
b = l[1]
c = l[2]

res = 0
res += c-b
a += res
b = c

res += ceil((c-a)/2)
a += 2*ceil((c-a)/2)

if a == b:
    print(res)
else:
    print(res + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = [int(x) for x in input().split()]
X_bit = [x%2 for x in X]
flag = sum(X_bit)
if flag==0 or flag==3:
    diff = [max(X)-x for x in X]
    print(sum(diff)//2)
elif flag==1:
    X_ = [x+1 if x%2==0 else x for x in X]
    diff = [max(X_)-x for x in X_]
    print(sum(diff)//2+1)
elif flag==2:
    X_ = [x+1 if x%2==1 else x for x in X]
    diff = [max(X_)-x for x in X_]
    print(sum(diff)//2+1)

Submission status: Accepted

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

def solve(a, b):
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        return (b - a + 1) // 2 + 1

ans = 0
if (A[2] - A[0]) % 2 == 1 and (A[2] - A[1]) % 2 == 1:
    A[2] -= 1
    ans += 1
ans += solve(A[0], A[2]) + solve(A[1], A[2])
print(ans)

Submission status: Accepted

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

if abc[0]%2 + abc[1]%2 + abc[2]%2 == 0:
	answer = abc[2] - (abc[0] + abc[1])/2
if abc[0]%2 + abc[1]%2 + abc[2]%2 == 3:
	answer = abc[2] - (abc[0] + abc[1])/2
	
if abc[0]%2 + abc[1]%2 + abc[2]%2 == 1:
	if abc[2]%2 == 1:
		answer = abc[2] - (abc[0] + abc[1]+2)/2 + 1
	if abc[2]%2 == 0:
		answer = (abc[2] + 1) - (abc[0] + abc[1]+1)/2 + 1

if abc[0]%2 + abc[1]%2 + abc[2]%2 == 2:
	if abc[2]%2 == 1:
		answer = (abc[2] + 1) - (abc[0] + abc[1]+1)/2 + 1
	if abc[2]%2 == 0:
		answer = abc[2] - (abc[0] + abc[1]+2)/2 + 1

print(int(answer))

Submission status: Accepted

Solution code:
abc = sorted(list(map(int,input().split())))
pari = [t%2 for t in abc]

ans = 0
for n in [0,1]:
    if pari.count(n) == 2:
        idx = []
        for i in range(3):
            if pari[i] == n: idx.append(i)
        abc[idx[0]] += 1
        abc[idx[1]] += 1
        ans += 1
for i in [0,1]: ans += (abc[2]-abc[i])//2
print(ans)

Submission status: Accepted

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

d1 = Ai[2] - Ai[1]
d2 = Ai[2] - Ai[0]

total = 0
total += (d1 // 2) + (d2 // 2)

if d1 % 2 > 0 and d2 % 2 > 0:
    total += 1
elif d1 % 2 > 0 or d2 % 2 > 0:
    total += 2

print(total)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys


# [x,y,z] is even*3 or odd*3
def solve(x,y,z):
  mx = max([x,y,z])
  return (mx*3-x-y-z)//2


a,b,c = map(int, input().split())
if a%2 == b%2 == c%2:
  print(solve(a,b,c))
elif a%2 == b%2:
  print(solve(a+1,b+1,c)+1)
elif b%2 == c%2:
  print(solve(a,b+1,c+1)+1)
elif a%2 == c%2:
  print(solve(a+1,b,c+1)+1)

Submission status: Accepted

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