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:
def solve(a, b, c):
    # 方針
    # 1. 2番目に大きな数字が1番大きな数字と一致するまで、1×2の操作をする
    # 2. 3番目に大きな数字が1番大きな数字以上になるまで、2×1の操作をする
    # 3. 数字のずれが生じるなら1×2の操作で調整する
    l = sorted((a, b, c))
    d1, d2 = l[2] - l[0], l[2] - l[1]
    return d2 + (d1 - d2 + 1) // 2 + (0 if (d1 - d2) % 2 == 0 else 1)

_a, _b, _c = list(map(int, input().split()))
print(solve(_a, _b, _c))

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
x = max(a,b,c)
# a=b=cにするために足さないといけない数y
y = (x-a) + (x-b) + (x-c)

if y&1:
    # yが奇数なら+3して偶数にする
    y += 3
ans = y//2
print(ans)

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):
    print(S//2)
else:
    print(S//2+2)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    a = [int(x) for x in input().split()]
    a.sort()

    ans = -(-(a[1] - a[0]) // 2)
    ans += a[2] - a[1]
    if (a[1] - a[0]) & 1:
        ans += 1

    print(ans)


    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X = sorted(list(map(int, input().split())))
d1 = X[2]-X[0]
d2 = X[2]-X[1]

ans = d1//2 + d2//2
k = (d1&1) + (d2&1)
if k==2:
    ans += 1
elif k==1:
    ans += 2
print(ans)

Submission status: Accepted

Solution code:
A,B,C=sorted(map(int,input().split()));print(C-B+(B-A+1)//2+((A&1)^(B&1)))

Submission status: Accepted

Solution code:
A,B,C = map(int,input().split())
Top = max(A,B,C)
Bottom = min(A,B,C)
Middle = A+B+C - Top - Bottom
if (Middle - Bottom)%2 != 0:
  Top += 1
  Bottom += 1
  Answer = (Top -Middle) + (Middle - Bottom)//2 +1
else:
  Answer = (Top - Middle) + (Middle - Bottom)//2
print(Answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C = map(int,input().split())
L = sorted([A,B,C])
a,b = L[2]-L[0],L[2]-L[1]
ans = 0
if a%2 == b%2:
    ans = (a+b)//2
else:
    ans = (a+b+3)//2
print(ans)

Submission status: Accepted

Solution code:
# 気分的に降順ソート
x, y, z = sorted([int(i) for i in input().split()])[::-1]
# x, y, z = 6, 3, 2
cnt = 0
if (y % 2 == 0 and z % 2 == 0) or (y % 2 != 0 and z % 2 != 0):
    # 中央が偶数オンリーor奇数オンリーならまず値を揃える
    # +2 を繰り返して揃える
    cnt += (y - z) // 2
else:
    # x と y を増やして（yとzの偶奇を揃えて）からzをyにを追いつかせる
    x += 1
    y += 1
    # +1 は xとyを増やす時、(y - z) // 2 はzに追いつかせる時
    cnt += 1 + (y - z) // 2

print(cnt + (x - y))

Submission status: Accepted

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

s=a[2]*2-a[0]-a[1]
if s&1:
  print((s+3)//2)
else:
  print(s//2)

Submission status: Accepted

Solution code:
import math

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

if ((max([A, B, C]) * 3) - (A + B + C)) % 2 == 0:
  ans = ((max([A, B, C]) * 3) - (A + B + C)) / 2
else:
  X = max([A, B, C]) + 1
  ans = (X * 3 - (A + B + C)) / 2

print(math.floor(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

diff = a[2] - a[1]
if diff > 0:
    ans += diff
    a[1] += diff
    a[0] += diff
if a[0]+1 == a[1] and a[1]+1 == a[2]:
    print(ans+3)
elif a[0]+1 == a[1] and a[1] == a[2]:
    print(ans+2)
elif a[0] == a[1] and a[1]+1 == a[2]:
    print(ans+1)
else:
    print(ans)

Submission status: Accepted

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

A.sort()
ans = 0
while True:
  if A[0]==A[1] and A[0] == A[2]:
    break
  if A[0]==A[1]: # 小さい値を増やす（操作1）
    A[0] += 1
    A[1] += 1
  else:
    A[0] += 2
  A.sort()
  ans += 1

print(ans)

Submission status: Accepted

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

# 偶数、奇数の個数を数える
odds = 0
even = 0
for a in A:
  if a%2 == 0:
    even += 1
  else:
    odds += 1

ans = 0
# 操作1をするため個数が多いものを少ないものに偶奇を合わせる
if even == 2: # 偶数を奇数にする
  ans += 1
  for i in range(3):
    if A[i]%2==0:
      A[i] += 1
      
elif odds == 2:
  ans += 1
  for i in range(3):# 奇数を偶数にする
    if A[i]%2==1:
      A[i] += 1
      

# 最大値に合わせるよう+2を加えて数を合わせる
ma = max(A)
for i in range(3):
  ans += (ma-A[i])//2
print(ans)

Submission status: Accepted

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

ret = 0
while True:
    if A == B and B == C:
        print(ret)
        exit()

    ret += 1
    A, B, C = sorted([A, B, C])
    if B < C:
        A += 1
        B += 1
    elif B == C:
        A += 2

Submission status: Accepted

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

def search(a,b,c):
    lst = [0,0,0]
    if a%2 == b%2:
        lst = [1,1,0]
        if a%2==c%2:
            lst = [1,1,1]
    elif a%2 == c%2:
        lst = [1,0,1]
    else:
        lst = [0,1,1]
    return lst


def make(a,b,c):
    lst = [a,b,c]
    lst.sort()
    lst[0] += 2
    return lst[0],lst[1],lst[2]

if __name__ == "__main__":
    ans = 0
    l = search(a,b,c)
    if sum(l) == 3:
        pass
    else:
        ans += 1
        a += l[0]
        b += l[1]
        c += l[2]
    while a != b or a != c:
        a,b,c = make(a,b,c)
        ans += 1
    print(ans)

Submission status: Accepted

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

memo1 = abc[2]-abc[0]
memo2 = abc[2]-abc[1]

if memo1%2 == memo2%2:
    print((memo1+memo2)//2)
else:
    print(((memo1+memo2)//2)+2)

Submission status: Accepted

Solution code:
from collections import defaultdict

ABC = sorted(map(int, input().split()))

count = 0
D = defaultdict(list)
for i, x in enumerate(ABC):
    D[x % 2].append(i)
for l in D.values():
    if len(l) == 2:
        count += 1
        for i in l:
            ABC[i] += 1
count += (ABC[2] - ABC[0]) // 2 + (ABC[2] - ABC[1]) // 2
print(count)

Submission status: Accepted

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

ret = 0

if not (A%2 == B%2 and B%2 == C%2):
    # どれか一つにイレギュラーがある
    ret += 1
    if A%2 == B%2:
        A += 1
        B += 1
    elif B%2 == C%2:
        B += 1
        C += 1
    else:
        A += 1
        C += 1

max_elem = max(A,B,C)
# print((A,B,C),max_elem, (max_elem-A)//2, (max_elem-B)//2, (max_elem-C)//2)
ret += (max_elem-A)//2 + (max_elem-B)//2 + (max_elem-C)//2

print(ret)

Submission status: Accepted

Solution code:
number = sorted([int(i) for i in input().split()])
cnt = number[2]-number[1]
number[0] += cnt

while number[0] < number[2]:
    number[0] += 2
    cnt += 1
print(cnt if number[0]==number[2] else cnt+1)

Submission status: Accepted

Solution code:
abc = sorted(list(map(int, input().split())), reverse=True)
ans = 0

if abc[1]%2 != 0 and abc[2]%2 == 0:
    ans += 1
    abc[0] += 1
    abc[1] += 1

elif abc[1]%2 == 0 and abc[2]%2 != 0:
    ans += 1
    abc[0] += 1
    abc[2] += 1

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

print(ans)

Submission status: Accepted

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

ans = 3 * max(a, b, c) - (a + b + c)

if ans % 2 == 0:
    print(int(ans / 2))
elif ans % 2 == 1:
    print(int((ans + 3) / 2))

Submission status: Accepted

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

X = A[0] - A[1]
Y = A[0] - A[2]
ans = 0

if (X % 2 == 0) and (Y % 2 == 0):
    ans = X//2 + Y//2
elif (X % 2 == 1) and (Y % 2 == 1):
    ans = X//2 + Y//2 + 1
else:
    ans = X//2 + Y//2 + 2

print(ans)

Submission status: Accepted

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

M = max(X)

if 3*M %2 == sum(X)%2:
    N = (3*M-sum(X))/2

else:
    N = (3*(M+1)-sum(X))/2

print(int(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a=list(map(int,input().split()))
a.sort()
A=a[0]
B=a[1]
C=a[2]
cnt=0
while A<B:
    A+=2
    cnt+=1
if A!=B:
    B+=1
    C+=1
    cnt+=1
while A<C:
    A+=1
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:

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

L = sorted([A, B, C])

cnt1 = L[2] - L[1]
diff = L[2] - (L[0] + cnt1)

if diff % 2 == 0:
  cnt2 = (L[2]-(L[0]+cnt1)) // 2
  print(cnt1 + cnt2)
else:
  cnt2 = (L[2] + 1 - (L[0] + cnt1)) // 2
  print(cnt1+cnt2+1)

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == "__main__":
  l = [int(i) for i in stdin.readline().split(' ')]
  l = sorted(l)
  if l[0]%2 == l[1]%2:
    ex = 0
  else:
    ex = 2
  print((l[-1]*2 - (l[0] + l[1]))//2 + ex)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abc=list(map(int,input().split()))
ans=0
while min(abc)*3!=sum(abc):
    ans+=1
    abc.sort()
    sa=abc[2]-abc[0]
    if sa>=2:
        abc[0]+=2
    elif sa==1:
        abc[0]+=1
        abc[1]+=1
print(ans)

Submission status: Accepted

Solution code:
As = list(map(int, input().split()))
"""
1,1は偶奇の調整
偶奇が一致したら
2であとは行ける
"""
sAs = sorted(As, reverse=True)
amari = [a%2 for a in As]
amari_a  = sorted([(a%2,a) for a in As])
if sum(amari) == 0 or sum(amari) == 3:
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans)
elif sum(amari) == 1:
    # 偶奇合わせ
    a1 = amari_a[0][1] + 1
    b1 = amari_a[1][1] + 1
    c1 = amari_a[2][1] 
    sAs = sorted([a1,b1,c1],reverse=True)
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans+1)
else:
    # 偶奇合わせ
    a1 = amari_a[1][1] + 1
    b1 = amari_a[2][1] + 1
    c1 = amari_a[0][1] 
    sAs = sorted([a1,b1,c1],reverse=True)
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans+1)

Submission status: Accepted

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

l=[a,b,c]
l.sort(reverse=True)
x_max=l[0]
x_mid=l[1]
x_min=l[2]
count=0
count+=l[0]-l[1]
dif=l[0]-(l[2]+count)
if dif%2==0:
    count+=dif//2
else:
    count+=dif//2+2
print(count)

Submission status: Accepted

Solution code:
A,B,C=map(int,input().split())
tmp=sorted([A,B,C])
sa=tmp[2]-tmp[1]
cnt=sa
tmp[1]=tmp[2]
tmp[0]+=sa
sa2=(tmp[1]-tmp[0])//2
cnt+=sa2
tmp[0]+=sa2*2
if tmp[0]!=tmp[1]:
    cnt+=2

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

tmp = max(num) * 3 - sum(num)

for i in range(2):
    num[i] %= 2

if num[0] == num[1]:
    print(math.ceil(tmp/2))
else:
    print(math.ceil(tmp/2)+1)

Submission status: Accepted

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


def solve(A: int, B: int, C: int):
    max_abc= max(A,B,C)

    dif = 3*max_abc-A-B-C
    if dif%2 == 0:
        print(dif//2)
    else:
        print((3*(max_abc+1)-A-B-C)//2)
    
    return


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:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    answer = 0
    max_abc= max(A,B,C)

    answer += (max_abc-A)//2
    A = max_abc-int((max_abc-A)%2 != 0)
    answer += (max_abc-B)//2
    B = max_abc-int((max_abc-B)%2 != 0)
    answer += (max_abc-C)//2
    C = max_abc-int((max_abc-C)%2 != 0)

    if A == B == C:
        print(answer)
        return 

    if [A,B,C].count(max_abc) == 2:
        answer += 2
    else:
        answer += 1

    print(answer)

    
    return


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:
a = list(map(int,input().split()))
a.sort()
b = list(map(lambda x:x%2,a))
ans = 0

if sum(b) in (1,2):
    ans += 1
    for i in range(3):
        if sum(b) == 1:
            a[i] -= b[i]
        else:
            a[i] += b[i]

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

Submission status: Accepted

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

cnt = 0
while not(A[0]==A[1]==A[2]):
  A.sort()
  if A[1]!=A[2]:
    A[0]+=1
    A[1]+=1
  else:
    A[0]+=2
  cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, c = list(map(int, readline().split()))
    dif = max([a, b, c]) * 3 - (a + b + c)
    print(dif // 2 if dif % 2 == 0 else (dif + 3) // 2)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

max_num = max(A,B,C)

flg = 0
if (max_num*3%2 == (A+B+C)%2):
    target = max_num
else:
    target = max_num+1
    flg += 1

ans = (3*target-(A+B+C)) // 2
print(ans)

Submission status: Accepted

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

# まずは1ずつ、次に2を足す、最後に1で調整
ans = 0
ans += L[2] - L[1]
L[0]+=ans
while L[2] > L[0]:
	L[0]+=2
	ans+=1

if L[2] == L[0]:
	print(ans)
else:
	print(ans+1)

Submission status: Accepted

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

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other

    if diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)

Submission status: Accepted

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

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other
    if diff % 2 and diff == 1:
        n_add = (max_set - min_other) // 2 + 2
    elif diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
li = [int(i) for i in input().split()]
li.sort()
dk = li[2] - li[1]
dl = li[2] - li[0]
sum = dk
dl -= dk
while dl > 0 :
    if dl == 1 :
        sum+=2
        dl = 0
    else :
        dl -=2
        sum+=1
print(sum)

Submission status: Accepted

Solution code:
import sys

*a, = map(int, sys.stdin.readline().split())

def main():
    a.sort()
    res = a[2] * 2 - a[0] - a[1]
    return (res + 3) // 2 if res & 1 else res // 2
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

first = abc[2] - abc[0]
second = abc[2] - abc[1]

cnt = 0

if first % 2 == 0 and second % 2 == 0:
    cnt += first//2 + second//2

elif (first % 2 == 1 and second % 2 == 0) or (first % 2 == 0 and second % 2 == 1):
    cnt += first//2 + second//2 + 2

else:
    cnt += first//2 + second//2 + 1

print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 S(): return input()
     
def main():
    arr = LI()
    arr = sorted(arr)
    mod2_arr = [0, 0, 0]
    for i, a in enumerate(arr):
        mod2_arr[i] = a % 2

    if sum(mod2_arr) == 0 or sum(mod2_arr) == 3:
        ans = 0

    elif sum(mod2_arr) == 1:
        for i, a in enumerate(arr):
            if arr[i] % 2 == 0:
                arr[i] += 1
        arr = sorted(arr)
        ans = 1
    else:
        for i, a in enumerate(arr):
            if arr[i] % 2 == 1:
                arr[i] += 1
        arr = sorted(arr)
        ans = 1
    ans += (arr[2] - arr[0]) // 2 + (arr[2] - arr[1]) // 2
    print(ans)
main()

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
cnt=0
m=max(a,b,c)
while a < m-1:
  cnt+=1
  a+=2
while b < m-1:
  cnt+=1
  b+=2
while c < m-1:
  cnt+=1
  c+=2
s=m*3
if s-a-b-c==0:
  print(cnt)
elif s-a-b-c==1:
  print(cnt+2)
else:
  print(cnt+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C=sorted(map(int,input().split()))
Z=C-B
ZZ = (C-(A+Z))/2
ANS=0
if ZZ == (C-(A+Z))//2:
  ANS = Z + (C-(A+Z))//2
else:
  import math
  ANS = Z + math.ceil(ZZ) + 1
print(ANS)

Submission status: Accepted

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

a.sort()

count = 0

#最大値との差
n = a[2]-a[1]
m = a[2]-a[0]

#最大値との差が両方とも奇数の場合、'２つ選んで１つずつ増やす操作'が１回必要
if (n % 2 == 1) and (m % 2 == 1) :
  count += 1

#最大値との差が片方だけ奇数の場合、'２つ選んで１つずつ増やす操作'が２回必要
elif ((a[2]-a[1])%2 == 1) or ((a[2]-a[0])%2 == 1) :
  count += 2

#最大値との差が両方とも偶数の場合、'２つ選んで１つ増やす操作'は不要

#'１つ選んで２つ増やす操作'の回数を足していく
count += (n//2)
count += (m//2)

print(count)

Submission status: Accepted

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

a.sort()

count = 0

if ((a[2]-a[1])%2 == 1) and ((a[2]-a[0])%2 == 1) :
  count += 1
elif ((a[2]-a[1])%2 == 1) or ((a[2]-a[0])%2 == 1) :
  count += 2

count += ((a[2]-a[1])//2)
count += ((a[2]-a[0])//2)

print(count)

Submission status: Accepted

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

if A%2 + B%2 == 1:
    C += 1
print((C*3-sum(abc))//2)

Submission status: Accepted

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

sa=l[2]-l[1]
sb=l[1]-l[0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil
a, b, c = [int(i) for i in sys.stdin.readline().split()]
INF = 10 ** 18
best = INF
for i in range(min(a, b, c), max(a, b, c) + 2):
    score = 0
    for j in [a, b, c]:
        if j < i:
            score += ceil((i - j) / 2)
            score += (i - j) % 2
        else:
            score += j - i
    best = min(best, score)
print(best)

Submission status: Accepted

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

n = max(A, B, C)
t = n * 3 - sum([A, B, C])

if t % 2 == 0:
    ans = t // 2
else:
    ans = (t + 3) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sumNum = sum(nums)
maxNum = max(nums)
count = 0

while True:
    if sumNum % 3 == 0 and sumNum/3 >= maxNum:
        break
    sumNum += 2
    count += 1

print(count)

Submission status: Accepted

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

a = A % 2
b = B % 2
c = C % 2

ans = 0
if (a == 0 and b == 0 and c == 1):
    A += 1
    B += 1
    ans += 1
elif (a == 0 and b == 1 and c == 0):
    A += 1
    C += 1
    ans += 1
elif (a == 1 and b == 0 and c == 0):
    B += 1
    C += 1
    ans += 1
elif (a == 1 and b == 0 and c == 1):
    A += 1
    C += 1
    ans += 1
elif (a == 1 and b == 1 and c == 0):
    A += 1
    B += 1
    ans += 1
elif (a == 0 and b == 1 and c == 1):
    B += 1
    C += 1
    ans += 1

arr = sorted([A,B,C])
l = arr[2]
m = arr[1]
n = arr[0]
ans += (l - m) // 2
ans += (l - n) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

max_n = max(a, b, c)

num = max_n * 3 - a - b - c

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

print(num)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
A = np.array([int(x) for x in input().split()])
A = np.sort(A)
E = A[np.nonzero(A % 2 == 0)]
O = A[np.nonzero(A % 2 == 1)]
e, o = len(E), len(O)
if e == 0 or o == 0:
    a, b = A[-1] - A[0], A[-1] - A[1]
    print(a // 2 + b // 2)
elif e > o:
    A_2 = np.sort(np.concatenate([(E + 1), O]))
    a, b = A_2[-1] - A_2[0], A_2[-1] - A_2[1]
    print(1 + a // 2 + b // 2)
elif o > e:
    A_2 = np.sort(np.concatenate([(O + 1), E]))
    a, b = A_2[-1] - A_2[0], A_2[-1] - A_2[1]
    print(1 + a // 2 + b // 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a = list(map(int,input().split()))
cnt = 0
a.sort()
while len(set(a))>1:
    if a[0]!=a[2] and a[1]!=a[2]:
        a[0]+=1
        a[1]+=1
    elif a[2] - a[1] < 1 and a[1]==a[2]:
        a[0]+=2
    else:
        a[1]+=1
        a[2]+=1
    cnt+=1
    a.sort()
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main()->None:
    # todo:1.入力に同じ値があった時にどうするかの考慮漏れをどうするか
    #      2.while と配列へのアクセスによって時間がかかってる。差が大きくなればなるほどアクセス回数増える。
    l = list(map(int, input().split()))
    l.sort()
    # 最大値l[2]からの差を考える。
    l[0] = l[2] - l[0]
    l[1] = l[2] - l[1]
    l[2] = 0
    
    # l[１]から見ていく
    count = 0
    while True:
        if l[1] - 2 < 0:
            if l[1] == 0:
                break
            else:
                l[1] -= 1
                l[0] -= 1
                count += 1
                break
        l[1] -= 2
        count += 1

    # l[0]について
    while True:
        if l[0] <= 0:
            if l[0] == 0:
                flag = True
                break
            if l[0] < 0:
                count += 1
                break
        l[0] -= 2
        count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
nums=list(map(int, input().split()))
nums.sort()
odds=[nums[i]%2 for i in range(3)]
counter=0
if sum(odds)==2:
  for i in range(3):
    if odds[i]==1:
      nums[i]+=1
      
  counter+=1
  
if sum(odds)==1:
  for i in range(3):
    if odds[i]==0:
      nums[i]+=1
      
  counter+=1
  
counter+=(2*nums[2]-nums[0]-nums[1])//2
print(counter)

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
li=[a,b,c]
li.sort()
x=li[1]-li[0]
y=li[2]-li[1]

if not x%2:
  print((2*y+x)//2)
else:
  print(((2*y+x)//2)+2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
while not a[0] == a[1] == a[2]:
    arr = a.sort()
    cnt += 1
    if a[0] == a[1] :
        a[0] += 1
        a[1] += 1
        continue
    if a[1] == a[2] :
        a[0] += 2
        continue
    else:
        min_id = a.index(min(a))
        a[min_id] += 2
        continue
print(cnt)

Submission status: Accepted

Solution code:
a, b, c = sorted(map(int, input().split()))
cnt = c - b
a += cnt
b += cnt
print(cnt + (b - a) // 2 + (b - a) % 2 * 2)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, c = list(map(int, readline().split()))
    sn = sum([a, b, c])
    mn = max(a, b, c)
    for i in range(mn * 3, 10 ** 10, 3):
        if (i - sn) % 2 == 0:
            print((i - sn) // 2)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

sm = sum(ABC)
mx = max(ABC)

if (mx * 3) % 2 == sm % 2:
    ans = (mx * 3 - sm) // 2
else:
    ans = ((mx + 1) * 3 - sm) // 2

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#093C
import sys
L = list(map(int, sys.stdin.readline().split()))
L.sort()

cnt =0
while True:
    if L[2]-L[0] >=2:
        L[0]+=2
        cnt+=1
        L.sort()
    elif L[2]-L[1] >=2:
        L[1]+=2
        cnt+=1
        L.sort()
    elif L[0] != L[1] or L[0] !=L[2]:
        L[0]+=1
        L[1]+=1
        cnt+=1
        L.sort()
    #print(L)
    if L[0]==L[1] and L[1]==L[2]:
        break

#print(L)
print(cnt)

Submission status: Accepted

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

suma += a[2] - a[1]
print(suma)

Submission status: Accepted

Solution code:
import sys
L=list(map(int,sys.stdin.readline().split()))
cnt=0
while True:
  if L[0]==L[1]==L[2]:
    break
  L.sort()
  if L[2]-L[0]>=2:
    L[0]+=2
  elif L[2]-L[1]>=2:
    L[1]+=2
  elif L[0] !=L[1] or L[1] !=L[2]:
    L[0]+=1
    L[1]+=1
  cnt+=1
  
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abc = list(map(int, input().split()))
abc.sort()
ans = 0
cnt = 0
rest = 0
for i in range(3):
    if abc[i] % 2 == 0:
        cnt += 1
if cnt == 0 or cnt == 3:
    print((abc[2] - abc[1]) // 2 + (abc[2] - abc[0]) // 2)
    exit()
elif cnt == 1:
    rest = 1
for i in range(3):
    if abc[i] % 2 == rest:
        abc[i] += 1
abc.sort()
print((abc[2] - abc[1]) // 2 + (abc[2] - abc[0]) // 2 + 1)

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
m = max(x)
d = [v - m for v in x]
count = 0
while sum(d) != 0:
    ix = [i for i in range(len(x)) if x[i] != m]
    if len(ix) == 2:
        x[ix[0]] += 1
        x[ix[1]] += 1
    if len(ix) == 1:
        x[ix[0]] += 2
    m = max(x)
    d = [v - m for v in x]
    count += 1
print(count)

Submission status: Accepted

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

ans = 0

maxl = max(l)

for i in range(3):
	if l[i]==maxl:
		pass
	else:
		while maxl-2 >= l[i]:
			l[i] = l[i] + 2
			ans = ans + 1

minl = min(l)

k = []
for i in range(3):
	k.append(l[i]-minl)

if sum(k)==0:
	pass
elif sum(k)==2:
	ans = ans + 2
elif sum(k)==1:
	ans = ans + 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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