Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.  

Example 

$arr=[1,3,5,7,9]$

The minimum sum is $1+3+5+7=16$ and the maximum sum is $3+5+7+9=24$.  The function prints

16 24

Function Description  

Complete the miniMaxSum function in the editor below.  

miniMaxSum has the following parameter(s):

arr: an array of $5$ integers  

Print   

Print two space-separated integers on one line: the minimum sum and the maximum sum of $4$ of $5$ elements.  

Input Format

A single line of five space-separated integers.

Constraints

$1\leq ar r[i]\leq10^9$  

Output Format

Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)

Sample Input
1 2 3 4 5

Sample Output
10 14

Explanation

The numbers are $1$, $2$, $3$, $4$, and $5$. Calculate the following sums using four of the five integers:

Sum everything except $1$, the sum is $2+3+4+5=14$.
Sum everything except $2$, the sum is $1+3+4+5=13$.
Sum everything except $3$, the sum is $1+2+4+5=12$.
Sum everything except $4$, the sum is $1+2+3+5=11$.
Sum everything except $5$, the sum is $1+2+3+4=10$.

Hints: Beware of integer overflow! Use 64-bit Integer.

Need help to get started? Try the Solve Me First problem

Difficulty: EASY

Solutions:
a = input().strip().split(' ')
for i in range(0, len(a)):
	a[i] = int(a[i])
s = sum(a)
print(str(s - max(a)) + ' ' + str(s - min(a)))


toy = list(map(int, input().split()))
ans = sum(toy)
toy.sort()
print(ans - toy[len(toy) - 1], ans - toy[0])


ar = sorted(map(int, input().split()))
print(sum(ar[:-1]), sum(ar[1:]))


a = [int(i) for i in input().split()]
a.sort()
print(sum(a[:4]), sum(a[1:]))


(a, b, c, d, e) = input().split(' ', 4)
(a, b, c, d, e) = (int(a), int(b), int(c), int(d), int(e))
print(a + b + c + d + e - max(a, b, c, d, e), a + b + c + d + e - min(a, b, c, d, e))


a = list(map(int, input().split()))
a.sort()
print(sum(a[:4]), end=' ')
print(sum(a[1:]))


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


l = list(map(int, input().split()))
l.sort()
print(sum(l[0:4]), end=' ')
print(sum(l[1:5]))


n = [int(x) for x in input().strip().split(' ')]
minsum = sum(n) - max(n)
maxsum = sum(n) - min(n)
print(minsum, maxsum)


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


l = list(map(int, input().split()))
l.sort()
print(sum(l[0:4]), sum(l[1:5]))


numbers = [int(i) for i in input().split()]
sum = 0
for i in numbers:
	sum += i
min_max = []
for i in numbers:
	min_max.append(sum - i)
print(min(min_max), max(min_max))


L = [int(x) for x in input().split()]
L.sort()
print(sum(L[:4]), sum(L[1:5]))


t = input().split()
t = [int(x) for x in t]
t.sort()
print(sum(t) - t[4], sum(t) - t[0])


a = [int(x) for x in input().split()]
a.sort()
print(sum(a[:4]), sum(a[1:]))


arr = [int(x) for x in input().split()]
arr.sort()
med = 0
for i in range(1, 4):
	med += arr[i]
print(med + arr[0], med + arr[4])


nums = input().strip().split()
nums = [int(i) for i in nums]
min = nums[0]
max = nums[0]
sum = nums[0]
for i in range(1, 5):
	if nums[i] < min:
		min = nums[i]
	if nums[i] > max:
		max = nums[i]
	sum += nums[i]
print(sum - max, sum - min)


nums = [int(x) for x in input().strip().split()]
num_sum = sum(nums)
print('%d %d' % (num_sum - max(nums), num_sum - min(nums)))


integers = list(map(int, input().split()))

def sequence_without(lst):
	_sum = sum(lst)
	for (i, el) in enumerate(lst):
		yield (_sum - el)
print(min(list(sequence_without(integers))), max(list(sequence_without(integers))))


ints = list(map(int, input().split()))
total = sum(ints)
max_val = sum(ints[:4])
min_val = sum(ints[:4])
for i in range(len(ints)):
	sum_i = total - ints[i]
	if sum_i > max_val:
		max_val = sum_i
	if sum_i < min_val:
		min_val = sum_i
print(min_val, max_val)


num = list(map(int, input().split()))
num.sort()
s = sum(num)
print(s - num[len(num) - 1], s - num[0])


t = input().split()
a = 0
for i in range(len(t)):
	a = a + int(t[i])
	t[i] = int(t[i])
b = a - min(t)
c = a - max(t)
print(c, end=' ')
print(b)


arr = [int(a) for a in input().split()]
arr.sort()
minm = sum(arr[:len(arr) - 1])
maxm = sum(arr[1:])
print(minm, maxm)


a = []
hepsi = 0
a = input().split()
for i in a:
	hepsi += int(i)
buy = hepsi - int(min(a))
kuc = hepsi - int(max(a))
print(kuc, buy)


l = [int(x) for x in input().split()]
l.sort()
print(sum(l[:4]), sum(l[1:]))


import itertools
s = [int(x) for x in input().strip().split()]
res = []
append = res.append
for subset in itertools.combinations(s, 4):
	append(sum(subset))
print(min(res), end=' ')
print(max(res))


a = [int(i) for i in input().split(' ')]
mn = sum(a) - max(a)
mx = sum(a) - min(a)
print(mn, mx)


nums = [int(t) for t in input().strip().split(' ')]
s = sum(nums)
print('{0} {1}'.format(s - max(nums), s - min(nums)))


arr = list(map(int, input().strip().split()))
arr.sort()
minVal = sum(arr)
maxVal = minVal
minVal -= arr[-1]
maxVal -= arr[0]
print(minVal, maxVal)


import sys
line = [int(x) for x in sys.stdin.readlines()[0].split()]
line.sort()
print(str(line[0] + line[1] + line[2] + line[3]) + ' ' + str(line[4] + line[1] + line[2] + line[3]))


import sys
numbers = list(map(int, sys.stdin.readline().split()))
numbers.sort()
print(sum(numbers[0:4]), sum(numbers[1:]))


lista = sorted(list(map(int, input().split())))
min = sum(lista[:4])
max = sum(lista[len(lista) - 4:])
print(str(min) + ' ' + str(max))


n = list(map(int, input().strip().split(' ')))
print(str(sum(n) - max(n)) + ' ' + str(sum(n) - min(n)))


numbers = list(map(int, input().split()))
min = sum(numbers)
max = numbers[1]
total = sum(numbers)
for i in range(5):
	if total - numbers[i] < min:
		min = total - numbers[i]
	if total - numbers[i] > max:
		max = total - numbers[i]
print(min, max)


str = input()
nums = str.split()
minsum = 0
maxsum = 0
sum = 0
for i in nums:
	sum = sum + int(i)
minsum = sum
maxsum = sum - int(nums[4])
for i in nums:
	if minsum > sum - int(i):
		minsum = sum - int(i)
	if maxsum < sum - int(i):
		maxsum = sum - int(i)
print(minsum, maxsum)


x = input().split()
y = []
for i in x:
	y.append(int(i))
y.sort()
sl = 0
sh = 0
for n in range(0, 4):
	sl += y[n]
for m in range(1, 5):
	sh += y[m]
print(sl, sh)


nums = list(map(int, input().strip().split()))
sm = sum(nums)
(mn, mx) = (10000000000, -10000000000)
for num in nums:
	x = sm - num
	(mn, mx) = (min(mn, x), max(mx, x))
print('{0} {1}'.format(mn, mx))


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


n = [int(i) for i in input().split()]
n.sort()
a = n[0] + n[1] + n[2] + n[3]
b = n[1] + n[2] + n[3] + n[4]
print(a, b)


lis = [int(arr_temp) for arr_temp in input().split(' ')]
lis.sort()
big = 0
small = 0
for i in lis[:4]:
	small += i
for i in lis[-4:]:
	big += i
print(small, big)


entrada = sorted([int(i) for i in input().split()])
suma = sum(entrada)
print('%d %d' % (suma - entrada[-1], suma - entrada[0]))


from itertools import combinations
a = list(map(int, input().strip().split(' ')))
mi = 60000000000
ma = 0
for i in combinations(a, 4):
	a = sum(i)
	ma = max(ma, a)
	mi = min(mi, a)
print(mi, ma)


m = list(map(int, input().split()))
(L, h, k) = (sum(m), max(m), min(m))
print(L - h, L - k)


num_list = [int(x) for x in input().split()]
print(str(sum(num_list) - max(num_list)), str(sum(num_list) - min(num_list)))


a = [int(x) for x in input().strip().split()]
min_i = a.index(min(a))
max_i = a.index(max(a))
sum_wo_min = sum(a[:min_i] + a[min_i + 1:])
sum_wo_max = sum(a[:max_i] + a[max_i + 1:])
print('%d %d' % (sum_wo_max, sum_wo_min))


a = list(map(int, input().split()))
print('%d %d' % (sum(a) - max(a), sum(a) - min(a)))


lista = sorted(list(map(int, input().split())))
minimo = sum(lista[:4])
maximo = sum(lista[len(lista) - 4:])
print(str(minimo) + ' ' + str(maximo))


(a, b, c, d, e) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
minn = min(a + b + c + d, a + b + c + e, a + b + d + e, a + c + d + e, b + c + d + e)
maxx = max(a + b + c + d, a + b + c + e, a + b + d + e, a + c + d + e, b + c + d + e)
print(minn, maxx)


x = list(map(int, input().strip().split()))
l = []
for i in range(5):
	a = 0
	for ii in range(5):
		if ii != i:
			a = a + x[ii]
	l.append(a)
print(min(l), max(l))


line = list(map(int, input().split()))
a = min(line)
b = max(line)
print(sum(line) - b, sum(line) - a)


r = [int(r) for r in input().split(' ')]
s = max(r)
t = min(r)
z = sum(r)
print(z - s, z - t)


lst = str(input())
lst = [int(k) for k in lst.split(' ')]
lst.sort()
print(sum(lst[:4]), sum(lst[-4:]))


line = input()
num_list = line.split()
total_sum = sum([int(x) for x in num_list])
minimum = total_sum - int(num_list[0])
maximum = total_sum - int(num_list[0])
for num in num_list:
	num = int(num)
	if total_sum - num < minimum:
		minimum = total_sum - num
	if total_sum - num > maximum:
		maximum = total_sum - num
print(minimum, maximum)


ar = list(map(int, input().strip().split(' ')))
s = sum(ar)
print(s - max(ar), s - min(ar))


import sys
nums = sorted([int(x) for x in sys.stdin.readline().split()])
print('{} {}'.format(sum(nums) - max(nums), sum(nums) - min(nums)))


l = list(map(int, input().split()))
s = sum(l)
m = min(l)
ma = max(l)
print('{0} {1}'.format(s - ma, s - m))


numbers = [int(x) for x in input().split()]
numbers_sum = sum(numbers)
print(numbers_sum - max(numbers), numbers_sum - min(numbers))


import fileinput

def read_input(filename):
	f = fileinput.input(files=filename)
	nums = [int(x) for x in f.readline().split(' ')]
	return nums

def mini_max_sum(nums):
	nums.sort()
	min_sum = sum(nums[:-1])
	max_sum = sum(nums[1:])
	return [min_sum, max_sum]
nums = read_input('-')
(min_sum, max_sum) = mini_max_sum(nums)
print(min_sum, max_sum)


arr = [int(t) for t in input().split(' ')]
arr.sort()
print(sum(arr[:4]), sum(arr[-4:]))


def swap(arr, x, y):
	mem = arr[x]
	arr[x] = arr[y]
	arr[y] = mem
	return arr

def qsort(ar, start, end):
	if end - start <= 0:
		return ar
	pivot = ar[end]
	ind = start
	for i in range(start, end):
		if ar[i] <= pivot:
			ar = swap(ar, i, ind)
			ind += 1
		else:
			pass
	swap(ar, ind, end)
	ar = qsort(ar, start, ind - 1)
	ar = qsort(ar, ind + 1, end)
	return ar
ar = [int(a) for a in input().strip().split(' ')]
ar = qsort(ar, 0, len(ar) - 1)
print(sum(ar[:4]), sum(ar[1:]))


data = input()
x = data.split()
x = [int(i) for i in x]
(minVal, maxVal) = (10000000000000000000000000000000000000, 0)
for i in range(5):
	y = x[:]
	del y[i]
	val = sum((j for j in y))
	if val < minVal:
		minVal = val
	if val > maxVal:
		maxVal = val
print(minVal, maxVal)


import sys
arr = [int(arr_tmp) for arr_tmp in input().strip().split(' ')]
sum_acu = 0
mi = ma = arr[0]
for item in arr:
	if item > ma:
		ma = item
	if item < mi:
		mi = item
	sum_acu += item
print(sum_acu - ma, sum_acu - mi)


number = list(map(int, input().split(' ')))
min = 'flag'
max = 'flag'
sum = 0
for i in range(len(number)):
	a = number[i]
	sum += a
	if min == 'flag':
		min = a
	elif a < min:
		min = a
	if max == 'flag':
		max = a
	elif a > max:
		max = a
print(sum - max, sum - min)


numbers = list(map(int, input().split()))
for (index, num) in enumerate(numbers):
	if index == 0:
		min = num
		max = num
		sum = 0
	if num < min:
		min = num
	elif num > max:
		max = num
	sum += num
print(sum - max, sum - min)


a = input().split()
s1 = []
for i in range(len(a)):
	al = a[:i]
	ar = a[i + 1:]
	s = sum((int(j) for j in al)) + sum((int(k) for k in ar))
	s1.append(int(s))
print(min(s1), end=' ')
print(max(s1))


x = [int(x) for x in input().split()]
x = sorted(x)
print(sum(x[:4]), sum(x[-4:]))


arr = [int(x) for x in input().split()]
maxi = max(arr)
mini = min(arr)
summ = sum(arr)
maxim = summ - mini
minim = summ - maxi
print(str(minim) + ' ' + str(maxim))


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


def find_smallest():
	result = 0
	for i in range(len(values)):
		if result == 0 or values[i] < result:
			result = values[i]
	return result

def find_total():
	result = 0
	for i in range(len(values)):
		result += values[i]
	return result

def find_biggest():
	result = 0
	for i in range(len(values)):
		if result == 0 or values[i] > result:
			result = values[i]
	return result
values = input().split(' ')
values = [int(x) for x in values]
max = find_total()
print(max - find_biggest(), max - find_smallest())


def minMax(v):
	total = sum(v)
	print(total - max(v), total - min(v))
minMax(list(map(int, input().split(' '))))


l = list(map(int, input().strip().split(' ')))
min1 = 10000000000.0
max1 = -10000000000.0
sum1 = 0
for x in l:
	sum1 = sum(l) - x
	if sum1 < min1:
		min1 = sum1
	if sum1 > max1:
		max1 = sum1
print('{} {}'.format(min1, max1))


def sum(L):
	sum = 0
	for i in range(0, len(L)):
		sum = sum + L[i]
	return sum
answer = []
L = []
L = input().split()
L = list(map(int, L))
x = max(L)
L.remove(max(L))
answer.append(sum(L))
L.append(x)
x = min(L)
L.remove(min(L))
answer.append(sum(L))
print('{0} {1}'.format(answer[0], answer[1]))


lis = list(map(int, input().split()))
lis.sort()
print(lis[0] + lis[1] + lis[2] + lis[3], lis[1] + lis[2] + lis[3] + lis[4])


n = [int(x) for x in input().strip().split()]
print(sum(n) - max(n), end=' ')
print(sum(n) - min(n))


nums = [int(x) for x in input().split()]
suma = 0
for x in nums:
	suma += x
sums_without = [suma - x for x in nums]
print(min(*sums_without), max(*sums_without))


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


arr = [int(x) for x in input().split(' ')]
mini = min(arr)
maxi = max(arr)
ans = []
ans.append(sum(arr) - maxi)
ans.append(sum(arr) - mini)
ans = ' '.join(map(str, ans))
print(ans)


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


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


arr = sorted([int(x) for x in input().split()])
print(sum(arr[0:4]), sum(arr[1:]))


l = input()
l = l.split()
l = [int(i) for i in l]
ll = []
tama = len(l)
for i in range(tama):
	s = 0
	for j in range(tama):
		if i != j:
			s += l[j]
	ll.append(s)
print(min(ll), max(ll))


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


l = [int(a) for a in input().split()]
s = sum(l)
m = max(l)
mi = min(l)
print(s - m, s - mi)


l = [int(i) for i in input().split()]
mi = min(l)
ma = max(l)
s = sum(l)
print(s - ma, s - mi, sep=' ')


toSum = [int(x) for x in input().split(' ')]
minNr = toSum[0]
maxNr = toSum[0]
summ = toSum[0]
for i in range(1, len(toSum)):
	summ += toSum[i]
	if toSum[i] > maxNr:
		maxNr = toSum[i]
		continue
	if toSum[i] < minNr:
		minNr = toSum[i]
print(summ - maxNr, summ - minNr)


import sys
a = sorted(list(map(int, input().split())))
print(sum(a[:4]), sum(a[1:]))


import sys
nums = list(map(int, input().strip().split(' ')))
nums_sum = sum(nums)
print(nums_sum - max(nums), nums_sum - min(nums), sep=' ')


import sys
(a, b, c, d, e) = input().strip().split(' ')
(a, b, c, d, e) = [int(a), int(b), int(c), int(d), int(e)]
x = b + c + d + e
y = a + c + d + e
z = a + b + d + e
w = a + b + c + d
q = a + b + c + e
lista = [x, y, z, w, q]
print(min(lista), max(lista))


import sys
(a, b, c, d, e) = input().strip().split(' ')
nums = [int(a), int(b), int(c), int(d), int(e)]
tot = sum(nums)
print(tot - max(nums), tot - min(nums))


a = sorted([int(x) for x in input('').split(' ')])
print(sum(a[:-1]), sum(a[1:]))


import sys
(a, b, c, d, e) = input().strip().split(' ')
(a, b, c, d, e) = [int(a), int(b), int(c), int(d), int(e)]
abcd = a + b + c + d
abce = a + b + c + e
abde = a + b + d + e
acde = a + c + d + e
bcde = b + c + d + e
print(min(abcd, abce, abde, acde, bcde), max(abcd, abce, abde, acde, bcde))


import sys
xs = [int(x) for x in input().split()]
s = sum(xs)
mi = min(xs)
ma = max(xs)
print(s - ma, s - mi)


import sys
(a, b, c, d, e) = input().strip().split(' ')
(a, b, c, d, e) = [int(a), int(b), int(c), int(d), int(e)]
print(sum([a, b, c, d, e]) - max(a, b, c, d, e), sum([a, b, c, d, e]) - min(a, b, c, d, e))


a = sorted([int(x) for x in input().split()])
print(sum(a[0:4]), sum(a[1:5]))


def minSum(l):
	minS = 0
	for i in l[:-1]:
		minS += i
	return minS

def maxSum(l):
	maxS = 0
	for i in l[1:]:
		maxS += i
	return maxS

def main():
	intList = [int(i) for i in sorted(input().strip().split())]
	print(minSum(intList), maxSum(intList))
main()


import sys
(a, b, c, d, e) = input().strip().split(' ')
(a, b, c, d, e) = [int(a), int(b), int(c), int(d), int(e)]
numbers = [a, b, c, d, e]
numbers.sort()
print(numbers[0] + numbers[1] + numbers[2] + numbers[3], numbers[4] + numbers[1] + numbers[2] + numbers[3])


import sys
(a, b, c, d, e) = input().strip().split(' ')
(a, b, c, d, e) = [int(a), int(b), int(c), int(d), int(e)]
s1 = b + c + d + e
s2 = a + c + d + e
s3 = a + b + d + e
s4 = a + b + c + e
s5 = a + b + c + d
list = [s1, s2, s3, s4, s5]
print(min(list), max(list))


import sys
(a, b, c, d, e) = input().strip().split(' ')
vector = [int(a), int(b), int(c), int(d), int(e)]
vector.sort()
print(sum(vector[0:4]), sum(vector[1:]))


nums = list(map(int, input().strip().split()))
nums.sort()
print(sum(nums[:4]), sum(nums[1:5]))


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