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:
ABC = list(map(int, input().split()))
ans = 0

while ABC[0] != ABC[1] or ABC[1] != ABC[2] or ABC[2] != ABC[0]:
    max_ABC = ABC.index(max(ABC))
    min_ABC = ABC.index(min(ABC))

    if ABC[max_ABC] - ABC[min_ABC] > 1:
        ABC[min_ABC] += 2
        ans += 1
    else:
        ABC[min_ABC] += 1
        for i in range(3):
            if i != min_ABC and i != max_ABC:
                ABC[i] += 1
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    a,b,c=map(int,readline().split())

    li=[a,b,c]
    li.sort()
    x=li[0]
    y=li[1]
    z=li[2]

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

    print(cnt)
if __name__=="__main__":
    main()

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 # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c = readInts()
    d = max(a,b,c)*3 - a - b - c
    if d % 2 == 0:
        print(d//2)
    else:
        print(d//2 + 2)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():

        l = sorted(list(map(int, input().split())))
        even = 0
        for i in range(3):
            if l[i] % 2 == 0:
                even += 1
        cnt = 0
        if even == 0 or even == 3:
            for i in range(3):
                cnt += (l[2]-l[i])//2
            return cnt
        elif even == 1:
            cnt += 1
            for i in range(3):
                if l[i] % 2 == 1:
                    l[i] += 1
            for i in range(3):
                cnt += (max(l)-l[i])//2
            return cnt
        else:
            cnt += 1
            for i in range(3):
                if l[i] % 2 == 0:
                    l[i] += 1
            for i in range(3):
                cnt += (max(l)-l[i])//2
            return cnt
    print(int(main()))


#
resolve()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    L = [int(i) for i in input().split()]
    count = 0
    L.sort()
    addMin = (L[2] - L[0]) // 2  
    addMid = (L[2] - L[1]) // 2
    count = addMin + addMid
    L[0] += addMin * 2
    L[1] += addMid * 2
    if L[0] < L[2] and L[1] < L[2]: print(count + 1)
    elif L[0] == L[1] == L[2]: print(count)
    else: print(count + 2)
    #print(L)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    num = list(map(int, input().split()))
    num.sort()
    answer = 0
    a = num[2] - num[0]
    b = num[2] - num[1]
    if a % 2 == b % 2:
        answer = a // 2 + b // 2 + a % 2
    elif a % 2 != b % 2:
        answer = a // 2 + b // 2 + 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    print(ans)


main()

Submission status: Accepted

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

def resolve():
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    cnt=0
    if l[0]>l[1]:
        cnt+=l[0]-l[1]
        l[2] = l[2] + cnt
        l[1]=l[1]+cnt

    if (l[1]-l[2])%2==0:
        cnt+=(l[1]-l[2])//2
    elif (l[1]-l[2])%2==1:
        cnt+=(l[1]-l[2])//2+2
    print(cnt)

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L = list(map(int, input().split()))
L = sorted(L)
A = L[0]
B = L[1]
C = L[2]
cnt = 0
while A < B-1:
    cnt += 1
    A += 2
if A == B:
    cnt += (C-A)
else:
    cnt += (C-A+1)
print(cnt)

Submission status: Accepted

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

p = [i%2 for i in N]

ans = 0

if sum(p) == 0 or sum(p) == 3:
    m = max(N)
    for i in N:
        ans += (m-i)//2
elif sum(p) == 1:
    for i in range(3):
        if N[i]%2 == 0:
            N[i] += 1
    ans += 1
    m = max(N)
    for j in N:
        ans += (m-j)//2
else:
    for i in range(3):
        if N[i]%2 == 1:
            N[i] += 1
    ans += 1
    m = max(N)
    for j in N:
        ans += (m-j)//2

print(ans)

Submission status: Accepted

Solution code:
abc=list(map(int,input().split()))
abc.sort()
a,b,c = abc[0],abc[1],abc[2]

ans=0

ans+=c-b
c+-(c-b)
a+=(c-b)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    A=list(pin())
    A.sort()
    ans=0
    x,y,z=A
    if (y-x)%2:
        y+=1
        z+=1
        ans+=1
    ans+=(y-x)//2
    x=y
    ans+=z-x
    print(ans)
    
            
#%%submit!
resolve()

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

a,b,c = myinput()
l = [a,b,c]
M = max(l)
g = M*3
sa = g - sum(l)

if sa%2==0:
    ans = sa//2
else:
    g = (M+1)*3
    ans = (g-sum(l))//2
    
print(ans)

Submission status: Accepted

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

a = [int(x) for x in input().split()]
cnt = 0
a.sort()
cnt += a[-1] - a[1]
a[0] += cnt
if (a[-1] - a[0]) % 2 == 1:
    cnt += 1
    a[-1] += 1
cnt += (a[-1] - a[0]) // 2
print(cnt)

Submission status: Accepted

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

  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math
 
a,b,c = map(int,input().split())
li = [a,b,c]
li.sort()
cnt = 0
while li[2] != li[1]:
    li[0] += 1
    li[1] += 1
    cnt+=1
cnt += (li[1]-li[0])//2
if (li[1]-li[0])%2 != 0:
    cnt += 2
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

d1 = (c - a) // 2
ans += d1
a += d1 * 2

d2 = (c - b) // 2
ans += d2
b += d2 * 2

a, b, c = sorted([a, b, c])
if a == b and b < c:
    ans += 1
elif a < b and b == c:
    ans += 2
print(ans)

Submission status: Accepted

Solution code:
def main():
    A = [int(i) for i in input().split()]
    A.sort()
    B = [A[2] - A[0], A[2] - A[1]]
    ans = 0
    if B[0] % 2 == B[1] % 2:
        ans = (B[0]+B[1])//2
    else:
        ans = 0--(B[0]+B[1])//2 + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
abc = [a, b, c]
abc.sort()
sho, chu, dai = abc[0], abc[1], abc[2]

huyasu = dai-chu + dai-sho
if huyasu % 2 == 1:
    huyasu += 3
print(huyasu//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

ABC = list(map(int, input().split()))
ABC.sort()

tmp = ABC[2] - ABC[1]
ans = tmp
ABC[0] += tmp

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

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
while True:
    sorted_list = sorted(sorted_list, reverse=True)
    if sorted_list[0] == sorted_list[1] and sorted_list[1] == sorted_list[2]:
        break

    count += 1
    if sorted_list[0] > sorted_list[1]:
        sorted_list[1] += 1
        sorted_list[2] += 1
    else:
        sorted_list[2] += 2


print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    l=list(map(int,input().split()))
    m=max(l)
    for i in range(3):
        l[i]-=m
    ans=0
    for i in range(3):
        ans+=l[i]//(-2)
        l[i]+=l[i]//(-2)*2
    if sum(l)==-2:
        ans+=1
    elif sum(l)==-1:
        ans+=2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
X = list(map(int, input().split()))
midle = sum(X)-min(X)-max(X)
dif_1 = max(X)-midle
new_min = min(X)+dif_1
dif_2 = max(X)-new_min
if dif_2%2 == 0:
    print(dif_1+dif_2//2)
else:
    print(dif_1+(dif_2//2)+2)

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
ref = max(l)*3 - sum(l) 

if ref%2 == 0:
    ans = ref//2
else:
    ans = ref//2 + 2

print(ans)

Submission status: Accepted

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

ABC.sort()

sum = ABC[2]-ABC[0]+ABC[2]-ABC[1]

result=0

if sum%2==0:
    result = sum/2
else:
    result = sum/2+2

print(int(result))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C = map(int, input().split())
l = [A, B, C]
l = sorted(l)
d1 = l[1] - l[0]
d2 = l[2] - l[1]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
import math

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

Submission status: Accepted

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

d=max(a,b,c)*3
e=a+b+c

if d%2 == e%2:
    print((d-e)//2)
else:
    print((d+3-e)//2)

Submission status: Accepted

Solution code:
abc = list(map(int, input().split()))
is_even = [0] * 3
ans = 0
for i in range(3):
    is_even[i] = True if abc[i] % 2 == 0 else False
if is_even.count(True) == 1:
    for i in range(3):
        if not is_even[i]:
            abc[i] += 1
    ans += 1
if is_even.count(True) == 2:
    for i in range(3):
        if is_even[i]:
            abc[i] += 1
    ans += 1
abc.sort()
ans += (abc[2] - abc[1]) // 2
ans += (abc[2] - abc[0]) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    if [A%2,B%2,C%2] in [[0,0,0],[1,1,1]]:
        pass
    else:
        if [A%2,B%2,C%2] in [[0,1,1],[1,0,0]]:
            B+=1
            C+=1
        elif [A%2,B%2,C%2] in [[1,0,1],[0,1,0]]:
            A+=1
            C+=1
        elif [A%2,B%2,C%2] in [[1,1,0],[0,0,1]]:
            A+=1
            B+=1
        cnt += 1
    arr = sorted([A,B,C])
    cnt += abs(arr[2]-arr[0])//2
    cnt += abs(arr[2]-arr[1])//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

if s[0]%2 == 0:
    if s[1]%2 == 0:
        if s[2]%2 == 1:
            s[0] += 1
            s[1] += 1
            ans += 1
    else:
        if s[2]%2 == 0:
            s[0] += 1
            s[2] += 1
            ans += 1
        else:
            s[1] += 1
            s[2] += 1
            ans += 1
else:
    if s[1]%2 == 0:
        if s[2]%2 == 0:
            s[1] += 1
            s[2] += 1
            ans += 1
        else:
            s[0] += 1
            s[2] += 1
            ans += 1
    else:
        if s[2]%2 == 0:
            s[0] += 1
            s[1] += 1
            ans += 1

ms = max(s)
for i in range(3):
    ans += (ms-s[i])//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    *a, = map(int, input().split())
    f = max(a) % 2 == 0
    g = sum(a) % 2 == 0
    if f == g:
        m = max(a)
    else:
        m = max(a) + 1

    ans = (3 * m - sum(a)) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
l=list(map(int, input().split()))
l.sort()
cnt=0
while l[0]!=l[1] or l[0]!=l[2] or l[1]!=l[2]:
    l.sort()
    #print(l)
    if l[1] == l[2]:
        l[0] += 2
    else:
        l[0] += 1
        l[1] += 1
    cnt+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#問題文はiに対して、+2 or -1の操作をすると置き換えられる
#数字を並べ替えて中心の数字に合わせる

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

num_li = sorted([a,b,c])
gap1 = num_li[1]-num_li[0]
gap2 = num_li[2]-num_li[1]
ans = (gap1+1)//2+gap1%2+gap2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nlist=list(map(int,input().split()))
count=0
while max(nlist)-min(nlist)!=0:
    if max(nlist)-min(nlist)>=2:
        #最小値のindexを取得して、+2する
        minindex=nlist.index(min(nlist))
        nlist[minindex]+=2
        #print("first")
        #print(nlist)
        count+=1
        
    else:
        #665,655のような状態。同種を+1ずつする。
        nlist.sort()
        if nlist[0]==nlist[1]:
            nlist[0]+=1
            nlist[1]+=1
            
        else:
            nlist[1]+=1
            nlist[2]+=1
            
        #print("second")
        #print(nlist)
        count+=1
        
#print(nlist)
print(count)

Submission status: Accepted

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

nums = sorted(nums, reverse=True)
diff_2_3 = nums[1] - nums[2]

if diff_2_3 == 0:
    cnt = 0
else :
    q, r = divmod(diff_2_3, 2)
    cnt = q + r
    if r == 1:
        cnt +=1

cnt += nums[0] - nums[1]

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    a,b,c=map(int,readline().split())

    count=0
    li=[a,b,c]
    li.sort()

    count+=li[2]-li[1]
    li[0]+=li[2]-li[1]
    li[1]+=li[2]-li[1]

    count+=(li[2]-li[0])//2
    li[0]+=((li[2]-li[0])//2)*2

    if li[0]==li[2]:
        print(count)
    else:
        print(count+2)
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
abc = sorted([int(x) for x in input().split()])
eo = [x%2 == 0 for x in abc]
n = eo.count(True)
cnt = 0
if n == 1:
  for i in range(3):
    if not eo[i]:
      abc[i] += 1
  cnt += 1
elif n == 2:
  for i in range(3):
    if eo[i]:
      abc[i] += 1
  cnt += 1
cnt += (abc[2]*2 - abc[0] - abc[1])//2
print(cnt)

Submission status: Accepted

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

m = (a+b+c)
n = max(a, max(b, c))

if m % 2 == n % 2:
  print((n*3-m)//2)
else:
  print(((n+1)*3-m)//2)

Submission status: Accepted

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

Submission status: Accepted

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

if l[2]%2==l[1]%2 and l[2]%2==l[0]%2:
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==0 and l[1]%2==1 and l[0]%2==1:
    l[1]+=1
    l[0]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==1 and l[1]%2==0 and l[0]%2==0:
    l[1]+=1
    l[0]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==0 and l[1]%2==1 and l[0]%2==0:
    l[2]+=1
    l[0]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==1 and l[1]%2==0 and l[0]%2==1:
    l[2]+=1
    l[0]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==1 and l[1]%2==1 and l[0]%2==0:
    l[2]+=1
    l[1]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2

elif l[2]%2==0 and l[1]%2==0 and l[0]%2==1:
    l[2]+=1
    l[1]+=1
    ans+=1
    ans+=(l[2]-l[1])//2 +(l[2]-l[0])//2



print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#print(numbers)
ans = 0
M = max(numbers)
if 3*M%2 == sum(numbers)%2:
    #print(numbers,M)
    ans += (M-numbers[0])
    ans += (M-numbers[1])
    ans += (M-numbers[2])


else:
    #print(numbers,M+1)
    ans += (M+1-numbers[0])
    ans += (M+1-numbers[1])
    ans += (M+1-numbers[2])

print(ans//2)

Submission status: Accepted

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

ans = 0
if a % 2 == b % 2 == c % 2:
    ans += (c - b) // 2 + (c - a) // 2
elif a % 2 == b % 2:
    ans += 1
    a += 1
    b += 1
    ans += (c - b) // 2 + (c - a) // 2
elif a % 2 == c % 2:
    ans += 1
    a += 1
    c += 1
    ans += (c - b) // 2 + (c - a) // 2
elif c % 2 == b % 2:
    ans += 1
    c += 1
    b += 1
    ans += (c - b) // 2 + (c - a) // 2

print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

if a%2==b%2==c%2:
  print((3*max(a,b,c)- a-b-c)//2)
  exit()
elif a%2==b%2:
  a += 1
  b += 1
  print((3*max(a,b,c)- a-b-c)//2 + 1)
  exit()
elif c%2==b%2:
  c += 1
  b += 1
  print((3*max(a,b,c)- a-b-c)//2 + 1)
  exit()
else:
  c += 1
  a += 1
  print((3*max(a,b,c)- a-b-c)//2 + 1)
  exit()

Submission status: Accepted

Solution code:
L=list(map(int,input().split()))
count=0
L=sorted(L)
while(1):
	if L[1]!=L[2]:
		L[0]+=1
		L[1]+=1
		count+=1
	else:
		if L[0]==L[1]:
			print(count)
			exit()
		elif L[1]-L[0]>1:
			L[0]+=2
			count+=1
		elif L[1]-L[0]==1:
			print(count+2)
			exit()

Submission status: Accepted

Solution code:
lst = list(map(int,input().split()))
lst2 = list(map(lambda x: max(lst) - x, lst))
lst2.remove(0)
if lst2[0] % 2 == lst2[1] % 2:
    print(sum(lst2) // 2)
else:
    print((sum(lst2) + 3) // 2)

Submission status: Accepted

Solution code:
lst = list(map(int,input().split()))
lst2 = list(map(lambda x: max(lst) - x, lst))
lst2.remove(0)
if lst2[0] % 2 == 0 and lst2[1] % 2 == 0:
    print(sum(lst2) // 2)
elif lst2[0] % 2 != 0 and lst2[1] % 2 != 0:
    _sum = (lst2[0] - 1) + (lst2[1] - 1)
    print(_sum // 2 + 1)
else:
    print((sum(lst2) + 1) // 2 + 1)

Submission status: Accepted

Solution code:
lst = list(map(int,input().split()))
_max = max(lst)
lst2 = list(map(lambda x: _max - x, lst))
lst2.remove(0)

if lst2[0] % 2 == 0 and lst2[1] % 2 == 0:
    print(sum(lst2) // 2)
elif lst2[0] % 2 != 0 and lst2[1] % 2 != 0:
    _sum = (lst2[0] - 1) + (lst2[1] - 1)
    print(_sum // 2 + 1)
else:
    print((sum(lst2) + 1) // 2 + 1)

Submission status: Accepted

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

a,b,c=map(int,input().split())
i=0
p=max(a,b,c)
while True:
    if p%2!=(a+b+c)%2:
        p+=1
    else:
        break
print((3*p-(a+b+c))//2)

Submission status: Accepted

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

count = 0
abc.sort(reverse=True)

# 偶奇が一致
if abc[0] % 2 == abc[1] % 2 and abc[0] % 2 == abc[2] % 2:
    count += (abc[0] - abc[1]) / 2
    count += (abc[0] - abc[2]) / 2

# 偶奇が両方違う
elif abc[0] % 2 != abc[1] % 2 and abc[0] % 2 != abc[2] % 2:
    abc[1] += 1
    abc[2] += 1
    count += 1

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

# 偶奇が片方違う
else:
    if abc[0] % 2 == abc[1] % 2:
        abc[0] += 1
        abc[1] += 1
        count += 1

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

    else:
        abc[0] += 1
        abc[2] += 1
        count += 1

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

print(int(count))

Submission status: Accepted

Solution code:
# Problem C - Same Integers

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

# initialization
num_count = 0
not_finished = True
ans_list = [A, B, C]

# count
while not_finished:
    if ans_list[0]==ans_list[1] and ans_list[1]==ans_list[2]:
        not_finished=False
        break
    ans_list = sorted(ans_list)
    if len(set(ans_list))==3:
        ans_list[0] += 1
        ans_list[1] += 1
        num_count += 1
    elif ans_list[1]==ans_list[2]:
        ans_list[0] += 2
        num_count += 1
    elif ans_list[0]==ans_list[1]:
        ans_list[0] += 1
        ans_list[1] += 1
        num_count += 1

# output
print(num_count)

Submission status: Accepted

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

Submission status: Accepted

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

al = sorted(al)

a = al[2] - al[1]
b = al[2] - al[0]

k = min(a,b)

if (k - b) % 2 == 1:
    print(k + (b - k) // 2 + 2)
else:
    print(k + (b - k) // 2)

Submission status: Accepted

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

cnt0=(A[2]-A[0])//2
A[0]+=cnt0*2
cnt1=(A[2]-A[1])//2
A[1]+=cnt1*2
A=sorted(A)
#print(A)
if A[1]==A[2] and A[0]==A[2]:
  ans=cnt0+cnt1
elif A[1]==A[2] and A[0]!=A[2]:   
  ans=cnt0+cnt1+2
elif A[2]==A[0]:
  ans=cnt0+cnt1
else:
  ans=cnt0+cnt1+1
print(ans)

Submission status: Accepted

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

D = [[], []]
D[A % 2].append(A)
D[B % 2].append(B)
D[C % 2].append(C)

D.sort(key=lambda a: len(a))

if len(D[-1]) == 2:
    ans += 1
    D[-1][0] += 1
    D[-1][1] += 1

    A, B, C = D[0][0], D[1][0], D[1][1]

mx = max(A, B, C)
ans += sum((mx - a) // 2 for a in (A, B, C))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
n = []
for i in range(len(a)):
  if a[i] % 2 == 0: n.append(i+1)
if len(n) == 3:
  a.sort()
  ans = (a[2] - a[0]) // 2 + (a[2] - a[1]) // 2
elif len(n) == 2:
  N = 3 - sum(n) - 1 #奇数のインデックス
  ans = 0
  if a[N] != max(a):
    while a[N] < max(a):
      a[N] += 2
      ans += 1
  a.sort()
  ans += (a[1] - a[0]) // 2 + a[2] - a[1]
elif len(n) == 1:
  for i in range(len(a)):
    if a[i] % 2 != 0:
      a[i] += 1
  a.sort()
  ans = (a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 1
else:
  a.sort()
  ans = (a[2] - a[0]) // 2 + (a[2] - a[1]) // 2
print(ans)

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
A = [a,b,c]
A.sort()

if (((A[2]-A[1])%2==0) and ((A[2]-A[0])%2==0)) or (((A[2]-A[1])%2==1) and ((A[2]-A[0])%2==1)):
    print(int(A[2]-(A[0]+A[1])/2))
else:
    print(int(A[2]-(A[0]+A[1])/2+3/2))

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
A = [a,b,c]
A.sort()

if (((A[2]-A[1])%2==0) and ((A[2]-A[0])%2==0)) or (((A[2]-A[1])%2==1) and ((A[2]-A[0])%2==1)):
    print(int(A[2]-(A[0]+A[1])/2))
else:
    print(int(A[2]-(A[0]+A[1])/2+3/2))

Submission status: Accepted

Solution code:
a = [int(i) for i in input().split()]
g = 0
k = 0
count = 0
for i in a:
    if i%2==0:
        g += 1
    else:
        k += 1
if g==1:
    count += 1
    for i in range(3):
        if a[i]%2==1:
            a[i] += 1
            
            
elif k==1:
    count += 1
    for i in range(3):
        if a[i]%2==0:
            a[i] += 1
a = sorted(a)[::-1]
count += (a[0]-a[1])//2 + (a[0]-a[2])//2
print(count)

Submission status: Accepted

Solution code:
ABC = list(map(int, input().split()))
ABC.sort(reverse=True)
max_val = ABC[0]
second_max_val = ABC[1]
ans = max_val - second_max_val
min_val = ABC[2] + ans
diff = max_val - min_val
if diff % 2 == 0:
    ans += diff // 2
else:
    ans += diff // 2 + 2
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
A,B,C=map(int, input().split())
L=sorted([A,B,C])
n1=L[0]
n2=L[1]
n3=L[2]

fir=ceil((n2-n1)/2)
if n1+2*fir!=n2:
    sec=1
else:
    sec=0

ans=n3+sec-(n1+2*fir)+fir+sec
print(ans)
#print(fir, sec)
#6+1-(4)