Problem:


A: チーム分け

問題文

今年の KUPC はチームで参加できることを聞きつけたあなたは、友達に声をかけてチームで出場することにしました。

最終的に、あなたを含めて $4$ 人が集まりました。

個人の強さはレーティングで表され、$4$ 人のレーティングはそれぞれ $a$, $b$, $c$, $d$ です。

あなたたちは $2$ 人ずつの $2$ チームに分かれることにしました。

このとき、チームの強さはそのチームを構成する $2$ 人のレーティングの和で定義されます。
また、チーム間の実力差はそれぞれのチームの強さの差の絶対値で定義されます。

あなたはチーム間の実力差ができるだけ小さくなるようにチーム分けを行いたいです。

うまくチーム分けを行ったときの、チーム間の実力差の最小値を求めてください。

制約

$1 \leq a, b, c, d \leq 2799$

入力はすべて整数である

入力

入力は以下の形式で標準入力から与えられる。

$a$ $b$ $c$ $d$

出力

チーム間の実力差の最小値を整数 $1$ 行で出力せよ。

入力例 1

2 1 3 4

出力例 1

0

$1$ 人目と $3$ 人目、$2$ 人目と $4$ 人目でチームを組むと、チームの強さは共に $5$ となり、実力差は $0$ となります。
明らかにこれが最小です。

入力例 2

64 224 239 1024

出力例 2

625



Sample input:
2 1 3 4


Sample output:
0

Submission status: Accepted

Solution code:
nums = list(int(x) for x in input().split())
nums.sort()
team_a = 0
team_b = 0
team_a += nums[0]
team_a += nums[3]
team_b += nums[1]
team_b += nums[2]
print(abs(team_a -team_b ))

Submission status: Accepted

Solution code:
import itertools
a = list(map(int, input().split()))
b = sum(a)
comb = itertools.combinations(a, 2)
sa = []
for i in comb:
    sa.append(abs(b - 2 *sum(i)))
print(min(sa))

Submission status: Accepted

Solution code:
A = list(map(int,input().split(" ")))
A = sorted(A)
print(abs(A[3]+A[0]-A[1]-A[2]))

Submission status: Accepted

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

print(abs((l[0] + l[3]) - (l[1] + l[2])))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = LIST()
A.sort()
a = A[0] + A[3]
b = A[2] + A[1]
# print(A)
print(abs(a - b))

Submission status: Accepted

Solution code:
num_list = sorted(list(map(int,input().split()))) #標準入力をして小さい順にしリストに入れる
num1 = num_list[0] + num_list[3] #リストの１番大きい数と１番小さい数を足す
num2 = num_list[1] + num_list[2] #リストの2番目と三番目を足す
print(max(num1,num2) - min(num1,num2)) #2つの数の大きい方から小さい方を引く

Submission status: Accepted

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

print abs(a[0]+a[3]-a[1]-a[2])

Submission status: Accepted

Solution code:
a, b, c, d = map(int,input().split())
print(min(abs((a+b)-(c+d)),abs((a+c)-(b+d)),abs((a+d)-(c+b))))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

power = [int(item) for item in input().split()]
power.sort()
print(abs(power[0] + power[3] - power[1] - power[2]))

Submission status: Accepted

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

def f(x,y):
    return abs(x-y)
ans = min(f(a+b,c+d), f(a+c,b+d), f(a+d,b+c))
print(ans)

Submission status: Accepted

Solution code:
from heapq import *
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    aa=LI()
    aa.sort()
    print(abs(aa[0]+aa[3]-aa[2]-aa[1]))

main()

Submission status: Accepted

Solution code:
A = sorted(list(map(int, input().split())))
print(abs(A[0]+A[3]-A[1]-A[2]))

Submission status: Accepted

Solution code:
def main():
    A= list(map( int, input().split()))
    ans = abs(A[0]+A[1]-A[2]-A[3])
    for i in range(4):
        for j in range(4):
            if i == j:
                continue
            now = 0
            for t in range(4):
                if t == i or t == j:
                    now += A[t]
                else:
                    now -= A[t]
            if abs( now) < ans:
                ans = abs(now)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
print(min(abs(sum(a)-(a[0]+a[i])*2) for i in range(1,4)))

Submission status: Accepted

Solution code:
A = sorted(list(map(int, input().split())))
print(abs(A[3]+A[0]-A[1]-A[2]))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = list(map(int, input().split()))
    T = sum(s)
    ans = 100000
    for i in range(4):
        for j in range(i+1,4):
            ans = min(abs(2*(s[i]+s[j])-T), ans)
    print(ans)
    return

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ans=1e100
for x in (b,c,d):
    ans=min(ans,abs(a+x*2-(b+c+d)))
print(ans)

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
ans = tot = sum(l)
for i in range(3):
    for j in range(i+1,4):
        cur = l[i] + l[j]
        c = abs(tot - cur * 2)
        if ans > c:
            ans = c
print(ans)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
x = [a+b-c-d, a+c-b-d, a+d-b-c, b+c-a-d, b+d-a-c, c+d-a-b]
print(min(map(abs, x)))

Submission status: Accepted

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

ans = 10 ** 9
for bit_state in range(1 << 4):
    if bin(bit_state).count("1") == 2:
        tmp1 = 0
        tmp2 = 0
        for i in range(4):
            if bit_state & (1 << i):
                tmp1 += li[i]
            else:
                tmp2 += li[i]
        ans = min(ans, abs(tmp1 - tmp2))
print(ans)

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
tuyoi = max(a,b,c,d) + min(a,c,b,d)
print(abs(a+b+c+d-2*tuyoi))

Submission status: Accepted

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

x=min(A)+max(A)
y=sum(A)-x

print(abs(x-y))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math


def main():
    a,b,c,d = getList()
    ans = min([abs(a+b-c-d), abs(a+c-b-d), abs(a+d-b-c)]
    )
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
a.sort()
print(abs(a[0]+a[3]-a[2]-a[1]))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
A = list(map(int,read().split()))
S = sum(A)
answer = 10 ** 10
for a,b in itertools.combinations(A,2):
    S1 = a + b
    S2 = S - S1
    x = abs(S1 - S2)
    if answer > x:
        answer = x
print(answer)

Submission status: Accepted

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

ans = 1<<30

def go(x, y):
    global ans
    ans = min(ans, abs(x-y))

go(a+b,c+d)
go(a+c,b+d)
go(a+d,b+c)

print(ans)