AtCoder Beginner Contest 103 - Task Scheduling Problem

You have three tasks, all of which need to be completed.
First, you can complete any one task at cost 0.
Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
Here, |x| denotes the absolute value of x.
Find the minimum total cost required to complete all the task.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq A_1, A_2, A_3 \leq 100

-----Input-----
Input is given from Standard Input in the following format:
A_1 A_2 A_3

-----Output-----
Print the minimum total cost required to complete all the task.

-----Sample Input-----
1 6 3

-----Sample Output-----
5

When the tasks are completed in the following order, the total cost will be 5, which is the minimum:
 - Complete the first task at cost 0.
 - Complete the third task at cost 2.
 - Complete the second task at cost 3.

Source: atcoder | Difficulty: EASY


Solutions:
a = sorted([int(i) for i in input().split()])
print(a[2] - a[0])


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


(a, b, c) = map(int, input().split())
list01 = [a, b, c]
list02 = sorted(list01)
print(list02[2] - list02[1] + list02[1] - list02[0])


n = sorted(map(int, input().split()))
print(n[2] - n[0])


tasks = list(map(int, input().split()))
max = tasks[0]
for i in range(1, 3, 1):
	if max < tasks[i]:
		max = tasks[i]
tasks.remove(max)
min = tasks[0]
if tasks[1] < min:
	min = tasks[1]
tasks.remove(min)
ans = max - min
print(ans)


l = [int(i) for i in input().split()]
print(max(l) - min(l))


A = [int(x) for x in input().split()]
print(max(A) - min(A))


(m, _, M) = sorted(map(int, input().split()))
print(M - m)


l = list(sorted(map(int, input().split())))
print(l[2] - l[0])


a = list(map(int, input().split()))
print(abs(max(a) - min(a)))


(a, b, c) = map(int, input().split())
print(max(a, b, c) - min(a, b, c))


A = sorted(list(map(int, input().split())))
print(A[2] - A[0])


def get_input() -> list:
	A = list(map(int, input().split()))
	return A

def main(A: list) -> None:
	ans = max(A) - min(A)
	print(ans)

def __starting_point():
	A = get_input()
	main(A)
__starting_point()


A = map(int, input().split())
A = list(A)
A.sort()
print(A[2] - A[0])


(A1, A2, A3) = map(int, input().split())
a = []
a.append(abs(A2 - A1) + abs(A3 - A2))
a.append(abs(A2 - A3) + abs(A1 - A2))
a.append(abs(A1 - A2) + abs(A3 - A1))
a.append(abs(A1 - A3) + abs(A2 - A1))
a.append(abs(A3 - A1) + abs(A2 - A3))
a.append(abs(A3 - A2) + abs(A1 - A3))
print(min(a))


A = sorted((int(x) for x in input().split()))
print(A[2] - A[0])


(*A,) = map(int, input().split())
print(max(A) - min(A))


a = [int(x) for x in input().split()]
print(max(a) - min(a))


(A1, A2, A3) = sorted(map(int, input().split()))
print(A3 - A1)


a = [int(x) for x in input().split()]
a = sorted(a)
print(a[2] - a[0])


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


c = list(map(int, input().split()))
d = sorted(c)
a = 0
a += d[1] - d[0]
a += d[2] - d[1]
print(a)


(A1, A2, A3) = map(int, input().split())
ans = max(A1, A2, A3) - min(A1, A2, A3)
print(ans)


li = list(map(int, input().split()))
li.sort()
print(li[2] - li[0])


lis = list(map(int, input().split()))
print(max(lis) - min(lis))


n = [int(i) for i in input().split()]
print(max(n) - min(n))


L = sorted(map(int, input().split()))
print(L[2] - L[0])


S = sorted(list(map(int, input().split())))
print(S[2] - S[0])


(a, _, c) = sorted(map(int, input().split()))
print(c - a)


a = sorted(list(map(int, input().split())))
print(a[2] - a[0])


l = sorted(map(int, input().split()))
print(l[-1] - l[0])


a = list(map(int, input().split()))
list_int = list(a)
min_num = min(list_int)
max_num = max(list_int)
mid_num = list_int.pop(1)
minimum_cost = abs(mid_num - min_num) + abs(max_num - mid_num)
print(minimum_cost)


a = list(map(int, input().split()))
x = abs(a[0] - a[1])
y = abs(a[1] - a[2])
z = abs(a[2] - a[0])
m = max(x, y, z)
if m == x:
	print(y + z)
elif m == y:
	print(x + z)
else:
	print(x + y)


(a, b, c) = sorted(map(int, input().split()), reverse=True)
print(a - c)


AS = list(map(int, input().split()))
AS.sort()
print(AS[2] - AS[0])


a = [int(i) for i in input().split(' ')]
a.sort()
print(a[2] - a[0])


(a1, a2, a3) = list(map(int, input().split()))
d1 = abs(a2 - a1)
d2 = abs(a3 - a2)
d3 = abs(a1 - a3)
print(min(d1 + d2, d2 + d3, d3 + d1))


a = list(map(int, input().split()))
ans = 0
a.sort()
for i in range(len(a) - 1):
	ans += a[i + 1] - a[i]
print(ans)


A = [int(i) for i in input().split()]
print(max(A) - min(A))


a = list(map(int, input().split()))
c = max(a[0], a[1], a[2]) - min(a[0], a[1], a[2])
print(c)


a = [int(i) for i in input().split()]
print(max(a) - min(a))


A = list(map(int, input().split()))
A.sort(reverse=True)
print(A[0] - A[2])


l = list(map(int, input().split()))
l.sort()
print(l[2] - l[0])


A = list(map(int, input().rstrip().split()))
print(max(*A) - min(*A))


List = list(map(int, input().split()))
print(max(List) - min(List))


xs = list(map(int, input().split()))
print(max(xs) - min(xs))


print((lambda l: max(l) - min(l))(list(map(int, input().split()))))


a = sorted(list(map(int, input().split())))
print(a[-1] - a[0])


from itertools import permutations
A = list(map(int, input().split()))
per_ls = list(permutations(A))
ans = float('inf')
for (a, b, c) in per_ls:
	tmp = 0 + abs(a - b) + abs(b - c)
	ans = min(ans, tmp)
print(ans)


aa = list(map(int, input().split()))
print(max(aa) - min(aa))


t = list(map(int, input().split()))
print(max(t) - min(t))


t = sorted(list(map(int, input().split())))
print(t[2] - t[0])


a_l = list(map(int, input().split()))
print(max(a_l) - min(a_l))


A = sorted(list(map(int, input().split())))
print(A[-1] - A[0])


A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[0])


c = list(map(int, input().split()))
print(max(c) - min(c))


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	A = LI()
	print(max(A) - min(A))

def __starting_point():
	resolve()
__starting_point()


l = map(int, input().split())
s = sorted(l)
print(s[2] - s[0])


s = list(map(int, input().split()))
print(max(s) - min(s))


A = [int(x) for x in input().split()]
A.sort()
print(A[2] - A[0])


n = list(map(int, input().split()))
a = max(n) - min(n)
print(a)


li = list(map(int, input().split()))
print(max(li) - min(li))


A = sorted(map(int, input().split()))
print(abs(A[0] - A[2]))


(a, b, c) = map(int, input().split())
min_n = min(a, b, c)
max_n = max(a, b, c)
cost_min = max_n - min_n
print(cost_min)


A = [int(a) for a in input().split()]
A.sort()
print(A[2] - A[0])


L = list(map(int, input().split()))
L.sort()
print(L[2] - L[0])


a = [int(_) for _ in input().split(' ')]
print(max(a) - min(a))


x = list(map(int, input().split()))
print(max(x) - min(x))


L = list(map(int, input().split()))
print(max(L) - min(L))


import sys
import math
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inm = lambda : map(int, sys.stdin.readline().split())
inl = lambda : list(inm())
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))
tasks = inl()
tasks.sort()
ans = 0
for i in range(len(tasks) - 1):
	ans += tasks[i + 1] - tasks[i]
print(ans)


t = tuple(map(int, input().split()))
print(max(t) - min(t))


arr = sorted(map(int, input().split()))
print(arr[-1] - arr[0])


n = [int(_) for _ in input().split()]
n.sort()
print(n[2] - n[0])


s = sorted(list(map(int, input().split())))
print(s[2] - s[0])


(A, B, C) = map(int, input().split())
print(max(A, B, C) - min(A, B, C))


a = list(map(int, input().split()))
a.sort()
ans = 0 if len(set(a)) == 1 else a[2] - a[0]
print(ans)


(*l,) = map(int, input().split())
print(max(l) - min(l))


A = sorted([int(i) for i in input().split()])
print(A[2] - A[0])


lst = input().split()
costs = []
for a in [[0, 1], [0, 2], [1, 2]]:
	costs.append(abs(int(lst[a[0]]) - int(lst[a[1]])))
print(sum(costs) - max(costs))


A = list(map(int, input().split()))
ans = max(A) - min(A)
print(ans)


import numpy as np
N_List = np.array(list(map(int, input().split())))
N_List_a = np.sort(N_List)
print(sum(N_List_a[1:] - N_List_a[:-1]))


s = sorted(map(int, input().split()))
print(s[-1] - s[0])


a = sorted(map(int, input().split()))[::-1]
print(a[0] - a[2])


A = [int(t) for t in input().split()]
print(max(A) - min(A))


al = list(map(int, input().split()))
s = []
for i in range(3):
	s.append(abs(al[-i] - al[1 - i]) + abs(al[1 - i] - al[2 - i]))
print(min(s))


lst = sorted(map(int, input().split()))
print(lst[2] - lst[0])


(S, M, L) = sorted(map(int, input().split()))
print(L - S)


(a, b, c) = list(map(int, input().split()))
d = abs(a - b)
e = abs(b - c)
f = abs(c - a)
print(min(d + e, e + f, f + d))


import math
a = list(map(int, input().split()))
q = []
for i in range(3):
	for j in range(3):
		if not i == j:
			q.append(abs(a[i] - a[j]) + abs(a[j] - a[3 - (i + j)]))
print(min(q))


(a, b, c) = map(int, input().split())
res = [abs(a - b), abs(a - c), abs(b - c)]
print(sum(res) - max(res))


a = [int(m) for m in input().split(' ')]
print(max(a) - min(a))


(a1, a2, a3) = sorted(map(int, input().split()))
print(a3 - a1)


(*a,) = map(int, input().split(' '))
print(max(a) - min(a))


lis = [int(i) for i in input().split()]
print(max(lis) - min(lis))


l = sorted(list(map(int, input().split())))
print(max(l) - min(l))


import itertools
a_lst = list(map(int, input().split()))
choice_lst = list(itertools.permutations(a_lst, 3))
cost_lst = []
for i in range(len(choice_lst)):
	cost = 0
	for j in range(3):
		tmp_cost = choice_lst[i][j]
		if j == 0:
			continue
		else:
			cost += abs(choice_lst[i][j] - choice_lst[i][j - 1])
	cost_lst.append(cost)
minimum = min(cost_lst)
print(minimum)


A = [int(i) for i in input().split()]
A.sort()
print(A[2] - A[0])


v = sorted(tuple(map(int, input().split())))
print(v[2] - v[0])


import sys
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans = abs(A[1] - A[0]) + abs(A[2] - A[1])
print(ans)


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


ns = list(map(int, input().split()))
ns.sort()
print(ns[2] - ns[0])


s = list(map(int, input().split()))
s.sort()
print(s[2] - s[0])


def main():
	(*a,) = list(map(int, input().split()))
	print(max(a) - min(a))

def __starting_point():
	main()
__starting_point()


N = list(map(int, input().split()))
print(max(N) - min(N))


x = list(map(int, input().split()))
x = sorted(x)
print(x[2] - x[0])


I = list(map(int, input().split()))
print(max(I) - min(I))


(x, y, z) = sorted(map(int, input().split()))
print(-x + z)


hoge = list(map(int, input().split()))
print(max(hoge) - min(hoge))


t = [int(i) for i in input().split()]
print(max(t) - min(t))


X = sorted(list(map(int, input().split())))
print(X[-1] - X[0])


tsk = list(map(int, input().split()))
print(max(tsk) - min(tsk))


A = list(map(int, input().split()))
A.sort()
ans = A[1] - A[0] + A[2] - A[1]
print(ans)


import sys
import itertools
A = list(map(int, input().split()))
ans = sys.maxsize
for (A_1, A_2, A_3) in itertools.permutations(A, r=3):
	ans = min(ans, abs(A_2 - A_1) + abs(A_3 - A_2))
print(ans)


A = list(map(int, input().split()))
line = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
ans = sum(A)
for i in range(len(line)):
	tmp = 0
	for j in range(1, 3):
		tmp += abs(A[line[i][j]] - A[line[i][j - 1]])
	ans = min(ans, tmp)
print(ans)


an = list(map(int, input().split()))
print(max(an) - min(an))


b = sorted(map(int, input().split()))
print(abs(b[1] - b[0]) + abs(b[2] - b[1]))


l = list(map(int, input().split()))
l.sort()
print(abs(l[1] - l[0]) + abs(l[2] - l[1]))


n = list(map(int, input().split()))
n.sort()
print(n[2] - n[0])


A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(2):
	ans += A[i + 1] - A[i]
print(ans)


S = list(map(int, input().split()))
S.sort()
sum = 0
sum += S[2] - S[0]
print(sum)


li = list(map(int, input().split()))
li.sort()
n = li[1] - li[0] + (li[2] - li[1])
print(n)


A = sorted(list(map(int, input().split())))
print(max(A) - min(A))


A = sorted(map(int, input().split()))
print(A[2] - A[1] + A[1] - A[0])


a = sorted([int(n) for n in input().split()])
print(a[2] - a[0])


li = sorted(list(map(int, input().split())))
print(li[2] - li[0])


li = (a, b, c) = list(map(int, input().split()))
lis = sorted(li)
print(lis[2] - lis[0])


list = input().split(' ')
list_n = [int(s) for s in list]
print(int(max(list_n)) - int(min(list_n)))


def mapt(fn, *args):
	return list(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def main():
	(a, b, c) = Input()
	(x, y, _) = sorted([abs(a - b), abs(b - c), abs(a - c)])
	print(x + y)
main()


A = list(map(int, input().split()))
A = sorted(A)
ret = 0
for i in range(len(A) - 1):
	ret += abs(A[i] - A[i + 1])
print(ret)


v = list(map(int, input().split()))
v.sort()
print(v[2] - v[0])


p = list(map(int, input().split(' ')))
p = sorted(p)
print(p[2] - p[0])


l = list(map(int, input().split()))
l.sort()
print(l[-1] - l[0])


a = [int(i) for i in input().split()]
a_list = []
for i in range(3):
	for j in range(3):
		for k in range(3):
			if i != j and j != k and (k != i):
				a_list.append(abs(a[i] - a[j]) + abs(a[k] - a[i]))
print(min(a_list))


A123 = list(map(int, input().split()))
ans = 1000
for (i, a) in enumerate(A123):
	for (j, b) in enumerate(A123):
		for (k, c) in enumerate(A123):
			if i != j and j != k and (k != i):
				tmp = abs(b - a) + abs(c - b)
				if tmp < ans:
					ans = tmp
print(ans)


A = [int(a) for a in input().split()]
print(max(A) - min(A))


a = map(int, input().split())
a = sorted(a)
print(abs(a[2] - a[0]))


alist = list(map(int, input().split()))
print(max(alist) - min(alist))


al = list(map(int, input().split()))
print(max(al) - min(al))


(a, b, c) = input().split()
a = int(a)
b = int(b)
c = int(c)
ls = [a, b, c]
ls.sort()
print(ls[2] - ls[0])


arr = list(map(int, input().split()))
print(max(arr) - min(arr))


import itertools
a = list(map(int, input().split()))
res = sum(a)
for i in itertools.permutations(a):
	(a1, a2, a3) = i
	tmp = abs(a1 - a2) + abs(a2 - a3)
	res = min(res, tmp)
print(res)


l = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(l) - 1):
	ans += l[i + 1] - l[i]
print(ans)


xs = [int(x) for x in input().split()]
print(max(xs) - min(xs))


(a, b, c) = map(int, input().split())
i = abs(a - b)
j = abs(a - c)
k = abs(b - c)
lst = sorted([i, j, k])
print(lst[0] + lst[1])


import math
(a, b, c) = sorted(map(int, input().split()))
print(c - a)


a = list(map(int, input().split()))
sort_a = sorted(a)
ans = 0
for i in range(len(sort_a) - 1):
	ans += abs(sort_a[i] - sort_a[i + 1])
print(ans)


k = [int(x) for x in input().split()]
print(max(k) - min(k))


a = [int(e) for e in input().split()]
print(max(a) - min(a))


r = sorted(map(int, input().split()))[::-1]
print(r[0] - r[2])


a = [int(x) for x in input().split()]
a1 = abs(a[1] - a[0]) + abs(a[1] - a[2])
a2 = abs(a[2] - a[0]) + abs(a[2] - a[1])
a3 = abs(a[2] - a[0]) + abs(a[1] - a[0])
print(min(a1, a2, a3))


lst = list(map(int, input().split()))
print(max(lst) - min(lst))


a = sorted(list(map(int, input().split())), reverse=True)
res = 0
for i in range(3 - 1):
	res += a[i] - a[i + 1]
print(res)


A = sorted(list(map(int, input().split())))
print(A[-1] - A[-3])


s = sorted(map(int, input().split()))
v = s[2] - s[0]
print(v)


(a, b, c) = sorted([int(n) for n in input().split()])
print(c - a)


(A, B, C) = list(map(int, input().split()))
a = abs(A - B) + abs(B - C)
b = abs(B - C) + abs(C - A)
c = abs(C - A) + abs(A - B)
print(min(a, b, c))


A = list(map(int, input().split()))
A.sort(reverse=True)
cur = A.pop(0)
ans = 0
for a in A:
	ans += cur - a
	cur = a
print(ans)


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():
	A = LI()
	A = sorted(A)
	ans = 0
	ans += A[1] - A[0] + A[2] - A[1]
	print(ans)
main()


print((lambda a: max(a) - min(a))(list(map(int, input().split()))))


As = list(map(int, input().split()))
print(max(As) - min(As))


X = list(map(int, input().split()))
print(max(X) - min(X))


(a, b, c) = map(int, input().split())
ans = abs(b - a) + abs(c - b)
ans2 = abs(c - a) + abs(b - c)
if ans2 < ans:
	ans = ans2
ans2 = abs(a - b) + abs(c - a)
if ans2 < ans:
	ans = ans2
ans2 = abs(c - b) + abs(a - c)
if ans2 < ans:
	ans = ans2
ans2 = abs(a - c) + abs(b - a)
if ans2 < ans:
	ans = ans2
ans2 = abs(b - c) + abs(a - b)
if ans2 < ans:
	ans = ans2
print(ans)


List = [int(i) for i in input().split()]
print(max(List) - min(List))


ls = [int(s) for s in input().split()]
ls.sort()
print(ls[2] - ls[0])


l = sorted([int(i) for i in input().split()])
print(l[2] - l[0])


(a, _, b) = sorted(map(int, input().split()))
print(b - a)