Alice and Bob have decided to play the game "Rock, Paper, Scissors". 

The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied:

  if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser;  if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser;  if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser. 

Alice and Bob decided to play exactly $n$ rounds of the game described above. Alice decided to show rock $a_1$ times, show scissors $a_2$ times and show paper $a_3$ times. Bob decided to show rock $b_1$ times, show scissors $b_2$ times and show paper $b_3$ times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that $a_1 + a_2 + a_3 = n$ and $b_1 + b_2 + b_3 = n$.

Your task is to find two numbers:

  the minimum number of round Alice can win;  the maximum number of rounds Alice can win. 


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 10^{9}$) — the number of rounds.

The second line of the input contains three integers $a_1, a_2, a_3$ ($0 \le a_i \le n$) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that $a_1 + a_2 + a_3 = n$.

The third line of the input contains three integers $b_1, b_2, b_3$ ($0 \le b_j \le n$) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that $b_1 + b_2 + b_3 = n$.


-----Output-----

Print two integers: the minimum and the maximum number of rounds Alice can win.


-----Examples-----
Input
2
0 1 1
1 1 0

Output
0 1

Input
15
5 5 5
5 5 5

Output
0 15

Input
3
0 0 3
3 0 0

Output
3 3

Input
686
479 178 29
11 145 530

Output
22 334

Input
319
10 53 256
182 103 34

Output
119 226



-----Note-----

In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.

In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.

In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway.

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Greedy algorithms

Complete search

Flows and cuts

Mathematics
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
def maxwin(a1, a2, a3, b1, b2, b3):
	return min(a1, b2) + min(a2, b3) + min(a3, b1)

def minwin(a1, a2, a3, b1, b2, b3):
	return max(0, b1 - a1 - a2) + max(0, b3 - a1 - a3) + max(0, b2 - a2 - a3)
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
print(minwin(a1, a2, a3, b1, b2, b3), maxwin(a1, a2, a3, b1, b2, b3))


n = int(input())
alice = tuple(map(int, input().split()))
bob = tuple(map(int, input().split()))

def minimize(order):
	(ag, ac, ap) = alice
	(bg, bc, bp) = bob
	for j in order:
		if j == 0:
			d = min(ag, bp)
			ag -= d
			bp -= d
		elif j == 1:
			d = min(ap, bc)
			ap -= d
			bc -= d
		elif j == 2:
			d = min(ac, bg)
			ac -= d
			bg -= d
		elif j == 3:
			d = min(ap, bp)
			ap -= d
			bp -= d
		elif j == 4:
			d = min(ag, bg)
			ag -= d
			bg -= d
		else:
			d = min(ac, bc)
			ac -= d
			bc -= d
	return ag + ac + ap

def maximize(f):
	ans = 0
	(ag, ac, ap) = bob
	(bg, bc, bp) = alice
	d = min(ag, bp)
	ag -= d
	bp -= d
	ans += d
	d = min(ap, bc)
	ap -= d
	bc -= d
	ans += d
	d = min(ac, bg)
	ac -= d
	bg -= d
	ans += d
	return ans
ans = n
from itertools import permutations as pe
for i in pe(list(range(6)), r=None):
	ans = min(ans, minimize(i))
print(ans, maximize(1))


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = 998244353
INF = float('inf')

def cal(p, q, i):
	if i == 2:
		p1 = p[:]
		q1 = q[:]
		p1[i] = max(p1[i] - q1[i - 1], 0)
		q1[i - 1] = max(q1[i - 1] - p1[i], 0)
		p1[i] = max(p1[i] - q1[i], 0)
		q1[i] = max(q1[i] - p1[i], 0)
		p[i] = max(p[i] - q[i], 0)
		q[i] = max(q[i] - p[i], 0)
		p[i] = max(p[i] - q[i - 1], 0)
		q[i - 1] = max(q[i - 1] - p[i], 0)
		return min(sum(p1), sum(p))
	p1 = p[:]
	q1 = q[:]
	p1[i] = max(p1[i] - q1[i - 1], 0)
	q1[i - 1] = max(q1[i - 1] - p1[i], 0)
	p1[i] = max(p1[i] - q1[i], 0)
	q1[i] = max(q1[i] - p1[i], 0)
	ans = cal(p1, q1, i + 1)
	p[i] = max(p[i] - q[i], 0)
	q[i] = max(q[i] - p[i], 0)
	p[i] = max(p[i] - q[i - 1], 0)
	q[i - 1] = max(q[i - 1] - p[i], 0)
	return min(ans, cal(p, q, i + 1))
n = int(data())
a = mdata()
b = mdata()
p = a[:]
q = b[:]
s = 0
for i in range(3):
	s += min(a[i], b[(i + 1) % 3])
print(cal(p, q, 0), s)


import math
from datetime import date
import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(mn, mx) = (0, 0)
	for i in range(3):
		mx += min(a[i], b[(i + 1) % 3])
	for i in range(3):
		mn += max(0, a[i] + b[(i + 1) % 3] - n)
	print(str(mn) + ' ' + str(mx))
main()


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [[0, 0], [1, 1], [2, 2], [0, 2], [1, 0], [2, 1]]
p = list(permutations(c))
m = 10 ** 9
for x in p:
	(ac, bc) = (a.copy(), b.copy())
	for (i, j) in x:
		val = min(ac[i], bc[j])
		ac[i] -= val
		bc[j] -= val
	ans = min(ac[0], bc[1]) + min(ac[1], bc[2]) + min(ac[2], bc[0])
	m = min(m, ans)
ans = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(m, ans)


from itertools import *

def min_wins(A, B):
	not_win = [(0, 2), (0, 0), (1, 0), (1, 1), (2, 1), (2, 2)]
	ans = float('inf')
	for p in permutations(range(6)):
		(a, b) = (A[:], B[:])
		li = [not_win[i] for i in p]
		for (i, j) in li:
			mn = min(a[i], b[j])
			a[i] -= mn
			b[j] -= mn
		cur = max_wins(a, b)
		ans = min(cur, ans)
	return ans

def max_wins(A, B):
	mx = 0
	for i in range(3):
		mn = min(A[i], B[(i + 1) % 3])
		mx += mn
	return mx

def solve(A, B, n):
	mxa = max_wins(A, B)
	mna = min_wins(A, B)
	print(mna, mxa)
n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
solve(alice, bob, n)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(maxx, minn) = (0, 0)
if a[0] > b[1]:
	maxx += a[0] - b[1]
if a[1] > b[2]:
	maxx += a[1] - b[2]
if a[2] > b[0]:
	maxx += a[2] - b[0]
if a[0] > b[0] + b[2]:
	minn += a[0] - b[0] - b[2]
if a[1] > b[1] + b[0]:
	minn += a[1] - b[1] - b[0]
if a[2] > b[1] + b[2]:
	minn += a[2] - b[1] - b[2]
print(minn, n - maxx)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from itertools import permutations
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans2 = sum((min(a[i], b[(i + 1) % 3]) for i in range(3)))
	ans1 = 10 ** 9
	for p in permutations([0, 1, 2]):
		a_ = a[:]
		b_ = b[:]
		for i in p:
			x = min(a_[i], b_[i])
			a_[i] -= x
			b_[i] -= x
			x = min(a_[i], b_[(i - 1) % 3])
			a_[i] -= x
			b_[(i - 1) % 3] -= x
		ans1 = min(ans1, sum(a_))
	print(ans1, ans2)
main()


from itertools import permutations
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
awin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
amin = n
pairs = [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 0)]
for seq in permutations(pairs):
	aa = a.copy()
	bb = b.copy()
	b_win = 0
	for pair in seq:
		ai = pair[1]
		bi = pair[0]
		delta = min(aa[ai], bb[bi])
		aa[ai] -= delta
		bb[bi] -= delta
		b_win += delta
	amin = min(amin, n - b_win)
print(amin, awin)


import sys
arg = []
for line in sys.stdin:
	arg.append(line)
n = int(arg[0])
a = [int(i) for i in arg[1].split(' ')]
b = [int(i) for i in arg[2].split(' ')]
nbAliceWinMax = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
nbAliceWinMin = max(0, b[0] - a[0] - a[1], b[1] - a[1] - a[2], b[2] - a[2] - a[0])
print(nbAliceWinMin, nbAliceWinMax)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
maximum = min(a1, b2) + min(a2, b3) + min(a3, b1)
minimum = min(a1, b1 + b3) + min(a2, b2 + b1) + min(a3, b3 + b2)
print(n - minimum, maximum)


n = int(input(''))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mxsol = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mnsol = max(a[0] - b[0] - b[2], a[1] - b[1] - b[0], a[2] - b[2] - b[1], 0)
print(mnsol, mxsol)


def calculate(rr1, ss1, pp1, rr2, ss2, pp2):
	w1 = 0
	if rr1 >= ss2:
		w1 += ss2
		rr1 -= ss2
		ss2 = 0
	elif rr1 < ss2:
		w1 += rr1
		ss2 -= rr1
		rr1 = 0
	if ss1 >= pp2:
		w1 += pp2
		ss1 -= pp2
		pp2 = 0
	elif ss1 < pp2:
		w1 += ss1
		pp2 -= ss1
		ss1 = 0
	if pp1 >= rr2:
		w1 += rr2
		pp1 -= rr2
		rr2 = 0
	elif pp1 < rr2:
		w1 += pp1
		rr2 -= pp1
		pp1 = 0
	return w1
t = int(input())
(r1, s1, p1) = map(int, input().split())
(r2, s2, p2) = map(int, input().split())
w1 = calculate(r1, s1, p1, r2, s2, p2)
wt1 = p2 - p1 - r1
wt2 = s2 - s1 - p1
wt3 = r2 - r1 - s1
if max(wt1, wt2, wt3) < 0:
	m = 0
else:
	m = max(wt1, wt2, wt3)
print(m, w1)


n = int(input())
(a, b, c) = map(int, input().split())
(x, y, z) = map(int, input().split())
maxwin = min(a, y) + min(b, z) + min(c, x)
minwin = max(a - x - z, b - x - y, c - y - z, 0)
print(minwin, maxwin)


import sys
from itertools import permutations
from copy import deepcopy

def solve(input_path=None):
	if input_path is None:
		f = sys.stdin
	else:
		f = open(input_path, 'r')
	n = int(f.readline())
	(paper1, rock1, scissor1) = map(int, f.readline().split())
	(paper2, rock2, scissor2) = map(int, f.readline().split())
	min_win = n - (min(paper1, paper2 + scissor2) + min(rock1, rock2 + paper2) + min(scissor1, scissor2 + rock2))
	max_win = min(paper1, rock2) + min(rock1, scissor2) + min(scissor1, paper2)
	return [f'{min_win} {max_win}']

def main():
	for line in solve():
		print(f'{line}')
main()


n = int(input())
(r, s, p) = map(int, input().split())
(a, b, c) = map(int, input().split())
maxi = min(r, b) + min(s, c) + min(a, p)
mini = max(0, r + b - n) + max(0, s + c - n) + max(0, p + a - n)
print(mini, maxi)


max = int(input())
max = 0
min = 0
a = [int(j) for j in input().split()]
a.append(a[0])
b = [int(j) for j in input().split()]
b.append(b[0])
for i in range(3):
	if a[i] <= b[i + 1]:
		max += a[i]
	else:
		max += b[i + 1]
	if a[i + 1] - b[i] - b[i + 1] > 0:
		min += a[i + 1] - b[i] - b[i + 1]
print(min, max)


n = int(input())
l1 = [int(i) for i in input().split()]
l2 = [int(i) for i in input().split()]
m1 = min(l1[0], l2[1])
m2 = min(l1[1], l2[2])
m3 = min(l1[2], l2[0])
m = m1 + m2 + m3
a1 = min(l2[0], l1[1])
a2 = min(l2[1], l1[2])
a3 = min(l2[2], l1[0])
l2[0] = l2[0] - a1
l2[1] = l2[1] - a2
l2[2] = l2[2] - a3
a = a1 + a2 + a3 + min(l1[0], l2[0]) + min(l1[1], l2[1]) + min(l1[2], l2[2])
print(n - a, m)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
maxx = min(a1, b2) + min(a2, b3) + min(a3, b1)
minn = 0
if a1 < b1 + b3:
	if a2 < b2 + b1:
		if a3 < b3 + b2:
			minn = a1 + a2 + a3
		else:
			minn = b3 + b2 + a1 + a2
	else:
		minn = b2 + b1 + a1 + a3
else:
	minn = b1 + b3 + a2 + a3
print(n - minn, maxx)


from itertools import permutations

def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
n = read_int()
a = list(read_ints())
b = list(read_ints())
hi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
lo = n
prs = [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 0)]
for seq in permutations(prs):
	a1 = a.copy()
	b1 = b.copy()
	no_win = 0
	for pr in seq:
		ai = pr[1]
		bi = pr[0]
		delta = min(a1[ai], b1[bi])
		no_win += delta
		a1[ai] -= delta
		b1[bi] -= delta
	lo = min(lo, n - no_win)
print(lo, hi)


n = int(input())
(ra, sa, pa) = [int(s) for s in input().split(' ')]
(rb, sb, pb) = [int(s) for s in input().split(' ')]
mx = min(pa, rb) + min(ra, sb) + min(sa, pb)
mn = min(pa, n - rb) + min(ra, n - sb) + min(sa, n - pb)
print(n - mn, mx)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def win(x):
	ans = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	return ans >= x

def lose(x):
	ans = max(0, a[0] + b[1] - n, a[1] + b[2] - n, a[2] + b[0] - n)
	return ans <= x
n = Int()
a = array()
b = array()
low = 0
high = n
(ans1, ans2) = (0, n)
while low <= high:
	mid = low + (high - low) // 2
	if win(mid):
		ans1 = mid
		low = mid + 1
	else:
		high = mid - 1
low = 0
high = n
while low <= high:
	mid = low + (high - low) // 2
	if lose(mid):
		ans2 = mid
		high = mid - 1
	else:
		low = mid + 1
print(ans2, ans1)


n = int(input())
Alice = list(map(int, input().split(' ')))
Alice2 = [Alice[0], Alice[1], Alice[2]]
Bob = list(map(int, input().split(' ')))
Bob2 = [Bob[0], Bob[1], Bob[2]]
minimum = 0
maximum = 0
j = 0
i = Alice.index(max(Alice))
while j < 3:
	remainder = Alice[i] - Bob[(i + 2) % 3]
	if remainder >= 0:
		if remainder >= Bob[i]:
			Alice[i] = remainder - Bob[i]
			Bob[i] = 0
		else:
			Bob[i] -= remainder
			Alice[i] = 0
	else:
		Bob[(i + 2) % 3] = abs(remainder)
		Alice[i] = 0
	i += 1
	i = i % 3
	j += 1
minimum = sum(Alice)
maximum = min(Bob2[0], Alice2[2]) + min(Bob2[1], Alice2[0]) + min(Bob2[2], Alice2[1])
print(minimum, maximum)


from heapq import heappush, heappop

class MinCostFlow:
	INF = 10 ** 18

	def __init__(self, N):
		self.N = N
		self.G = [[] for i in range(N)]

	def add_edge(self, fr, to, cap, cost):
		forward = [to, cap, cost, None]
		backward = forward[3] = [fr, 0, -cost, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def flow(self, s, t, f):
		N = self.N
		G = self.G
		INF = MinCostFlow.INF
		res = 0
		H = [0] * N
		prv_v = [0] * N
		prv_e = [None] * N
		d0 = [INF] * N
		dist = [INF] * N
		while f:
			dist[:] = d0
			dist[s] = 0
			que = [(0, s)]
			while que:
				(c, v) = heappop(que)
				if dist[v] < c:
					continue
				r0 = dist[v] + H[v]
				for e in G[v]:
					(w, cap, cost, _) = e
					if cap > 0 and r0 + cost - H[w] < dist[w]:
						dist[w] = r = r0 + cost - H[w]
						prv_v[w] = v
						prv_e[w] = e
						heappush(que, (r, w))
			if dist[t] == INF:
				return None
			for i in range(N):
				H[i] += dist[i]
			d = f
			v = t
			while v != s:
				d = min(d, prv_e[v][1])
				v = prv_v[v]
			f -= d
			res += d * H[t]
			v = t
			while v != s:
				e = prv_e[v]
				e[1] -= d
				e[3][1] += d
				v = prv_v[v]
		return res
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = MinCostFlow(8)
d.add_edge(0, 1, a[0], 0)
d.add_edge(0, 2, a[1], 0)
d.add_edge(0, 3, a[2], 0)
d.add_edge(1, 4, n, 0)
d.add_edge(1, 5, n, 1)
d.add_edge(1, 6, n, 0)
d.add_edge(2, 4, n, 0)
d.add_edge(2, 5, n, 0)
d.add_edge(2, 6, n, 1)
d.add_edge(3, 4, n, 1)
d.add_edge(3, 5, n, 0)
d.add_edge(3, 6, n, 0)
d.add_edge(4, 7, b[0], 0)
d.add_edge(5, 7, b[1], 0)
d.add_edge(6, 7, b[2], 0)
M = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(d.flow(0, 7, n), M)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
l = 0
w = 0
for i in range(3):
	w += min(a[i], b[(i + 1) % 3])
l = max([a[i] - (b[i] + b[(i + 2) % 3]) for i in range(3)])
if l < 0:
	l = 0
print(str(l) + ' ' + str(w))


n = input()
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
max_wins = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
min_wins = max(a[0] - b[0] - b[2], 0) + max(a[1] - b[0] - b[1], 0) + max(a[2] - b[1] - b[2], 0)
print(min_wins, max_wins)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
maxcount = 0
if a1 - b2 > 0 and b2 != 0:
	maxcount += b2
elif b2 == 0:
	maxcount += 0
else:
	maxcount += a1
if a2 - b3 > 0 and b3 != 0:
	maxcount += b3
elif b3 == 0:
	maxcount += 0
else:
	maxcount += a2
if a3 - b1 > 0 and b1 != 0:
	maxcount += b1
elif b1 == 0:
	maxcount += 0
else:
	maxcount += a3
mincount = 0
if a1 > b1 + b3:
	mincount += a1 - b1 - b3
if a2 > b1 + b2:
	mincount += a2 - b1 - b2
if a3 > b2 + b3:
	mincount += a3 - b2 - b3
print(mincount, maxcount)


def main():
	n = int(input())
	(a, b, c) = map(int, input().split())
	(q, w, e) = map(int, input().split())
	maximum = min(c, q) + min(a, w) + min(b, e)
	if q >= w and q >= e:
		c -= min(c, e)
		e -= min(c, e)
		c -= min(c, w)
		w -= min(c, w)
		b -= min(b, w)
		w -= min(b, w)
		b -= min(b, q)
		q -= min(b, q)
		a -= min(a, q)
		q -= min(a, q)
		a -= min(a, e)
		e -= min(a, e)
	elif w >= e:
		a -= min(a, q)
		q -= min(a, q)
		a -= min(a, e)
		e -= min(a, e)
		c -= min(c, e)
		e -= min(c, e)
		c -= min(c, w)
		w -= min(c, w)
		b -= min(b, w)
		w -= min(b, w)
		b -= min(b, q)
		q -= min(b, q)
	else:
		b -= min(b, w)
		w -= min(b, w)
		b -= min(b, q)
		q -= min(b, q)
		a -= min(a, q)
		q -= min(a, q)
		a -= min(a, e)
		e -= min(a, e)
		c -= min(c, e)
		e -= min(c, e)
		c -= min(c, w)
		w -= min(c, w)
	minimum = a + b + c
	print(minimum, maximum)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ma = 0
ma += min(a[0], b[1])
ma += min(a[1], b[2])
ma += min(a[2], b[0])
m = min(a[0], b[2])
a[0] -= min(a[0], b[0] + b[2])
a[1] -= min(a[1], b[1] + b[0])
a[2] -= min(a[2], b[1] + b[2])
print(sum(a), ma)


import sys, math
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
b = inpl()
sua = sum(a)
sub = sum(b)
mi_res = 0
if a[0] > b[0] + b[2]:
	mi_res = a[0] - b[0] - b[2]
if a[1] > b[0] + b[1]:
	mi_res = a[1] - b[0] - b[1]
if a[2] > b[2] + b[1]:
	mi_res = a[2] - b[2] - b[1]
ma_res = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(mi_res, ma_res)


from sys import stdin
tt = 1
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	maxans = 0
	for i in range(3):
		maxans += min(a[i], b[(i + 1) % 3])
	b = [b[1], b[2], b[0]]
	minans = 0
	for i in range(3):
		now = a[i]
		for j in range(3):
			if i != j:
				now -= b[j]
		minans = max(minans, now)
	for i in range(3):
		now = b[i]
		for j in range(3):
			if i != j:
				now -= a[j]
		minans = max(minans, now)
	print(minans, maxans)


n = int(input())
(Ar, As, Ap) = map(int, input().split())
(br, bs, bp) = map(int, input().split())
print(n - (min(As, n - bp) + min(Ap, n - br) + min(Ar, n - bs)), min(bp, As) + min(Ap, br) + min(Ar, bs))


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
minwin = n - min(a1, b1 + b3) - min(a2, b1 + b2) - min(a3, b2 + b3)
maxwin = min(a1, b2) + min(a3, b1) + min(a2, b3)
print(minwin, maxwin)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	b = L()
	mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	mn = max(0, a[0] + b[1] - n) + max(0, a[1] + b[2] - n) + max(0, a[2] + b[0] - n)
	print(mn, mx)
	return
t = 1
for i in range(t):
	solve()


n = int(input())
(rock, scissor, paper) = map(int, input().split(' '))
(x, y, z) = map(int, input().split(' '))
if n == 1:
	print(0)
else:
	highest = min(rock, y) + min(scissor, z) + min(paper, x)
	lowest = n - (min(x, rock + scissor) + min(y, scissor + paper) + min(z, paper + rock))
	print(lowest, highest)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(2 * n)]
mo = 1000000007
inf = 1e+18
div = 998244353
n = inn()
(r1, s1, p1) = value()
(r2, s2, p2) = value()
ans2 = min(r1, s2) + min(s1, p2) + min(p1, r2)
ans1 = max(r1 - r2 - p2, 0) + max(s1 - s2 - r2, 0) + max(p1 - p2 - s2, 0)
print(ans1, ans2)


input()
k = list(map(int, input().rstrip().split()))
l = list(map(int, input().rstrip().split()))
a1 = max({0, k[0] - l[0] - l[2], k[1] - l[1] - l[0], k[2] - l[2] - l[1]})
a2 = min(k[0], l[1]) + min(k[1], l[2]) + min(k[2], l[0])
print(a1, a2)


import itertools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
M = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
order = []
order.append((0, 0))
order.append((0, 2))
order.append((1, 1))
order.append((1, 0))
order.append((2, 2))
order.append((2, 1))
orders = itertools.permutations(order)
m = float('inf')
for ordr in orders:
	ac = a[:]
	bc = b[:]
	for i in range(6):
		cnt = min(ac[ordr[i][0]], bc[ordr[i][1]])
		ac[ordr[i][0]] -= cnt
		bc[ordr[i][1]] -= cnt
	cand = min(ac[0], bc[1]) + min(ac[1], bc[2]) + min(ac[2], bc[0])
	m = min(m, cand)
print(m, M)


from sys import stdin, stdout
from collections import deque

class MaxFlow:

	def __init__(self, src, snk):
		self.src = src
		self.snk = snk
		self.dic = {}

	def add_edge(self, f, t, cap):
		if f not in self.dic:
			self.dic[f] = {}
		if t not in self.dic:
			self.dic[t] = {}
		self.dic[f][t] = [f, t, 0, cap]
		self.dic[t][f] = [t, f, 0, 0]

	def bfs(self):
		q = deque()
		q.append([self.src, []])
		s = set()
		s.add(self.src)
		while q:
			cnt = len(q)
			for _ in range(cnt):
				cur = q.popleft()
				for k in self.dic[cur[0]]:
					if k in s:
						continue
					edge = self.dic[cur[0]][k]
					if edge[2] >= edge[3]:
						continue
					s.add(k)
					if k == self.snk:
						cur[1].append(edge)
						return cur[1]
					q.append([k, cur[1] + [edge]])
		return None

	def augment(self, lst):
		delta = 2 ** 63 - 1
		for edge in lst:
			delta = min(delta, edge[3] - edge[2])
		for edge in lst:
			edge[2] += delta
			f = edge[0]
			t = edge[1]
			self.dic[t][f][2] -= delta

	def max_flow(self):
		while True:
			lst = self.bfs()
			if not lst:
				break
			self.augment(lst)
		flow = 0
		for k in self.dic[self.src]:
			flow += self.dic[self.src][k][2]
		return flow

def rock_paper_scissors(n, a_a, b_a):
	MAX_C = 2 ** 63 - 1
	mf = MaxFlow(0, 7)
	mf.add_edge(0, 1, a_a[0])
	mf.add_edge(0, 2, a_a[1])
	mf.add_edge(0, 3, a_a[2])
	mf.add_edge(1, 4, MAX_C)
	mf.add_edge(1, 6, MAX_C)
	mf.add_edge(2, 4, MAX_C)
	mf.add_edge(2, 5, MAX_C)
	mf.add_edge(3, 5, MAX_C)
	mf.add_edge(3, 6, MAX_C)
	mf.add_edge(4, 7, b_a[0])
	mf.add_edge(5, 7, b_a[1])
	mf.add_edge(6, 7, b_a[2])
	mxflow = mf.max_flow()
	return n - mxflow
n = int(stdin.readline())
a_a = list(map(int, stdin.readline().split()))
b_a = list(map(int, stdin.readline().split()))
res2 = min(a_a[0], b_a[1]) + min(a_a[1], b_a[2]) + min(a_a[2], b_a[0])
res1 = rock_paper_scissors(n, a_a, b_a)
stdout.write(str(res1))
stdout.write(' ')
stdout.write(str(res2))


n = int(input())
(a, b, c) = map(int, input().split())
(x, y, z) = map(int, input().split())
maxa = min(a, y) + min(b, z) + min(c, x)
mina = min(a, n - y) + min(b, n - z) + min(c, n - x)
print(n - mina, maxa)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline()[:-1]

def SI():
	return sys.stdin.buffer.readline()[:-1].decode()
n = II()
aa = LI()
bb = LI()
mn = sum((max(aa[i] - bb[i] - bb[i - 1], 0) for i in range(3)))
mx = sum((min(aa[i - 1], bb[i]) for i in range(3)))
print(mn, mx)


n = int(input())
(r1, s1, p1) = tuple([int(x) for x in input().split()])
(r2, s2, p2) = tuple([int(x) for x in input().split()])
resmax = min(r1, s2) + min(s1, p2) + min(p1, r2)
resmin = min(r1, n - s2) + min(s1, n - p2) + min(p1, n - r2)
print(n - resmin, resmax)


n = int(input())
a = input().split()
a = [int(play) for play in a]
b = input().split()
b = [int(play) for play in b]
amax = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
amin = n - (min(a[0], b[2] + b[0]) + min(a[1], b[0] + b[1]) + min(a[2], b[1] + b[2]))
print(amin, amax)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
(r1, s1, p1) = list(map(int, input().rstrip().split(' ')))
(r2, s2, p2) = list(map(int, input().rstrip().split(' ')))
w1 = min(r1, s2) + min(s1, p2) + min(p1, r2)
w2 = max(r1 - (r2 + p2), 0) + max(s1 - (r2 + s2), 0) + max(p1 - (p2 + s2), 0)
print(w2, w1)


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from itertools import permutations as pt
n = int(read())
a = list(readi())
b = list(readi())
operations = [(0, 0), (0, 2), (1, 1), (1, 0), (2, 2), (2, 1)]
maxWin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
minWin = float('-inf')
for perm in pt(operations, 6):
	A = a.copy()
	B = b.copy()
	temp = 0
	for (i, j) in perm:
		diff = min(A[i], B[j])
		A[i] -= diff
		B[j] -= diff
		temp += diff
	minWin = max(minWin, temp)
minWin = n - minWin
print(minWin, maxWin)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
minimum = 0
if b[0] + b[2] < a[0]:
	minimum += abs(b[0] + b[2] - a[0])
if b[0] + b[1] < a[1]:
	minimum += abs(b[0] + b[1] - a[1])
if b[1] + b[2] < a[2]:
	minimum += abs(b[1] + b[2] - a[2])
maximum = 0
maximum += min(a[0], b[1])
maximum += min(a[1], b[2])
maximum += min(a[2], b[0])
print(minimum, maximum)


n = int(input())
(a1, a2, a3) = list(map(int, input().rstrip().split()))
(b1, b2, b3) = list(map(int, input().rstrip().split()))
max_win = min(a1, b2) + min(a2, b3) + min(a3, b1)
min_win = max(0, b1 - (a1 + a2), b2 - (a2 + a3), b3 - (a1 + a3))
print(min_win, end=' ')
print(max_win)


import sys
from itertools import permutations
from copy import deepcopy

def solve1(input_path=None):
	if input_path is None:
		f = sys.stdin
	else:
		f = open(input_path, 'r')
	n = int(f.readline())
	a = list(map(int, f.readline().split()))
	b = list(map(int, f.readline().split()))
	min_win = n
	cases = list()
	cases.append((0, 0))
	cases.append((0, 2))
	cases.append((1, 1))
	cases.append((1, 0))
	cases.append((2, 2))
	cases.append((2, 1))
	cases = sorted(cases)
	for case in permutations(cases):
		a_temp = deepcopy(a)
		b_temp = deepcopy(b)
		for match in case:
			cnt = min(a_temp[match[0]], b_temp[match[1]])
			a_temp[match[0]] -= cnt
			b_temp[match[1]] -= cnt
		cur = min(a_temp[0], b_temp[1]) + min(a_temp[1], b_temp[2]) + min(a_temp[2], b_temp[0])
		min_win = min(min_win, cur)
	max_win = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	return [f'{min_win} {max_win}']

def main():
	for line in solve1():
		print(f'{line}')
main()


import sys
input = sys.stdin.readline

def fa(a1, b2, a2, b3, a3, b1):
	c = 0
	bv = max(b1 - a1 - a2, 0)
	c = c + bv
	a2 = a2 - b1
	if a2 < 0:
		a1 = max(a1 + a2, 0)
		a2 = 0
	bv = max(b2 - a2 - a3, 0)
	c = c + bv
	a2 = a2 - b2
	if a2 < 0:
		a3 = max(a2 + a3, 0)
	bv = max(b3 - a1 - a3, 0)
	c = c + bv
	return c

def main():
	n = int(input())
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	v = min(a1, b2) + min(a2, b3) + min(a3, b1)
	c = min(fa(a1, b2, a2, b3, a3, b1), fa(a1, b2, a3, b1, a2, b3), fa(a2, b3, a1, b2, a3, b1), fa(a2, b3, a3, b1, a1, b2), fa(a3, b1, a1, b2, a2, b3), fa(a3, b1, a2, b3, a1, b2))
	print(c, v)
main()


def f(n, a, b):
	losses = []
	for i in range(3):
		l = max([a[i - 1] - (n - b[i]), 0])
		losses.append(l)
	losses = sum(losses)
	wins = []
	for i in range(3):
		w = min([a[i - 1], b[i]])
		wins.append(w)
	wins = sum(wins)
	return [losses, wins]
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
results = f(n, a, b)
for i in results:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
maxWin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])

def dfs():
	takenCnts = 0
	for x in takenCombinations:
		if x == True:
			takenCnts += 1
	if takenCnts == 6:
		minWins.append(sum(arr[:3]))
		return
	for i in range(6):
		if takenCombinations[i] == False:
			takenCombinations[i] = True
			(x, y) = combinations[i]
			subtract = min(arr[x], arr[y])
			arr[x] -= subtract
			arr[y] -= subtract
			dfs()
			arr[x] += subtract
			arr[y] += subtract
			takenCombinations[i] = False
arr = a + b
combinations = [(0, 3), (0, 5), (1, 4), (1, 3), (2, 5), (2, 4)]
takenCombinations = [False] * 6
minWins = []
dfs()
minWin = min(minWins)
print('{} {}'.format(minWin, maxWin))


input()
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
(a[1], a[2]) = (a[2], a[1])
(b[1], b[2]) = (b[2], b[1])
maxwin = min(a[0], b[2]) + min(a[1], b[0]) + min(a[2], b[1])

def calc(a, b, left):
	m = 10 ** 9
	for possible in left[:]:
		(newleft, newa, newb) = (left[:], a[:], b[:])
		newleft.remove(possible)
		played = min(a[possible[0]], b[possible[1]])
		newa[possible[0]] -= played
		newb[possible[1]] -= played
		res = calc(newa, newb, newleft)
		m = min(m, res)
	if not len(left):
		return min(a[0], b[2]) + min(a[1], b[0]) + min(a[2], b[1])
	return m
minwin = calc(a[:], b[:], [(0, 0), (0, 1), (1, 1), (1, 2), (2, 0), (2, 2)])
print(minwin, maxwin)


def minv(a, b):
	m = 0
	for i in range(3):
		m = max(m, b[i] - a[i] - a[(i + 1) % 3])
	return m

def maxv(a, b):
	total = 0
	for i in range(3):
		total += min(a[i], b[(i + 1) % 3])
	return total
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(minv(a, b), maxv(a, b))


n = int(input())
(a, b, c) = tuple(map(int, input().split()))
(d, e, f) = tuple(map(int, input().split()))
a1 = max(0, a - d - f) + max(0, b - e - d) + max(0, c - f - e)
a2 = min(a, e) + min(b, f) + min(c, d)
print(a1, a2)


import sys
from itertools import permutations
n = int(input())
input = sys.stdin.readline
(r1, s1, p1) = map(int, input().split())
(r2, s2, p2) = map(int, input().split())
a1 = min(r1, s2) + min(s1, p2) + min(p1, r2)
li = [[0, 3], [0, 5], [1, 4], [1, 3], [2, 5], [2, 4]]
xx = list(permutations(li))
a2 = []
for i in xx:
	tem = [r1, s1, p1, r2, s2, p2]
	ans = 0
	for j in i:
		pp = min(tem[j[0]], tem[j[1]])
		ans += pp
		tem[j[0]] -= pp
		tem[j[1]] -= pp
	a2.append(ans)
print(n - max(a2), a1)


from itertools import permutations
n = int(input())
(RA, SA, PA) = map(int, input().split())
(RB, SB, PB) = map(int, input().split())
alice = {'RA': RA, 'SA': SA, 'PA': PA}
bob = {'RB': RB, 'SB': SB, 'PB': PB}
minimum = maximum = 0
moves = [['RA', 'PB'], ['SA', 'RB'], ['PA', 'SB'], ['RA', 'RB'], ['SA', 'SB'], ['PA', 'PB']]
perm = list(permutations(moves))
minimum = float('inf')
for move in perm:
	(acopy, bcopy) = (alice.copy(), bob.copy())
	for (a, b) in move:
		val = min(acopy[a], bcopy[b])
		acopy[a] -= val
		bcopy[b] -= val
	temp = min(acopy['RA'], bcopy['SB']) + min(acopy['SA'], bcopy['PB']) + min(acopy['PA'], bcopy['RB'])
	minimum = min(minimum, temp)
maximum = min(alice['RA'], bob['SB']) + min(alice['SA'], bob['PB']) + min(alice['PA'], bob['RB'])
print(f'{minimum} {maximum}')


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
(a, b, c) = R()
(x, y, z) = R()
mx = min(a, y) + min(b, z) + min(c, x)
mn = max(a - x - z, b - x - y, c - y - z, 0)
print(mn, mx)


n = int(input())
(a1, a2, a3) = [int(num) for num in input().split()]
(b1, b2, b3) = [int(num) for num in input().split()]
c1 = min(a1, b2)
c2 = min(a2, b3)
c3 = min(a3, b1)
c4 = max(0, a1 - (b3 + b1))
c5 = max(0, a2 - (b1 + b2))
c6 = max(0, a3 - (b2 + b3))
print(max(c4, c5, c6), c1 + c2 + c3)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mx = 0
mn = 0
mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mn = max(0, a[0] - b[0] - b[2]) + max(0, a[1] - b[1] - b[0]) + max(0, a[2] - b[2] - b[1])
print(mn, mx)


import sys
input = sys.stdin.readline
n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
V = 8
EDGE = [[0] * V for i in range(V)]
start = 0
goal = V - 1
EDGE[0][1] = a1
EDGE[0][2] = a2
EDGE[0][3] = a3
EDGE[4][7] = b1
EDGE[5][7] = b2
EDGE[6][7] = b3
EDGE[1][4] = float('inf')
EDGE[1][6] = float('inf')
EDGE[2][4] = float('inf')
EDGE[2][5] = float('inf')
EDGE[3][5] = float('inf')
EDGE[3][6] = float('inf')
ANS = 0
while True:
	USED = [0] * V
	ROUTE = [-1] * V
	Q = [(start, float('inf'))]
	while Q:
		(NOW, cost) = Q.pop()
		if NOW == goal:
			break
		for to in range(V):
			if USED[to] == 0 and EDGE[NOW][to] != 0:
				ROUTE[to] = NOW
				USED[to] = 1
				Q.append((to, min(cost, EDGE[NOW][to])))
	else:
		break
	ANS += cost
	i = goal
	while i != start:
		j = ROUTE[i]
		EDGE[j][i] -= cost
		EDGE[i][j] += cost
		i = j
print(n - ANS, min(a1, b2) + min(a2, b3) + min(a3, b1))


import sys

def solve(x):
	print(x)
	return x
IN = [x.strip() for x in sys.stdin.readlines()]
n = int(IN[0])
(ar, a_s, ap) = [int(x) for x in IN[1].split(' ')]
(br, bs, bp) = [int(x) for x in IN[2].split(' ')]
min_alice_wins = max(ar - (br + bp), a_s - (br + bs), ap - (bs + bp), 0)
max_alice_wins = min(ap, br) + min(ar, bs) + min(a_s, bp)
print('{} {}'.format(min_alice_wins, max_alice_wins))


n = int(input())
(a1, a2, a3) = list(map(int, input().strip().split()))
(b1, b2, b3) = list(map(int, input().strip().split()))
max_win = min(a3, b1) + min(a1, b2) + min(a2, b3)
min_win = 0
a1_must_win = max(0, a1 - b1 - b3)
a2_must_win = max(0, a2 - b2 - b1)
a3_must_win = max(0, a3 - b3 - b2)
a1_b1_draw = min(a1, b1)
a1_b3_lose = min(a1, b3)
a1_b2_sure_win = max(0, a1 - b1 - b3)
if a1_b2_sure_win > 0:
	(b1, b3) = (0, 0)
a2_b2_draw = min(a2, b2)
a2_b1_lose = min(a2, b1)
a2_b3_sure_win = max(0, a2 - b2 - b1)
if a2_b3_sure_win > 0:
	(b2, b1) = (0, 0)
a3_b3_draw = min(a3, b3)
a3_b2_lose = min(a3, b2)
a3_b1_sure_win = max(0, a3 - b3 - b2)
if a3_b1_sure_win > 0:
	(b3, b2) = (0, 0)
min_win = a1_b2_sure_win + a2_b3_sure_win + a3_b1_sure_win
print(f'{min_win} {max_win}')


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
maxx = min(b2, a1) + min(a2, b3) + min(a3, b1)
c = 0
if b1 > a1:
	c += 1
if b2 > a2:
	c += 1
if b3 > a3:
	c += 1
if c == 1:
	if b1 > a1:
		minn = max(0, min(b1, a3 - (b2 + b3)))
	elif b2 > a2:
		minn = max(0, min(b2, a1 - (b1 + b3)))
	else:
		minn = max(0, min(b3, a2 - (b1 + b2)))
elif a1 > b1:
	minn = max(0, min(b2, a1 - (b1 + b3)))
elif a2 > b2:
	minn = max(0, min(b3, a2 - (b1 + b2)))
else:
	minn = max(0, min(b1, a3 - (b3 + b2)))
print(minn, maxx)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(mn, mx) = (0, 0)
for i in range(3):
	mn += max(0, a[i] + b[(i + 1) % 3] - n)
	mx += min(a[i], b[(i + 1) % 3])
print(mn, mx)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
max_ = 0
max_ += min(A[0], B[1])
max_ += min(A[1], B[2])
max_ += min(A[2], B[0])
min_ = 0
min_ += max(0, A[0] - B[0] - B[2])
min_ += max(0, A[1] - B[0] - B[1])
min_ += max(0, A[2] - B[1] - B[2])
print(min_, max_)


import os, sys
from io import BytesIO, IOBase
from itertools import permutations

def main():
	n = int(input())
	(r1, s1, p1) = map(int, input().split())
	(r2, s2, p2) = map(int, input().split())
	maxi = min(r1, s2) + min(s1, p2) + min(p1, r2)
	(r3, s3, p3) = (r2, s2, p2)
	(r4, s4, p4) = (r1, s1, p1)
	mini = 10 ** 10
	for i in permutations([1, 2, 3]):
		dct = {1: r1, 2: s1, 3: p1}
		dct1 = {1: [r2, p2], 2: [s2, r2], 3: [p2, s2]}
		dct2 = {1: [p2, r2], 2: [r2, s2], 3: [s2, p2]}
		dct3 = {1: s2, 2: p2, 3: r2}
		ans = 0
		for x in i:
			r = min(dct[x], dct1[x][0])
			dct[x] -= r
			dct1[x][0] -= r
			q = min(dct[x], dct1[x][1])
			dct[x] -= q
			dct1[x][1] -= q
			dct3[x] -= dct[x]
			ans += dct[x]
			dct[x] = 0
		mini = min(mini, ans)
		(r2, s2, p2) = (r3, s3, p3)
		(r1, s1, p1) = (r4, s4, p4)
	print(mini, maxi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
(a1, a2, a3) = list(map(int, input().rstrip().split()))
(b1, b2, b3) = list(map(int, input().rstrip().split()))
mx = min(a1, b2) + min(a2, b3) + min(a3, b1)
mi = max(0, b1 - (a1 + a2), b2 - (a2 + a3), b3 - (a1 + a3))
print(mi, mx)


from itertools import permutations
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
(a_r, a_s, a_p) = a
(b_r, b_s, b_p) = b
a_max_win = 0
k = min(a_r, b_s)
a_max_win += k
a_r -= k
b_s -= k
k = min(a_s, b_p)
a_max_win += k
a_s -= k
b_p -= k
k = min(a_p, b_r)
a_max_win += k
a_p -= k
b_r -= k
(a_r, a_s, a_p) = b
(b_r, b_s, b_p) = a

def simulate(a__r, a__s, a__p, b__r, b__s, b__p, order):
	for i in order:
		if i == 0:
			k = min(a__r, b__s)
			a__r -= k
			b__s -= k
		elif i == 1:
			k = min(a__s, b__p)
			a__s -= k
			b__p -= k
		elif i == 2:
			k = min(a__p, b__r)
			a__p -= k
			b__r -= k
		elif i == 3:
			k = min(a__r, b__r)
			a__r -= k
			b__r -= k
		elif i == 4:
			k = min(a__s, b__s)
			a__s -= k
			b__s -= k
		else:
			k = min(a__p, b__p)
			a__p -= k
			b__p -= k
	return sum([a__r, a__s, a__p])
print(min((simulate(a_r, a_s, a_p, b_r, b_s, b_p, p) for p in permutations(list(range(6))))), a_max_win)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	(a, a1, a2) = map(int, sys.stdin.readline().split())
	(b, b1, b2) = map(int, sys.stdin.readline().split())
	res = min(a, b1) + min(a1, b2) + min(a2, b)
	if b >= a1 + a:
		ans = a2 - (n - b)
	elif b1 >= a1 + a2:
		ans = a - (n - b1)
	elif b2 >= a2 + a:
		ans = a1 - (n - b2)
	elif b == a and b1 == a1 and (b2 == a2):
		ans = 0
	elif a > b and a1 > b1:
		b2 -= a2
		a -= b2
		a1 -= b1
		if a <= 0:
			ans = a1 - b
		else:
			ans = a + a1 - b
	elif a2 > b2 and a1 > b1:
		b -= a
		a1 -= b
		a2 -= b2
		if a1 <= 0:
			ans = a2 - b1
		else:
			ans = a2 + a1 - b1
	elif a > b and a2 > b2:
		b1 -= a1
		a2 -= b1
		a -= b
		if a2 <= 0:
			ans = a - b
		else:
			ans = a2 + a - b
	elif a > b:
		a -= b
		b1 -= a1
		a2 -= b1
		a1 = 0
		ans = a + a2 - b2
	elif a1 > b1:
		a1 -= b1
		b2 -= a2
		a -= b2
		a2 = 0
		ans = a + a1 - b
	elif a2 > b2:
		a2 -= b2
		b -= a
		a1 -= b
		a = 0
		ans = a2 + a1 - b1
	print(max(0, ans), res)
for i in range(1):
	main()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mini = 0
for i in range(3):
	if A[i] >= B[i] + B[i - 1]:
		mini = A[i] - (B[i] + B[i - 1])
	if B[i] >= A[i] + A[i - 2]:
		mini = B[i] - (A[i] + A[i - 2])
print(mini, min(A[0], B[1]) + min(A[1], B[2]) + min(A[2], B[0]))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
v = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
u = n - (min(b[0], a[0] + a[1]) + min(b[1], a[1] + a[2]) + min(b[2], a[2] + a[0]))
print(str(u) + ' ' + str(v))


from math import *
from sys import *
input = stdin.readline

def solveMin(a, b, index):
	if index == 3:
		return sum(a)
	index1 = index
	index2 = (index + 1) % 3
	a1 = list(a)
	b1 = list(b)
	if b1[index1] <= a1[index1]:
		a1[index1] = a1[index1] - b1[index1]
		b1[index1] = 0
	else:
		b1[index1] = b1[index1] - a1[index1]
		a1[index1] = 0
		if b1[index1] <= a1[index2]:
			a1[index2] = a1[index2] - b1[index1]
			b1[index1] = 0
		else:
			b1[index1] = b1[index1] - a1[index2]
			a1[index2] = 0
	s1 = solveMin(a1, b1, index + 1)
	a2 = list(a)
	b2 = list(b)
	if b2[index1] <= a2[index2]:
		a2[index2] = a2[index2] - b2[index1]
		b2[index1] = 0
	else:
		b2[index1] = b2[index1] - a2[index2]
		a2[index2] = 0
		if b2[index1] <= a2[index1]:
			a2[index1] = a2[index1] - b2[index1]
			b2[index1] = 0
		else:
			b2[index1] = b2[index1] - a2[index1]
			a2[index1] = 0
	s2 = solveMin(a2, b2, index + 1)
	return min(s1, s2)

def solveMax(a, b, index):
	if index == 3:
		return sum(a)
	index1 = (index + 2) % 3
	a1 = list(a)
	b1 = list(b)
	if b1[index] <= a1[index1]:
		a1[index1] = a1[index1] - b1[index]
		b1[index] = 0
	else:
		b1[index] = b1[index] - a1[index1]
		a1[index1] = 0
	s1 = solveMax(a1, b1, index + 1)
	return s1
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mn = solveMin(list(a), list(b), 0)
	mx = solveMax(a, b, 0)
	print(mn, n - mx)


n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
maxwin = min(alice[0], bob[1]) + min(alice[1], bob[2]) + min(alice[2], bob[0])
minlose = alice[0] - min(alice[0], bob[0] + bob[2]) + (alice[1] - min(alice[1], bob[1] + bob[0])) + (alice[2] - min(alice[2], bob[2] + bob[1]))
print(minlose, maxwin)


import math

def non_zero_seg():
	n = int(input())
	alice = [int(x) for x in input().split(' ')]
	bob = [int(x) for x in input().split(' ')]
	max_won = min(alice[0], bob[1])
	max_won += min(alice[1], bob[2])
	max_won += min(alice[2], bob[0])
	min_won = max(0, alice[0] - bob[2] - bob[0])
	min_won += max(0, alice[1] - bob[0] - bob[1])
	min_won += max(0, alice[2] - bob[1] - bob[2])
	print(max(0, min_won), max(0, max_won))
non_zero_seg()


from itertools import permutations
from math import inf

def mx(a, b):
	return sum([min(a[0], b[1]), min(a[1], b[2]), min(a[2], b[0])])

def mn(a, b):
	combs = [(0, 0), (0, 2), (1, 1), (1, 0), (2, 2), (2, 1)]
	res = inf
	for ele in permutations(combs):
		la = list(a)
		lb = list(b)
		for el in list(ele):
			w = min(la[el[0]], lb[el[1]])
			la[el[0]] -= w
			lb[el[1]] -= w
		ans = sum(la)
		res = min(res, ans)
	return res
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(mn(a, b), mx(a, b))


import sys
import math
import itertools

class State:

	def __init__(self, a_r, a_s, a_p, b_r, b_s, b_p):
		self.a_r = a_r
		self.b_r = b_r
		self.a_s = a_s
		self.b_s = b_s
		self.a_p = a_p
		self.b_p = b_p
		self.wins = 0

	def f1(self):
		self.a_r -= min(self.a_r, self.b_r)
		self.b_r -= min(self.a_r, self.b_r)

	def f2(self):
		self.a_s -= min(self.a_s, self.b_s)
		self.b_s -= min(self.a_s, self.b_s)

	def f3(self):
		self.a_p -= min(self.a_p, self.b_p)
		self.b_p -= min(self.a_p, self.b_p)

	def f4(self):
		self.a_r -= min(self.a_r, self.b_p)
		self.b_p -= min(self.a_r, self.b_p)

	def f5(self):
		self.a_p -= min(self.a_p, self.b_s)
		self.b_s -= min(self.a_p, self.b_s)

	def f6(self):
		self.a_s -= min(self.a_s, self.b_r)
		self.b_r -= min(self.a_s, self.b_r)
n = int(input())
(a_r, a_s, a_p) = [int(i) for i in input().split()]
(b_r, b_s, b_p) = [int(i) for i in input().split()]
max_wins = min(a_r, b_s) + min(a_s, b_p) + min(a_p, b_r)
funs = [State.f1, State.f2, State.f3, State.f4, State.f5, State.f6]
min_wins = float('inf')
for perm in itertools.permutations(funs):
	state = State(a_r, a_s, a_p, b_r, b_s, b_p)
	for fun in perm:
		fun(state)
	wins = min(state.a_r, state.b_s) + min(state.a_s, state.b_p) + min(state.a_p, state.b_r)
	min_wins = min(wins, min_wins)
print(min_wins, max_wins)


number_of_rounds = int(input())
[rock_a, scissors_a, paper_a] = list(map(int, input().split()))
[rock_b, scissors_b, paper_b] = list(map(int, input().split()))
max_alice = 0
min_alice = 0
max_alice = min(rock_a, scissors_b) + min(scissors_a, paper_b) + min(paper_a, rock_b)
if rock_a > rock_b + paper_b:
	min_alice += rock_a - (rock_b + paper_b)
if scissors_a > scissors_b + rock_b:
	min_alice += scissors_a - (scissors_b + rock_b)
if paper_a > paper_b + scissors_b:
	min_alice += paper_a - (paper_b + scissors_b)
print(min_alice, end=' ')
print(max_alice, end='')


n = int(input())
(r, s, p) = [int(x) for x in input().split()]
(rx, sx, px) = [int(x) for x in input().split()]
mx = min(p, rx) + min(s, px) + min(r, sx)
mn = max(0, p - sx - px, s - sx - rx, r - rx - px)
print(str(mn) + ' ' + str(mx))


n = int(input())
(ar, asis, ap) = map(int, input().split())
(br, bsis, bp) = map(int, input().split())
max = min(ar, bsis) + min(asis, bp) + min(ap, br)
min = min(ar, n - bsis) + min(asis, n - bp) + min(ap, n - br)
print(n - min, max)


(N, *A) = map(int, open(0).read().split())
T = [*zip(A, A[4:] + A[3:4])]
print(sum((max(0, a + b - N) for (a, b) in T)), sum(map(min, T)))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	n = int(stdin.readline())
	(ra, sa, pa) = list(map(int, stdin.readline().rstrip().split()))
	(rb, sb, pb) = list(map(int, stdin.readline().rstrip().split()))
	ans1 = min(ra, sb) + min(pa, rb) + min(sa, pb)
	ans2 = max(rb - (ra + sa), pb - (pa + ra), sb - (sa + pa), 0)
	print(ans2, ans1)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ans = min(a1, b2) + min(a2, b3) + min(a3, b1)
out = max(b3 - a3 - a1, b2 - a2 - a3, b1 - a1 - a2, 0)
print(out, ans)


import sys
import itertools
from functools import reduce
n = int(sys.stdin.readline().strip())
inputA = list(map(int, sys.stdin.readline().strip().split()))
inputB = list(map(int, sys.stdin.readline().strip().split()))
inputA2 = inputA.copy()
inputB2 = inputB.copy()

def getWonMaxFast(inputA, inputB):
	wins = [0] * 3
	for i in range(0, 3):
		good = (i + 1) % 3
		wins[i] = min(inputA[i], inputB[good])
		inputA[i] -= wins[i]
		inputB[good] -= wins[i]
	return sum(wins)

def getLostMaxFast(inputA, inputB):
	waysToLose = [[0, 2], [1, 0], [2, 1], [0, 0], [1, 1], [2, 2]]
	allWaysToLosePermutations = list(itertools.permutations(waysToLose))
	maxLost = 0
	for permutation in allWaysToLosePermutations:
		losts = [0] * 3
		inputACopy = inputA.copy()
		inputBCopy = inputB.copy()
		for wayToLose in permutation:
			lost_add = min(inputACopy[wayToLose[0]], inputBCopy[wayToLose[1]])
			inputACopy[wayToLose[0]] -= lost_add
			inputBCopy[wayToLose[1]] -= lost_add
			losts[wayToLose[0]] += lost_add
		lostSum = sum(losts)
		if lostSum > maxLost:
			maxLost = lostSum
	return maxLost
print(n - getLostMaxFast(inputA2, inputB2), getWonMaxFast(inputA, inputB))


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
x1 = x2 = x3 = 0
if b1 - a1 - a2 >= 0:
	x1 = b1 - a1 - a2
if b2 - a2 - a3 >= 0:
	x2 = b2 - a2 - a3
if b3 - a3 - a1 >= 0:
	x3 = b3 - a3 - a1
mi = max(x1, x2, x3)
print(mi, min(a1, b2) + min(a2, b3) + min(a3, b1))


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
alis_max = min(a1, b2) + min(a2, b3) + min(a3, b1)
alis_min = max(0, b1 - a1 - a2, b2 - a2 - a3, b3 - a3 - a1)
print(alis_min, alis_max)


import sys, os
from math import sqrt, gcd, ceil, log, floor
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	n = int(input())
	a = read()
	b = read()
	mn = max(0, a[0] - (b[2] + b[0]), a[1] - (b[0] + b[1]), a[2] - (b[1] + b[2]))
	mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	print(mn, mx)
main()


def maximum_wins(a1, a2, a3, rock, scissor, paper):
	ans = 0
	mini1 = min(a1, scissor)
	ans += mini1
	scissor -= mini1
	mini2 = min(a2, paper)
	ans += mini2
	paper -= mini2
	mini3 = min(a3, rock)
	rock -= mini3
	ans += mini3
	return ans

def minimum_wins(rock, paper, scissor, a1, a2, a3):
	return max(0, a1 - paper - rock) + max(0, a2 - rock - scissor) + max(0, a3 - paper - scissor)
n = int(input())
(a1, a2, a3) = map(int, input().split())
(rock, scissor, paper) = map(int, input().split())
print(minimum_wins(rock, paper, scissor, a1, a2, a3), maximum_wins(a1, a2, a3, rock, scissor, paper))


import math
import sys
n = int(input())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
mn = 0
for i in range(3):
	sum = 0
	for j in range(3):
		if j == (i + 1) % 3:
			continue
		sum += br[j]
	mn = max(mn, max(ar[i] - sum, 0))
mx = 0
for i in range(3):
	mx += min(ar[i], br[(i + 1) % 3])
print(mn, mx)


numR = int(input())
(r1, s1, p1) = [int(x) for x in input().split()]
(r2, s2, p2) = [int(x) for x in input().split()]
(mx, mn) = (0, 0)
mx += min(r1, s2)
mx += min(s1, p2)
mx += min(p1, r2)
mn = max(mn, r1 + s2 - numR)
mn = max(mn, s1 + p2 - numR)
mn = max(mn, p1 + r2 - numR)
print(mn, mx)


for _ in range(1):
	n = int(input())
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	mx = min(a1, b2) + min(b1, c2) + min(c1, a2)
	mn = min(a1, a2 + c2) + min(b1, a2 + b2) + min(c1, b2 + c2)
	print(n - mn, mx)


t = int(input())
r = 0
(a, b, c) = input().split()
(d, e, f) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = int(f)
if c > e + f:
	r += c - e - f
elif a > d + f:
	r += a - d - f
elif b > e + d:
	r += b - e - d
print(r, min(a, e) + min(b, f) + min(c, d))


n = int(input())
(a, b, c) = map(int, input().split())
(x, y, z) = map(int, input().split())
max = min(a, y) + min(b, z) + min(c, x)
min = min(a, n - y) + min(b, n - z) + min(c, n - x)
print(n - min, max)


import itertools

def e1(a1, a2, a3, b1, b2, b3):
	return (a1 - min(a1, b1), a2, a3, b1 - min(a1, b1), b2, b3)

def e2(a1, a2, a3, b1, b2, b3):
	return (a1, a2 - min(a2, b2), a3, b1, b2 - min(a2, b2), b3)

def e3(a1, a2, a3, b1, b2, b3):
	return (a1, a2, a3 - min(a3, b3), b1, b2, b3 - min(a3, b3))

def l1(a1, a2, a3, b1, b2, b3):
	return (a1, a2 - min(b1, a2), a3, b1 - min(b1, a2), b2, b3)

def l2(a1, a2, a3, b1, b2, b3):
	return (a1, a2, a3 - min(b2, a3), b1, b2 - min(b2, a3), b3)

def l3(a1, a2, a3, b1, b2, b3):
	return (a1 - min(a1, b3), a2, a3, b1, b2, b3 - min(a1, b3))
_ = input()
(a1, a2, a3) = [int(x) for x in input().split()]
(b1, b2, b3) = [int(x) for x in input().split()]
minn = 10000000000.0
for p in itertools.permutations([e1, e2, e3, l1, l2, l3]):
	(A1, A2, A3, B1, B2, B3) = (a1, a2, a3, b1, b2, b3)
	for fn in p:
		(A1, A2, A3, B1, B2, B3) = fn(A1, A2, A3, B1, B2, B3)
		minn = min(A1 + A2 + A3, minn)
print(minn, min(a1, b2) + min(a2, b3) + min(a3, b1))


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
n = ii1()
a = iia()
b = iia()
a2 = max(0, a[0] - (b[0] + b[2])) + max(0, a[1] - (b[1] + b[0])) + max(0, a[2] - (b[2] + b[1]))
a1 = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(a2, a1)


import heapq

class mcf_graph_int_cost:

	def __init__(self, n):
		self.n = n
		self.pos = []
		self.g = [[] for _ in range(n)]

	def add_edge(self, from_, to, cap, cost):
		m = len(self.pos)
		self.pos.append((from_, len(self.g[from_])))
		self.g[from_].append(self.__class__._edge(to, len(self.g[to]), cap, cost))
		self.g[to].append(self.__class__._edge(from_, len(self.g[from_]) - 1, 0, -cost))
		return m

	class edge:

		def __init__(self, from_, to, cap, flow, cost):
			self.from_ = from_
			self.to = to
			self.cap = cap
			self.flow = flow
			self.cost = cost

	def get_edge(self, i):
		_e = self.g[self.pos[i][0]][self.pos[i][1]]
		_re = self.g[_e.to][_e.rev]
		return self.__class__.edge(self.pos[i][0], _e.to, _e.cap + _re.cap, _re.cap, _e.cost)

	def edges(self):
		ret = []
		for i in range(len(self.pos)):
			_e = self.g[self.pos[i][0]][self.pos[i][1]]
			_re = self.g[_e.to][_e.rev]
			ret.append(self.__class__.edge(self.pos[i][0], _e.to, _e.cap + _re.cap, _re.cap, _e.cost))
		return ret

	def _dual_ref(self, s, t):
		self.dist = [4294967295] * self.n
		self.pv = [-1] * self.n
		self.pe = [-1] * self.n
		self.vis = [False] * self.n
		que = [s]
		self.dist[s] = 0
		while que:
			v = heapq.heappop(que) & 4294967295
			if self.vis[v]:
				continue
			self.vis[v] = True
			if v == t:
				break
			for i in range(len(self.g[v])):
				e = self.g[v][i]
				if self.vis[e.to] or e.cap == 0:
					continue
				cost = e.cost - self.dual[e.to] + self.dual[v]
				if self.dist[e.to] > self.dist[v] + cost:
					self.dist[e.to] = self.dist[v] + cost
					self.pv[e.to] = v
					self.pe[e.to] = i
					heapq.heappush(que, (self.dist[e.to] << 32) + e.to)
		if not self.vis[t]:
			return False
		for v in range(self.n):
			if not self.vis[v]:
				continue
			self.dual[v] -= self.dist[t] - self.dist[v]
		return True

	def slope(self, s, t, flow_limit=4294967295):
		self.dual = [0] * self.n
		self.dist = [4294967295] * self.n
		self.pv = [-1] * self.n
		self.pe = [-1] * self.n
		self.vis = [False] * self.n
		flow = 0
		cost = 0
		prev_cost = -1
		result = [(flow, cost)]
		while flow < flow_limit:
			if not self._dual_ref(s, t):
				break
			c = flow_limit - flow
			v = t
			while v != s:
				c = min(c, self.g[self.pv[v]][self.pe[v]].cap)
				v = self.pv[v]
			v = t
			while v != s:
				e = self.g[self.pv[v]][self.pe[v]]
				e.cap -= c
				self.g[v][e.rev].cap += c
				v = self.pv[v]
			d = -self.dual[s]
			flow += c
			cost += c * d
			if prev_cost == d:
				result.pop()
			result.append((flow, cost))
			prev_cost = cost
		return result

	def flow(self, s, t, flow_limit=4294967295):
		return self.slope(s, t, flow_limit)[-1]

	class _edge:

		def __init__(self, to, rev, cap, cost):
			self.to = to
			self.rev = rev
			self.cap = cap
			self.cost = cost
INF = 10 ** 9
n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
g = mcf_graph_int_cost(8)
g.add_edge(0, 1, a1, 0)
g.add_edge(0, 2, a2, 0)
g.add_edge(0, 3, a3, 0)
g.add_edge(4, 7, b1, 0)
g.add_edge(5, 7, b2, 0)
g.add_edge(6, 7, b3, 0)
for i in range(1, 4):
	for j in range(4, 7):
		cost = 1 if (j - i) % 3 == 1 else 0
		g.add_edge(i, j, INF, cost)
(f, ans1) = g.flow(0, 7)
ans2 = min(a1, b2) + min(a2, b3) + min(a3, b1)
print(ans1, ans2)


n = int(input())
(a1, b1, c1) = list(map(int, input().split()))
(a2, b2, c2) = list(map(int, input().split()))
d = min(a1, b2) + min(b1, c2) + min(c1, a2)
x = a1 - c2
y = b1 - a2
z = c1 - b2
e = max(0, x - a2, y - b2, z - c2)
print(e, d)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate, permutations
from functools import lru_cache
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
(rock1, sci1, paper1) = li()
(rock2, sci2, paper2) = li()

def maximum():
	ans = min(rock1, sci2) + min(sci1, paper2) + min(paper1, rock2)
	return ans

def match(a, b):
	if a == b:
		return 0
	elif (a, b) in [(1, 2), (2, 3), (3, 1)]:
		return 1
	else:
		return -1

def give(l1, l2):
	ans = 0
	curr1 = curr2 = 0
	while l1 or l2:
		try:
			if 0 == curr1:
				curr1 = l1.pop()
			if 0 == curr2:
				curr2 = l2.pop()
		except:
			return ans
		ans += max(0, min(curr1[0], curr2[0]) * match(curr1[1], curr2[1]))
		if curr1[0] < curr2[0]:
			curr2[0] -= curr1[0]
			curr1 = 0
		elif curr1[0] > curr2[0]:
			curr1[0] -= curr2[0]
			curr2 = 0
		else:
			curr1 = curr2 = 0
	return ans

def minimum():
	ans = n
	l = [[rock1, 1], [sci1, 2], [paper1, 3]]
	l1 = [list(i) for i in list(permutations(l))]
	l = [[rock2, 1], [sci2, 2], [paper2, 3]]
	l2 = [list(i) for i in list(permutations(l))]
	ans = float('inf')
	for i in l1:
		for j in l2:
			mylist1 = [temp[:] for temp in i]
			mylist2 = [temp[:] for temp in j]
			ans = min(ans, give(mylist1, mylist2))
	return ans
print(minimum(), maximum())


n = int(input())
l = input().split()
a1 = int(l[0])
a2 = int(l[1])
a3 = int(l[2])
l = input().split()
b1 = int(l[0])
b2 = int(l[1])
b3 = int(l[2])
ans = 0
ans += min(a1, b2)
ans += min(a2, b3)
ans += min(a3, b1)
ok = 0
ok += min(a1, b1 + b3)
ok += min(a2, b2 + b1)
ok += min(a3, b3 + b2)
print(n - ok, ans)


r = lambda : [*map(int, input().split())]
t = r()[0]
a = r()
b = r()
bmax = 0
x = sum((min(a[i], b[(i + 1) % 3]) for i in range(3)))
n = t - sum((min(a[i], t - b[(i + 1) % 3]) for i in range(3)))
print(n, x)


import sys

class Graph:
	verticies = {}
	nodesCount = 0

	class Vertex:

		def __init__(self, label):
			self.label = label
			self.edges = []
			self.visitedToken = 0

	class Edge:
		residual = None

		def __init__(self, from_, to_, isResidual, maxCapacity):
			self.from_ = from_
			self.to_ = to_
			self.isResidual = isResidual
			self.capacity = maxCapacity
			self.flow = 0

		def augment(self, bootleneck):
			self.flow += bootleneck
			self.residual.flow -= bootleneck

		def remainingCapacity(self):
			return self.capacity - self.flow

	def addEdge(self, from_, to_, capacity):
		from_ = self.verticies[from_]
		to_ = self.verticies[to_]
		main = self.Edge(from_, to_, False, capacity)
		residual = self.Edge(to_, from_, True, 0)
		main.residual = residual
		residual.residual = main
		from_.edges.append(main)
		to_.edges.append(residual)

	def addVertex(self, label):
		self.nodesCount += 1
		self.verticies[label] = self.Vertex(label)

	def maxFlow(self, f, t):
		f = self.verticies[f]
		t = self.verticies[t]
		visitedToken = 1
		flow = 0

		def dfs(node, bootleneck=sys.maxsize):
			node.visitedToken = visitedToken
			bootleneck_backup = bootleneck
			if node == t:
				return bootleneck
			for edge in node.edges:
				if edge.remainingCapacity() == 0 or edge.to_.visitedToken == visitedToken:
					continue
				bootleneck = dfs(edge.to_, min(bootleneck, edge.remainingCapacity()))
				if bootleneck:
					edge.augment(bootleneck)
					return bootleneck
				else:
					bootleneck = bootleneck_backup
			return 0
		while True:
			bootleneck = dfs(f)
			if not bootleneck:
				break
			flow += bootleneck
			visitedToken += 1
		return flow
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
g = Graph()
for i in range(0, 8):
	g.addVertex(i)
for i in range(3):
	g.addEdge(0, i + 1, a[i])
for i in range(3):
	g.addEdge(i + 4, 7, b[i])
g.addEdge(1, 4, a[0])
g.addEdge(1, 6, a[0])
g.addEdge(2, 4, a[1])
g.addEdge(2, 5, a[1])
g.addEdge(3, 5, a[2])
g.addEdge(3, 6, a[2])
print(n - g.maxFlow(0, 7), min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]))


from itertools import permutations
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxa = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
combi = ((0, 0), (1, 1), (2, 2), (0, 2), (1, 0), (2, 1))
mina = sys.maxsize
for i in permutations(combi):
	a1 = a[:]
	b1 = b[:]
	for j in i:
		x = min(a1[j[0]], b1[j[1]])
		a1[j[0]] -= x
		b1[j[1]] -= x
	mina = min(mina, min(a1[0], b1[1]) + min(a1[1], b1[2]) + min(a1[2], b1[0]))
print('%d %d' % (mina, maxa))


import sys

def input():
	return sys.stdin.readline()
n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total_parties = sum(a)

def max_wins(a, b):
	a = list(a)
	b = list(b)
	res = 0
	for i in range(-1, len(a) - 1):
		wins = min(a[i], b[i + 1])
		res += wins
		a[i] -= wins
		b[i + 1] -= wins
	return res

def max_not_wins(a, b):
	a = list(a)
	b = list(b)
	_max_res = 0
	res = 0
	pairs = [(0, -1), (1, 0), (2, 1), (0, 0), (1, 1), (2, 2)]

	def permutations(seq):
		if len(seq) == 1:
			return [seq]
		else:
			res = []
			for i in range(len(seq)):
				for perm in permutations(seq[:i] + seq[i + 1:]):
					new = [seq[i]] + perm
					res.append(new)
			return res

	def get_max(perm, a, b):
		a = list(a)
		b = list(b)
		res = 0
		for (i, j) in perm:
			not_wins = min(a[i], b[j])
			a[i] -= not_wins
			b[j] -= not_wins
			res += not_wins
		return res
	for perm in permutations(pairs):
		_max_res = max(_max_res, get_max(perm, a, b))
	return _max_res
print(sum(a) - max_not_wins(a, b), max_wins(a, b))


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxWin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
maxNotWin = min(a[0], b[0] + b[2]) + min(a[1], b[1] + b[0]) + min(a[2], b[2] + b[1])
minWin = 0
if maxNotWin < N:
	minWin = N - maxNotWin
print(str(minWin) + ' ' + str(maxWin))


def find_max_winning_rounds(p1, p2):
	result = 0
	for i in range(3):
		max_winnable = min(p1[i], p2[(i + 1) % 3])
		result += max_winnable
	return result

def calculate_max(p1, p2):
	result = 0
	for i in range(3):
		re = p1[i] - p2[i] - p2[(i + 2) % 3]
		result += max(0, re)
	return result
rounds = int(input())
player1_strategy = list(map(int, input().split()))
player2_strategy = list(map(int, input().split()))
print(calculate_max(player1_strategy, player2_strategy), find_max_winning_rounds(player1_strategy, player2_strategy))


n = int(input())
(a, b, c) = map(int, input().split())
(e, f, g) = map(int, input().split())
mx = min(a, f) + min(b, g) + min(c, e)
mn = max(0, a - e - g) + max(0, b - f - e) + max(0, c - f - g)
print(mn, mx)


n = int(input())
(ra, sa, pa) = map(int, input().split())
(rb, sb, pb) = map(int, input().split())
maxi = 0
maxi += min(ra, sb)
maxi += min(pa, rb)
maxi += min(sa, pb)
mini = 0
sa = sa - rb
if sa > 0:
	mini += max(0, sa - sb)
ra = ra - pb
if ra > 0:
	mini += max(0, ra - rb)
pa = pa - sb
if pa > 0:
	mini += max(0, pa - pb)
print(mini, maxi)


def main():
	_ = int(input())
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	mini = max(0, a - d - f) + max(0, b - e - d) + max(0, c - e - f)
	maxi = min(a, e) + min(b, f) + min(c, d)
	print(mini, maxi)
tn = 1
for _ in range(tn):
	main()


def solve():
	from itertools import permutations as perm
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxans = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	minans = 1e+18
	k = [(0, 0), (0, 2), (1, 1), (1, 0), (2, 1), (2, 2)]
	k = perm(k)
	for i in k:
		aa = a[:]
		bb = b[:]
		for j in range(6):
			u = i[j][0]
			v = i[j][1]
			val = min(aa[u], bb[v])
			aa[u] -= val
			bb[v] -= val
		ans = min(aa[0], bb[1]) + min(aa[1], bb[2]) + min(aa[2], bb[0])
		minans = min(minans, ans)
	print(minans, maxans)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


minimo = -1

def find_min(a_s, a_f, a_c, b_s, b_f, b_c, ordine, prossimo, antenato):
	global minimo
	if prossimo == 3:
		valore = max(a_s, a_f, a_c)
		if minimo < 0:
			minimo = valore
		elif valore < minimo:
			minimo = valore
	else:
		elem = ordine[prossimo]
		if elem == 's':
			(c_a_s, c_b_s, c_b_c) = (a_s, b_s, b_c)
			tmin = min(c_a_s, c_b_s)
			c_a_s -= tmin
			c_b_s -= tmin
			if c_a_s > 0:
				tmin = min(c_a_s, c_b_c)
				c_a_s -= tmin
				c_b_c -= tmin
			find_min(c_a_s, a_f, a_c, c_b_s, b_f, c_b_c, ordine, prossimo + 1, elem)
			tmin = min(a_s, b_c)
			a_s -= tmin
			b_c -= tmin
			if a_s > 0:
				tmin = min(a_s, b_s)
				a_s -= tmin
				b_s -= tmin
			find_min(a_s, a_f, a_c, b_s, b_f, b_c, ordine, prossimo + 1, elem)
		if elem == 'f':
			(c_a_f, c_b_f, c_b_s) = (a_f, b_f, b_s)
			tmin = min(c_a_f, c_b_f)
			c_a_f -= tmin
			c_b_f -= tmin
			if c_a_f > 0:
				tmin = min(c_a_f, c_b_s)
				c_a_f -= tmin
				c_b_s -= tmin
			find_min(a_s, c_a_f, a_c, c_b_s, c_b_f, b_c, ordine, prossimo + 1, elem)
			tmin = min(a_f, b_s)
			a_f -= tmin
			b_s -= tmin
			if a_f > 0:
				tmin = min(a_f, b_f)
				a_f -= tmin
				b_f -= tmin
			find_min(a_s, a_f, a_c, b_s, b_f, b_c, ordine, prossimo + 1, elem)
		if elem == 'c':
			(c_a_c, c_b_c, c_b_f) = (a_c, b_c, b_f)
			tmin = min(c_a_c, c_b_c)
			c_a_c -= tmin
			c_b_c -= tmin
			if c_a_c > 0:
				tmin = min(c_a_c, c_b_f)
				c_a_c -= tmin
				c_b_f -= tmin
			find_min(a_s, a_f, c_a_c, b_s, c_b_f, c_b_c, ordine, prossimo + 1, elem)
			tmin = min(a_c, b_f)
			a_c -= tmin
			b_f -= tmin
			if a_c > 0:
				tmin = min(a_c, b_c)
				a_c -= tmin
				b_c -= tmin
			find_min(a_s, a_f, a_c, b_s, b_f, b_c, ordine, prossimo + 1, elem)
n = int(input())
la = input().strip().split(' ')
lb = input().strip().split(' ')
(a_s, a_f, a_c) = (int(la[0]), int(la[1]), int(la[2]))
(b_s, b_f, b_c) = (int(lb[0]), int(lb[1]), int(lb[2]))
diz = {}
diz['s'] = [a_s, b_s]
diz['f'] = [a_f, b_f]
diz['c'] = [a_c, b_c]
ll = ['sfc', 'scf', 'fsc', 'csf', 'fcs', 'cfs']
for ordine in ll:
	find_min(a_s, a_f, a_c, b_s, b_f, b_c, list(ordine), 0, 'ORI')
massimo = 0
if a_s > b_f:
	massimo += b_f
else:
	massimo += a_s
if a_f > b_c:
	massimo += b_c
else:
	massimo += a_f
if a_c > b_s:
	massimo += b_s
else:
	massimo += a_c
print('%d %d' % (minimo, massimo))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict
sys.setrecursionlimit(300000)

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = N()
	(a1, a2, a3) = sep()
	(b1, b2, b3) = sep()
	ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
	mi = max(0, a1 - b1 - b3) + max(0, a2 - b2 - b1) + max(0, a3 - b3 - b2)
	print(mi, ma)
solve()


def ans(a1, a2, n):
	a_r = a1[0]
	a_s = a1[1]
	a_p = a1[2]
	b_r = a2[0]
	b_s = a2[1]
	b_p = a2[2]
	maxm = min(a_r, b_s) + min(a_s, b_p) + min(a_p, b_r)
	minm = n - (min(b_r, a_s + a_r) + min(b_s, a_p + a_s) + min(b_p, a_r + a_p))
	s = str(minm) + ' ' + str(maxm)
	return s
n = int(input())
arr1 = input().split()
a1 = []
arr2 = input().split()
a2 = []
for i in arr1:
	a1.append(int(i))
for i in arr2:
	a2.append(int(i))
print(ans(a1, a2, n))


import sys
from itertools import permutations
rounds = int(input())
(alice_rock, alice_scissors, alice_paper) = [int(x) for x in input().split()]
(bob_rock, bob_scissors, bob_paper) = [int(x) for x in input().split()]
max_wins_alice = min(alice_rock, bob_scissors) + min(alice_scissors, bob_paper) + min(alice_paper, bob_rock)
max_alice_not_wins = -sys.maxsize
for perm in permutations(range(6), 6):
	(alice_rock_s, alice_scissors_s, alice_paper_s) = (alice_rock, alice_scissors, alice_paper)
	(bob_rock_s, bob_scissors_s, bob_paper_s) = (bob_rock, bob_scissors, bob_paper)
	current_not_winning = 0
	for case in perm:
		if case == 0:
			m = min(bob_rock_s, alice_scissors_s)
			current_not_winning += m
			bob_rock_s -= m
			alice_scissors_s -= m
		elif case == 1:
			m = min(bob_scissors_s, alice_paper_s)
			current_not_winning += m
			bob_scissors_s -= m
			alice_paper_s -= m
		elif case == 2:
			m = min(bob_paper_s, alice_rock_s)
			current_not_winning += m
			bob_paper_s -= m
			alice_rock_s -= m
		elif case == 3:
			m = min(bob_rock_s, alice_rock_s)
			current_not_winning += m
			bob_rock_s -= m
			alice_rock_s -= m
		elif case == 4:
			m = min(bob_paper_s, alice_paper_s)
			current_not_winning += m
			bob_paper_s -= m
			alice_paper_s -= m
		elif case == 5:
			m = min(bob_scissors_s, alice_scissors_s)
			current_not_winning += m
			bob_scissors_s -= m
			alice_scissors_s -= m
	if current_not_winning > max_alice_not_wins:
		max_alice_not_wins = current_not_winning
print(' '.join([str(rounds - max_alice_not_wins), str(max_wins_alice)]))


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
mi = max(0, a1 - b1 - b3) + max(0, a2 - b1 - b2) + max(0, a3 - b2 - b3)
print(mi, ma)


n = int(input())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
max_a = min(l_a[0], l_b[1]) + min(l_a[1], l_b[2]) + min(l_a[2], l_b[0])
min_a = n - min(l_a[0], l_b[0] + l_b[2]) - min(l_a[1], l_b[0] + l_b[1]) - min(l_a[2], l_b[2] + l_b[1])
print(min_a, max_a)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
maxx = min(a1, b2) + min(a2, b3) + min(a3, b1)
miin = min(a1, n - b2) + min(a2, n - b3) + min(a3, n - b1)
miin = n - miin
print(miin, maxx)


n = int(input())
(a1, a2, a3) = [int(i) for i in input().split()]
(b1, b2, b3) = [int(i) for i in input().split()]
res = [0, 0]
winrock = min(a1, b2)
winsci = min(a2, b3)
winpap = min(a3, b1)
wins = winrock + winsci + winpap
res[1] = str(wins)
r = a1 - (b1 + b3)
s = a2 - (b1 + b2)
p = a3 - (b2 + b3)
losrock = 0
lossci = 0
lospap = 0
if r > 0:
	losrock = r
if s > 0:
	lossci = s
if p > 0:
	lospap = p
los = losrock + lossci + lospap
res[0] = str(los)
print(' '.join(res))


import math
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mi = 0
	(ar, ass, ap) = (a[0], a[1], a[2])
	(br, bss, bp) = (b[0], b[1], b[2])
	ar = max(ar - br, 0)
	ass = max(ass - bss, 0)
	ap = max(ap - bp, 0)
	rock = min(ar, bp)
	ar -= rock
	bp -= rock
	paper = min(ap, bss)
	ap -= paper
	bss -= paper
	sci = min(ass, br)
	ass -= sci
	br -= sci
	mi = ar + ass + ap
	ma = 0
	(ar, ass, ap) = (a[0], a[1], a[2])
	(br, bss, bp) = (b[0], b[1], b[2])
	rock = min(ar, bss)
	ar -= rock
	bss -= rock
	paper = min(ap, br)
	ap -= paper
	br -= paper
	sci = min(ass, bp)
	ass -= sci
	bp -= sci
	ma = rock + paper + sci
	print(mi, ma)


import itertools
n = int(input())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
fc = f[:]
sc = s[:]
win = 0
mWin = 999999999999999

def func(i, g):
	m = min(f[i], s[g])
	f[i] -= m
	s[g] -= m
	return m
win += func(0, 1)
win += func(1, 2)
win += func(2, 0)
perms = list(itertools.permutations([[0, 2], [1, 0], [2, 1], [0, 0], [1, 1], [2, 2]]))
for i in range(len(perms)):
	now = 0
	f = fc[:]
	s = sc[:]
	for g in range(6):
		m = min(f[perms[i][g][0]], s[perms[i][g][1]])
		f[perms[i][g][0]] -= m
		s[perms[i][g][1]] -= m
	now = min(f[0], s[1]) + min(f[1], s[2]) + min(f[2], s[0])
	mWin = min(mWin, now)
print(mWin, win)


n = int(input())
(x1, x2, x3) = map(int, input().split())
(y1, y2, y3) = map(int, input().split())
(max1, min1) = (min(x1, y2) + min(x2, y3) + min(x3, y1), 0)
if x1 > y1 + y3:
	min1 = x1 - y1 - y3
elif x2 > y2 + y1:
	min1 = x2 - y1 - y2
elif x3 > y3 + y2:
	min1 = x3 - y3 - y2
print(min1, max1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
a = min(a1, b1 + b3)
b = min(a2, b2 + b1)
c = min(a3, b3 + b2)
mi = n - a - b - c
print(mi, ma)


n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
maxwin = 0
for i in range(len(alice)):
	if i == 0:
		if alice[i] >= bob[1]:
			maxwin += bob[1]
		else:
			maxwin += alice[i]
	elif i == 1:
		if alice[i] >= bob[2]:
			maxwin += bob[2]
		else:
			maxwin += alice[i]
	elif i == 2:
		if alice[i] >= bob[0]:
			maxwin += bob[0]
		else:
			maxwin += alice[i]
minwin = 0
for j in range(len(alice)):
	if j == 0:
		if alice[j] > bob[2] + bob[0]:
			minwin += alice[j] - bob[2] - bob[0]
	elif j == 1:
		if alice[j] > bob[1] + bob[0]:
			minwin += alice[j] - bob[0] - bob[1]
	elif j == 2:
		if alice[j] > bob[1] + bob[2]:
			minwin += alice[j] - bob[1] - bob[2]
if minwin < 0:
	print(minwin)
	minwin = 0
print(minwin, maxwin)


n = int(input())
(a1, a2, a3) = list(map(int, input().split(' ')))
(b1, b2, b3) = list(map(int, input().split(' ')))
largest = min(a1, b2) + min(a2, b3) + min(a3, b1)
smallest = max(0, -(b3 + b1) + a1) + max(0, -(b1 + b2) + a2) + max(0, -(b2 + b3) + a3)
print(smallest, largest)


def main():
	n = int(input())
	(r2, s2, p2) = map(int, input().split())
	(r1, s1, p1) = map(int, input().split())
	ma = min(r1, p2) + min(s1, r2) + min(p1, s2)
	if s2 >= r1 + s1:
		mi = s2 - r1 - s1
	else:
		mi = n
		k1 = max(0, s2 - s1)
		k2 = min(r1, s2)
		c1 = r1 - r2
		c2 = p2 - s1 + s2
		if k1 <= c1:
			mi = c1 - min(k2, c1)
		if k2 >= c2:
			mi = min(mi, max(k1, c2) - c2)
		if c2 > c1 + 1 and (c2 > k1 and c1 < k2) or (k1 > c1 and k2 < c2):
			mi = 0
	print(mi, ma)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acopy = a.copy()
bcopy = b.copy()
ans = []
p = 0
for i in range(3):
	p = max(p, a[i] - b[i] - b[i - 1])
ans.append(str(p))
acopy = a.copy()
bcopy = b.copy()
p = 0
for i in range(3):
	t = min(acopy[i - 1], bcopy[i])
	p += t
ans.append(str(p))
print(' '.join(ans))


import math
import sys
from sys import stdin, stdout
ipi = lambda : int(stdin.readline())
ipil = lambda : map(int, stdin.readline().split())
ipf = lambda : float(stdin.readline())
ipfl = lambda : map(float, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
outl = lambda x: print(*x)
n = ipi()
(a1, a2, a3) = ipil()
(b1, b2, b3) = ipil()
print(max(0, a1 - b1 - b3) + max(0, a2 - b2 - b1) + max(0, a3 - b3 - b2))
print(min(a1, b2) + min(a2, b3) + min(a3, b1))


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
min_wins = n - (min(a1, n - b2) + min(a2, n - b3) + min(a3, n - b1))
max_wins = min(a1, b2) + min(a2, b3) + min(a3, b1)
print(min_wins, max_wins)


from math import ceil, sqrt
from collections import defaultdict
from itertools import permutations
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ans1 = 10 ** 18
ans2 = min(a1, b2) + min(a2, b3) + min(a3, b1)
per = [['a1', 'b1'], ['a2', 'b2'], ['a3', 'b3'], ['a1', 'b3'], ['a2', 'b1'], ['a3', 'b2']]
z = permutations(per)
for i in z:
	(x1, x2, x3) = (a1, a2, a3)
	(y1, y2, y3) = (b1, b2, b3)
	for (a, b) in i:
		if a == 'a1' and b == 'b1':
			z = min(x1, y1)
			x1 -= z
			y1 -= z
		if a == 'a2' and b == 'b2':
			z = min(x2, y2)
			x2 -= z
			y2 -= z
		if a == 'a3' and b == 'b3':
			z = min(x3, y3)
			x3 -= z
			y3 -= z
		if a == 'a1' and b == 'b3':
			z = min(x1, y3)
			x1 -= z
			y3 -= z
		if a == 'a2' and b == 'b1':
			z = min(x2, y1)
			x2 -= z
			y1 -= z
		if a == 'a3' and b == 'b2':
			z = min(x3, y2)
			x3 -= z
			y2 -= z
	ans1 = min(ans1, x1 + x2 + x3)
print(ans1, ans2)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
a = [a1, a2, a3]
b = [b1, b2, b3]
win = {0: b2, 1: b3, 2: b1}
loss = {0: [b1, b3], 1: [b1, b2], 2: [b2, b3]}
ma1 = -1
pos1 = -1
for i in range(len(a)):
	if ma1 < a[i]:
		ma1 = a[i]
		pos1 = i
result = 0
result = min(ma1, win[pos1])
ma2 = -1
pos2 = -1
for i in range(len(a)):
	if ma2 < a[i] and i != pos1:
		ma2 = a[i]
		pos2 = i
result = result + min(ma2, win[pos2])
ma3 = -1
pos3 = -1
for i in range(len(a)):
	if i != pos1 and i != pos2:
		ma3 = a[i]
		pos3 = i
result = result + min(ma3, win[pos3])
mi = 0
for i in range(len(loss[pos1])):
	if loss[pos1][i] <= ma1:
		ma1 = ma1 - loss[pos1][i]
		loss[pos1][i] = 0
	else:
		ma1 = ma1 - loss[pos1][i]
		loss[pos1][i] = loss[pos1][i] - ma1
if ma1 > 0:
	mi += ma1
for i in range(len(loss[pos1])):
	if loss[pos2][i] <= ma2:
		ma2 = ma2 - loss[pos2][i]
		loss[pos2][i] = 0
	else:
		ma2 = ma2 - loss[pos2][i]
		loss[pos2][i] = loss[pos2][i] - ma2
if ma2 > 0:
	mi += ma2
for i in range(len(loss[pos1])):
	if loss[pos3][i] <= ma3:
		ma3 = ma3 - loss[pos3][i]
		loss[pos3][i] = 0
	else:
		ma3 = ma3 - loss[pos3][i]
		loss[pos3][i] = loss[pos3][i] - ma3
if ma3 > 0:
	mi += ma3
print(mi, result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mins = max(0, b[0] - a[0] - a[1], b[1] - a[1] - a[2], b[2] - a[2] - a[0])
maxs = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(mins, maxs)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
(a1, a3, a2) = a
(b1, b3, b2) = b
wins = 0
t = min(a1, b3)
wins += t
a1 -= t
b3 -= t
t = min(a2, b1)
wins += t
a2 -= t
b1 -= t
t = min(a3, b2)
wins += t
a3 -= t
b2 -= t
maxx = wins

def f(a1, a3, a2, b1, b3, b2, flag):
	if flag == 1:
		t = min(a1, b3)
		a1 -= t
		b3 -= t
	if flag == 2:
		t = min(a1, b1)
		a1 -= t
		b1 -= t
	if flag == 3:
		t = min(a3, b3)
		a3 -= t
		b3 -= t
	if flag == 4:
		t = min(a3, b2)
		a3 -= t
		b2 -= t
	if flag == 5:
		t = min(a2, b1)
		a2 -= t
		b1 -= t
	if flag == 6:
		t = min(a2, b2)
		a2 -= t
		b2 -= t
	return (a1, a3, a2, b1, b3, b2)
import itertools
perms = list(itertools.permutations([1, 2, 3, 4, 5, 6]))
wins = float('inf')
for perm in perms:
	(b1, b3, b2) = a
	(a1, a3, a2) = b
	for num in perm:
		(a1, a3, a2, b1, b3, b2) = f(a1, a3, a2, b1, b3, b2, num)
	wins = min(wins, min(a1, b2) + min(a2, b3) + min(a3, b1))
minn = wins
print(minn, maxx)


no = int(input())
(alice_rock, alice_scissors, alice_paper) = list(map(int, input().split()))
(bob_rock, bob_scissors, bob_paper) = list(map(int, input().split()))
my_max = min(alice_rock, bob_scissors) + min(alice_scissors, bob_paper) + min(alice_paper, bob_rock)
my_min = min(alice_rock, no - bob_scissors) + min(alice_scissors, no - bob_paper) + min(alice_paper, no - bob_rock)
print(no - my_min, my_max)


round = int(input())
firstperson = input().split(' ')
secondperson = input().split(' ')

def solve(round, firstperson, secondperson):
	win = 0
	secondperson.append(secondperson[0])
	for i in range(len(firstperson)):
		if int(firstperson[i]) <= int(secondperson[i + 1]):
			findless = int(firstperson[i])
		else:
			findless = int(secondperson[i + 1])
		win += findless
	del secondperson[3]
	secondperson.insert(0, secondperson[2])
	for i in range(len(firstperson)):
		if int(firstperson[i]) > 0:
			diff = min(int(firstperson[i]), int(secondperson[i]))
			firstperson[i] = int(firstperson[i]) - int(diff)
			secondperson[i] = int(secondperson[i]) - int(diff)
			if int(firstperson[i]) > 0:
				diff = min(int(firstperson[i]), int(secondperson[i + 1]))
				firstperson[i] = int(firstperson[i]) - int(diff)
				secondperson[i + 1] = int(secondperson[i + 1]) - int(diff)
	print(str(int(firstperson[0]) + int(firstperson[1]) + int(firstperson[2])) + ' ' + str(win))
solve(round, firstperson, secondperson)


from math import *
t = 1
while t:
	t = t - 1
	n = int(input())
	(ra, sa, pa) = map(int, input().split())
	(rb, sb, pb) = map(int, input().split())
	mx = min(ra, sb) + min(sa, pb) + min(pa, rb)
	mn = max(0, ra - rb - pb) + max(0, sa - sb - rb) + max(0, pa - pb - sb)
	print(mn, mx)


from sys import stdin, stdout

def find(A, B, N):
	X = min(A[0], B[1])
	Y = min(A[1], B[2])
	Z = min(A[2], B[0])
	P = min(A[0], B[2] + B[0])
	Q = min(A[1], B[1] + B[0])
	R = min(A[2], B[2] + B[1])
	return (N - (P + Q + R), X + Y + Z)

def main():
	N = int(stdin.readline())
	A = list(map(int, stdin.readline().split()))
	B = list(map(int, stdin.readline().split()))
	print(' '.join(map(str, find(A, B, N))))
main()


n = int(input())
(a1, a2, a3) = [int(p) for p in input().split()]
(b1, b2, b3) = [int(p) for p in input().split()]
mx = 0
mx += min(a1, b2) + min(a2, b3) + min(a3, b1)
mn = 0
if a1 >= b1 + b3:
	mn = a1 - b1 - b3
elif a2 >= b2 + b1:
	mn = a2 - b1 - b2
elif a3 >= b3 + b2:
	mn = a3 - b3 - b2
else:
	mn = 0
print(mn, mx)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxans = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	minans = max(a[0] - b[0] - b[2], a[1] - b[1] - b[0], a[2] - b[1] - b[2], 0)
	print(minans, maxans)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
n = L()[0]
d1 = {}
d2 = {}
A = L()
d1['R'] = A[0]
d1['S'] = A[1]
d1['P'] = A[2]
A = L()
d2['R'] = A[0]
d2['S'] = A[1]
d2['P'] = A[2]
ansmn = 10 ** 10
for p in list(perm(['R', 'S', 'P'])):
	d2cur = d2.copy()
	d1cur = d1.copy()
	curmn = 0
	for ele in p:
		if ele == 'R':
			f1 = min(d1cur[ele], d2cur['P'])
			d1cur[ele] -= f1
			d2cur['P'] -= f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['R'])
				d1cur[ele] -= f2
				d2cur['R'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['S'])
					d1cur[ele] -= f2
					d2cur['S'] -= f2
					curmn += f2
		elif ele == 'S':
			f1 = min(d1cur[ele], d2cur['R'])
			d1cur[ele] -= f1
			d2cur['R'] -= f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['S'])
				d1cur[ele] -= f2
				d2cur['S'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['P'])
					d1cur[ele] -= f2
					d2cur['P'] -= f2
					curmn += f2
		elif ele == 'P':
			f1 = min(d1cur[ele], d2cur['S'])
			d1cur[ele] -= f1
			d2cur['S'] -= f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['P'])
				d1cur[ele] -= f2
				d2cur['P'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['R'])
					d1cur[ele] -= f2
					d2cur['R'] -= f2
					curmn += f2
	ansmn = min(ansmn, curmn)
ansmax = 0
for p in list(perm(['R', 'S', 'P'])):
	d2cur = d2.copy()
	d1cur = d1.copy()
	curmn = 0
	for ele in p:
		if ele == 'R':
			f1 = min(d1cur[ele], d2cur['S'])
			d1cur[ele] -= f1
			d2cur['S'] -= f1
			curmn += f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['R'])
				d1cur[ele] -= f2
				d2cur['R'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['P'])
					d1cur[ele] -= f2
					d2cur['P'] -= f2
		elif ele == 'S':
			f1 = min(d1cur[ele], d2cur['P'])
			d1cur[ele] -= f1
			d2cur['P'] -= f1
			curmn += f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['S'])
				d1cur[ele] -= f2
				d2cur['S'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['R'])
					d1cur[ele] -= f2
					d2cur['R'] -= f2
		elif ele == 'P':
			f1 = min(d1cur[ele], d2cur['R'])
			d1cur[ele] -= f1
			d2cur['R'] -= f1
			curmn += f1
			if d1cur[ele] != 0:
				f2 = min(d1cur[ele], d2cur['P'])
				d1cur[ele] -= f2
				d2cur['P'] -= f2
				if d1cur[ele] != 0:
					f2 = min(d1cur[ele], d2cur['S'])
					d1cur[ele] -= f2
					d2cur['S'] -= f2
	ansmax = max(ansmax, curmn)
print(ansmn, ansmax)
endtime = time.time()


n = int(input())
(a1, a2, a3) = [int(x) for x in input().split()]
(b1, b2, b3) = [int(x) for x in input().split()]
maxNum = min(a1, b2) + min(a2, b3) + min(a3, b1)
minNum = max(a1 - b1 - b3, a2 - b1 - b2, a3 - b3 - b2)
if minNum < 0:
	print(0, maxNum)
else:
	print(minNum, maxNum)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : list(map(int, input().strip().split()))
mulf = lambda : list(map(float, input().strip().split()))
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
n = stdint()
(a1, a2, a3) = stdarr()
(b1, b2, b3) = stdarr()
mi = 0
ma = 0
wi = min(a1, b2)
re = max(a1 - wi, 0)
draw = min(re, b1)
re = re - draw
lose = min(re, b3)
ma += wi
wi = min(a2, b3)
re = max(a2 - wi, 0)
draw = min(re, b2)
re = re - draw
lose = min(re, b1)
ma += wi
wi = min(a3, b1)
re = max(a3 - wi, 0)
draw = min(re, b3)
re = re - draw
lose = min(re, b2)
ma += wi
l1 = min(a1, b3)
re = max(a1 - l1, 0)
draw = min(re, b1)
wi = min(re - draw, b2)
mi += wi
l1 = min(a2, b1)
re = max(a2 - l1, 0)
draw = min(re, b2)
wi = min(re - draw, b3)
mi += wi
l1 = min(a3, b2)
re = max(a3 - l1, 0)
draw = min(re, b3)
wi = min(re - draw, b1)
mi += wi
print(mi, ma)


from itertools import permutations

def rsp(a, b):
	t = a.copy()
	t2 = b.copy()
	maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	lst = [[0, 0], [1, 1], [2, 2], [0, 2], [2, 1], [1, 0]]
	mini = float('inf')
	for l in list(permutations(lst)):
		a = t.copy()
		b = t2.copy()
		for i in l:
			if a[i[0]] > b[i[1]]:
				a[i[0]] -= b[i[1]]
				b[i[1]] = 0
			else:
				b[i[1]] -= a[i[0]]
				a[i[0]] = 0
		mini = min(mini, sum(a))
	print(mini, maxi)
	return ''
x = input()
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
print(rsp(a, b))


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
if a[0] > b[0] + b[2]:
	mn = a[0] - b[0] - b[2]
elif a[1] > b[0] + b[1]:
	mn = a[1] - b[0] - b[1]
elif a[2] > b[1] + b[2]:
	mn = a[2] - b[1] - b[2]
else:
	mn = 0
print(mn, mx)


import sys
input = sys.stdin.readline
n = int(input())
(a1, a2, a3) = [int(i) for i in input().split()]
(b1, b2, b3) = [int(i) for i in input().split()]
min_res = n + 1
max_res = -1

def rec(a1, a2, a3, b1, b2, b3, cur_res):
	if min(a1, b2) == min(a2, b3) == min(a3, b1) == min(b1, a2) == min(b2, a3) == min(b3, a1) == 0:
		global min_res, max_res
		min_res = min(min_res, cur_res)
		max_res = max(max_res, cur_res)
		return
	if a1 != 0 and b1 != 0:
		rec(max(a1 - b1, 0), a2, a3, max(b1 - a1, 0), b2, b3, cur_res)
	if a2 != 0 and b2 != 0:
		rec(a1, max(a2 - b2, 0), a3, b1, max(b2 - a2, 0), b3, cur_res)
	if a3 != 0 and b3 != 0:
		rec(a1, a2, max(a3 - b3, 0), b1, b2, max(b3 - a3, 0), cur_res)
	if a1 != 0 and b2 != 0:
		rec(max(a1 - b2, 0), a2, a3, b1, max(b2 - a1, 0), b3, cur_res + min(a1, b2))
	if a2 != 0 and b1 != 0:
		rec(a1, max(0, a2 - b1), a3, max(0, b1 - a2), b2, b3, cur_res)
	if a2 != 0 and b3 != 0:
		rec(a1, max(0, a2 - b3), a3, b1, b2, max(0, b3 - a2), cur_res + min(a2, b3))
	if a3 != 0 and b2 != 0:
		rec(a1, a2, max(0, a3 - b2), b1, max(0, b2 - a3), b3, cur_res)
	if a3 != 0 and b1 != 0:
		rec(a1, a2, max(a3 - b1, 0), max(b1 - a3, 0), b2, b3, cur_res + min(a3, b1))
	if a1 != 0 and b3 != 0:
		rec(max(0, a1 - b3), a2, a3, b1, b2, max(0, b3 - a1), cur_res)
rec(a1, a2, a3, b1, b2, b3, 0)
print(min_res, max_res)


n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
maxmum = min(a1, b2) + min(a2, b3) + min(a3, b1)
minimum = max(0, a1 - b1 - b3, a2 - b2 - b1, a3 - b3 - b2)
print(minimum, maxmum)


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	n = inp()
	(a, b, c) = ma()
	(a1, b1, c1) = ma()
	ma = min(a, b1) + min(b, c1) + min(c, a1)
	mi = max(0, a - a1 - c1, b - a1 - b1, c - b1 - c1)
	print(mi, ma)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
mm = min(l[0], d[1]) + min(l[1], d[2]) + min(d[0], l[2])
x = min(l[0], n - d[1]) + min(l[1], n - d[2]) + min(l[2], n - d[0])
print(n - x, mm)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import defaultdict
from pprint import pprint
from math import ceil

def f(a, b, c, y, z, x):
	m = min(x, a)
	a -= m
	x -= m
	m = min(z, a)
	a -= m
	z -= m
	m = min(x, b)
	b -= m
	x -= m
	m = min(y, b)
	b -= m
	y -= m
	m = min(z, c)
	c -= m
	z -= m
	m = min(y, c)
	c -= m
	y -= m
	return a + b + c

def main():
	n = int(input())
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	mx_win = min(a, y) + min(b, z) + min(c, x)
	mi_win = min(float('inf'), f(a, b, c, y, z, x))
	mi_win = min(mi_win, f(a, c, b, y, x, z))
	mi_win = min(mi_win, f(b, a, c, z, y, x))
	mi_win = min(mi_win, f(b, c, a, z, x, y))
	mi_win = min(mi_win, f(c, a, b, x, y, z))
	mi_win = min(mi_win, f(c, b, a, x, z, y))
	print(mi_win, mx_win)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(1):
	main()


r = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c1 = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
l = [[0, 0], [1, 1], [2, 2], [0, 2], [1, 0], [2, 1]]
c2 = 2 ** 32
from itertools import permutations
import copy
l = permutations(l)
perm = []
for e in l:
	a1 = copy.deepcopy(a)
	b1 = copy.deepcopy(b)
	for ele in e:
		x = ele[0]
		y = ele[1]
		cnt = min(a1[x], b1[y])
		a1[x] -= cnt
		b1[y] -= cnt
	ans = min(a1[0], b1[1]) + min(a1[1], b1[2]) + min(a1[2], b1[0])
	c2 = min(c2, ans)
print(f'{c2} {c1}')


import itertools
import copy
n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
max_wins = 0
max_wins += min(alice[0], bob[1])
max_wins += min(alice[1], bob[2])
max_wins += min(alice[2], bob[0])
permutations = itertools.permutations(((0, 0), (0, 2), (1, 1), (1, 0), (2, 2), (2, 1)))
min_wins = n
for permutation in permutations:
	temp_alice = copy.deepcopy(alice)
	temp_bob = copy.deepcopy(bob)
	wins = n
	for combination in permutation:
		lower = min(temp_alice[combination[0]], temp_bob[combination[1]])
		temp_alice[combination[0]] -= lower
		temp_bob[combination[1]] -= lower
		wins -= lower
	min_wins = min(min_wins, wins)
print(min_wins, max_wins)


import itertools
n = int(input())
(r, s, p) = map(int, input().split())
(R, S, P) = map(int, input().split())
win_r = min(r, S)
win_s = min(s, P)
win_p = min(p, R)
win = win_r + win_s + win_p
res = n
for perm in itertools.permutations(range(6)):
	(rr, ss, pp) = (r, s, p)
	(RR, SS, PP) = (R, S, P)
	asd = n
	for i in perm:
		if i == 0:
			mn = min(rr, RR)
			rr -= mn
			RR -= mn
		if i == 1:
			mn = min(ss, SS)
			ss -= mn
			SS -= mn
		if i == 2:
			mn = min(pp, PP)
			pp -= mn
			PP -= mn
		if i == 3:
			mn = min(rr, PP)
			rr -= mn
			PP -= mn
		if i == 4:
			mn = min(ss, RR)
			ss -= mn
			RR -= mn
		if i == 5:
			mn = min(pp, SS)
			pp -= mn
			SS -= mn
		asd -= mn
	res = min(asd, res)
print(res, win)


from itertools import permutations
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
ordi = [[0, 0], [0, 2], [1, 1], [1, 0], [2, 2], [2, 1]]
d = list(permutations(ordi))
mini = float('inf')
j = 0
while j < len(d):
	ordi = d[j]
	a1 = a[:]
	b1 = b[:]
	for i in range(len(ordi)):
		cnt = min(a1[ordi[i][0]], b1[ordi[i][1]])
		a1[ordi[i][0]] -= cnt
		b1[ordi[i][1]] -= cnt
	curr = min(a1[0], b1[1]) + min(a1[1], b1[2]) + min(a1[2], b1[0])
	mini = min(mini, curr)
	j += 1
print(mini, maxi)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ans1 = min(a1, b2) + min(a2, b3) + min(a3, b1)
ans2 = n - (min(a1, n - b2) + min(a2, n - b3) + min(a3, n - b1))
print(str(ans2) + ' ' + str(ans1))


rw = 1
for wewq in range(rw):
	n = int(input())
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	a = [a1, a2, a3]
	b = [b1, b2, b3]
	f = 0
	t = min(a1, b2)
	f += t
	a1 -= t
	b2 -= t
	t = min(a2, b3)
	f += t
	a2 -= t
	b3 -= t
	t = min(a3, b1)
	f += t
	a3 -= t
	b1 -= t
	wins = f
	(a1, a2, a3) = a
	(b1, b2, b3) = b
	f = 0
	d1 = a1 - b1
	d2 = a2 - b2
	d3 = a3 - b3
	if d1 < 0 - a2:
		f += -d1 - a2
		a1 = 0
		a2 = 0
	d2 = a2 - b2
	d3 = a3 - b3
	if d2 < 0 - a3:
		f += -d2 - a3
		a2 = 0
		a3 = 0
	d3 = a3 - b3
	if d3 < 0 - a1:
		f += -d3 - a1
	print(f, wins)


import sys
infile = sys.stdin
n = infile.readline()
a = list(map(int, infile.readline().split()))
b = list(map(int, infile.readline().split()))
maxi = 0
if min(a[0], b[1]) != 0:
	maxi += min(a[0], b[1])
if min(a[1], b[2]) != 0:
	maxi += min(a[1], b[2])
if min(a[2], b[0]) != 0:
	maxi += min(a[2], b[0])
aans = []
for i in range(3):
	am = a.index(max(a))
	if am == 0:
		bm = 2
	else:
		bm = am - 1
	if b[bm] > b[am]:
		a[am] = max(a[am] - b[bm], 0)
		b[bm] = abs(min(a[am] - b[bm], 0))
		if a[am] > 0:
			a[am] = max(a[am] - b[am], 0)
			b[am] = abs(min(a[am] - b[am], 0))
	else:
		a[am] = max(a[am] - b[am], 0)
		b[am] = abs(min(a[am] - b[am], 0))
		if a[am] > 0:
			a[am] = max(a[am] - b[bm], 0)
			b[bm] = abs(min(a[am] - b[bm], 0))
	aans.append(a[am])
	a[am] = 0
ans = aans[0] + aans[1] + aans[2]
print(ans, maxi)


from itertools import permutations as perms
gw = {'k': 'n', 'n': 'b', 'b': 'k'}

def get(a, b):
	na = [i.copy() for i in a]
	nb = [i.copy() for i in b]
	res = 0
	i = j = 0
	while i < 3 and j < 3:
		if na[i][0] == 0:
			i += 1
		elif nb[j][0] == 0:
			j += 1
		elif na[i][0] <= nb[j][0]:
			res += (nb[j][1] == gw[a[i][1]]) * na[i][0]
			nb[j][0] -= na[i][0]
			na[i][0] = 0
			i += 1
		else:
			res += (nb[j][1] == gw[na[i][1]]) * nb[j][0]
			na[i][0] -= nb[j][0]
			nb[j][0] = 0
			j += 1
	return res
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ans1 = 10 ** 10
ans2 = 0
for pa in perms([[a1, 'k'], [a2, 'n'], [a3, 'b']]):
	for pb in perms([[b1, 'k'], [b2, 'n'], [b3, 'b']]):
		res = get(pa, pb)
		ans1 = min(ans1, res)
		ans2 = max(ans2, res)
print(ans1, ans2)


(n, arr1, arr2) = (int(input()), [int(i) for i in input().split()], [int(i) for i in input().split()])
ma = 0
(a, b) = ([], [])
for i in range(10):
	a.append(arr1)
	b.append(arr2)
ma += min([arr1[0], arr2[1]])
ma += min([arr1[1], arr2[2]])
ma += min([arr1[2], arr2[0]])
mi = n + 1
for x in range(2):
	for y in range(2):
		for z in range(2):
			(aa, bb) = (a[x * 4 + y * 2 + z], b[x * 4 + y * 2 + z])
			(xx, yy, zz) = (min([aa[0], bb[0]]), min([aa[1], bb[1]]), min([aa[2], bb[2]]))
			m = [0] * 10
			if x == 0:
				m[0] -= xx
				m[3] -= xx
			if y == 0:
				m[1] -= yy
				m[4] -= yy
			if z == 0:
				m[2] -= zz
				m[5] -= zz
			(xx, yy, zz) = (min([aa[0] + m[0], bb[2] + m[5]]), min([aa[1] + m[1], bb[0] + m[3]]), min([aa[2] + m[2], bb[1] + m[4]]))
			m[0] -= xx
			m[1] -= yy
			m[2] -= zz
			m[3] -= yy
			m[4] -= zz
			m[5] -= xx
			t = 0
			(xx, yy, zz) = (min([aa[0] + m[0], bb[0] + m[3]]), min([aa[1] + m[1], bb[1] + m[4]]), min([aa[2] + m[2], bb[2] + m[5]]))
			m[0] -= xx
			m[3] -= xx
			m[1] -= yy
			m[4] -= yy
			m[2] -= zz
			m[5] -= zz
			t += min([aa[0] + m[0], bb[1] + m[4]])
			t += min([aa[1] + m[1], bb[2] + m[5]])
			t += min([aa[2] + m[2], bb[0] + m[3]])
			mi = min([mi, t])
print(mi, ma)


from collections import deque
inf = float('inf')

class Graph:

	def __init__(self, graph):
		self.graph = [i.copy() for i in graph]
		self.n = len(graph)

	def bfs(self, s, t, par):
		vis = [False] * self.n
		q = deque([s])
		vis[s] = True
		while q:
			u = q.popleft()
			for (ind, val) in enumerate(self.graph[u]):
				if vis[ind] == False and val > 0:
					q.append(ind)
					vis[ind] = True
					par[ind] = u
					if ind == t:
						return True
		return False

	def FordFulkerson(self, source, sink):
		par = [-1] * self.n
		max_flow = 0
		while self.bfs(source, sink, par):
			path_flow = float('inf')
			s = sink
			while s != source:
				path_flow = min(path_flow, self.graph[par[s]][s])
				s = par[s]
			max_flow += path_flow
			v = sink
			while v != source:
				u = par[v]
				self.graph[u][v] -= path_flow
				self.graph[v][u] += path_flow
				v = u
		return max_flow
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
g1 = [[0, inf, inf, inf, 0, 0], [0, 0, 0, 0, a1, 0, a1, 0], [0, 0, 0, 0, a2, a2, 0, 0], [0, 0, 0, 0, 0, a3, a3, 0], [0, 0, 0, 0, 0, 0, 0, b1], [0, 0, 0, 0, 0, 0, 0, b2], [0, 0, 0, 0, 0, 0, 0, b3], [0, 0, 0, 0, 0, 0, 0, 0]]
g2 = [[0, inf, inf, inf, 0, 0], [0, 0, 0, 0, 0, a1, 0, 0], [0, 0, 0, 0, 0, 0, a2, 0], [0, 0, 0, 0, a3, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, b1], [0, 0, 0, 0, 0, 0, 0, b2], [0, 0, 0, 0, 0, 0, 0, b3], [0, 0, 0, 0, 0, 0, 0, 0]]
g = Graph(g1)
ans1 = g.FordFulkerson(0, 7)
g = Graph(g2)
ans2 = g.FordFulkerson(0, 7)
print(n - ans1, ans2)


n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
m1 = min(a1, b2) + min(a2, b3) + min(a3, b1)
an = max(0, a1 + b2 - n, a2 + b3 - n, a3 + b1 - n)
print(an, m1)


def main():
	input()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans1 = max(0, b[1] - a[1] - a[2], b[2] - a[2] - a[0], b[0] - a[0] - a[1])
	ans2 = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	print('{} {}'.format(ans1, ans2))
main()


input()
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(max(0, a[0] - b[0] - b[2], a[1] - b[1] - b[0], a[2] - b[2] - b[1]), min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]))


import sys
n = int(input())
(AR, AS, AP) = map(int, sys.stdin.readline().split())
(BR, BS, BP) = map(int, sys.stdin.readline().split())
maxwin = min(AR, BS) + min(AS, BP) + min(AP, BR)
minwin = 0
A_list = [AR, AS, AP]
B_list = [BS, BP, BR]
if max(A_list) < max(B_list):
	A_list = [BS, BP, BR]
	B_list = [AR, AS, AP]
big1 = max(A_list)
big1index = A_list.index(big1)
if big1index == 0 and B_list[0] >= A_list[1] + A_list[2] or (big1index == 1 and B_list[1] >= A_list[0] + A_list[2]) or (big1index == 2 and B_list[2] >= A_list[1] + A_list[0]):
	if big1index == 0:
		minwin = B_list[0] - A_list[1] - A_list[2]
	elif big1index == 1:
		minwin = B_list[1] - A_list[2] - A_list[0]
	elif big1index == 2:
		minwin = B_list[2] - A_list[1] - A_list[0]
else:
	minwin == 0
print(minwin, maxwin)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
maxWin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
a1 = max(0, a[0] - (b[0] + b[2]))
a2 = max(0, a[1] - (b[1] + b[0]))
a3 = max(0, a[2] - (b[2] + b[1]))
minWin = a1 + a2 + a3
print('{} {}'.format(minWin, maxWin))


inp = lambda : int(input())
seq = lambda : list(map(int, input().strip().split()))

def results(p, q):
	(p1, p2, p3) = (p[0], p[1], p[2])
	(q1, q2, q3) = (q[0], q[1], q[2])
	return min(p1, q2) + min(p2, q3) + min(p3, q1)

def mii(p, q, n):
	(p1, p2, p3) = (p[0], p[1], p[2])
	(q1, q2, q3) = (q[0], q[1], q[2])
	return max(p1 + q2 - n, p2 + q3 - n, p3 + q1 - n, 0)

def main():
	n = inp()
	a = seq()
	b = seq()
	x = results(a, b)
	z = mii(a, b, n)
	print('{} {}'.format(z, x))
main()


n = int(input())
(a1, a2, a3) = list(map(int, input().rstrip().split()))
(b1, b2, b3) = list(map(int, input().rstrip().split()))
ans = [0, 0]
ans[1] = min(a1, b2) + min(a2, b3) + min(a3, b1)
ans[0] = max(0, b1 - (a1 + a2), b2 - (a2 + a3), b3 - (a1 + a3))
print(*ans)


n = int(input())
(x, y, z) = [int(i) for i in input().split()]
(a, b, c) = [int(i) for i in input().split()]
(a, b, c) = (b, c, a)
mi = max(0, max(x - b - c, max(y - a - c, z - a - b)))
ma = min(x, a) + min(y, b) + min(z, c)
print(mi, ma)


from sys import stdin
rounds = int(stdin.readline())
alice = list(map(int, stdin.readline().split()))
bob = list(map(int, stdin.readline().split()))
mins = 0
maxs = 0
for i in range(3):
	maxs += min(alice[i], bob[i - 2])
mins = max(0, bob[0] - alice[0] - alice[1], bob[1] - alice[1] - alice[2], bob[2] - alice[2] - alice[0])
print(mins, maxs)


n = int(input())
(ra, sa, pa) = map(int, input().split())
(rb, sb, pb) = map(int, input().split())
mx = min(ra, sb) + min(sa, pb) + min(pa, rb)
mn = max(0, ra - (rb + pb)) + max(0, pa - (pb + sb)) + max(0, sa - (sb + rb))
print(mn, mx)


import itertools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ma = sum([min(a[i], b[(i + 1) % 3]) for i in range(3)])
mi = n
for p in itertools.permutations([i for i in range(3)]):
	for s in [0, 2]:
		for t in [0, 2]:
			for u in [0, 2]:
				(aa, bb) = (list(a), list(b))
				p = list(p)
				x = min(aa[p[0]], bb[(p[0] + s) % 3])
				aa[p[0]] -= x
				bb[(p[0] + s) % 3] -= x
				if aa[p[0]] > 0:
					x = min(aa[p[0]], bb[(p[0] + (s ^ 2)) % 3])
					aa[p[0]] -= x
					bb[(p[0] + (s ^ 2)) % 3] -= x
				x = min(aa[p[1]], bb[(p[1] + t) % 3])
				aa[p[1]] -= x
				bb[(p[1] + t) % 3] -= x
				if aa[p[1]] > 0:
					x = min(aa[p[1]], bb[(p[1] + (t ^ 2)) % 3])
					aa[p[1]] -= x
					bb[(p[1] + (t ^ 2)) % 3] -= x
				x = min(aa[p[2]], bb[(p[2] + u) % 3])
				aa[p[2]] -= x
				bb[(p[2] + u) % 3] -= x
				if aa[p[2]] > 0:
					x = min(aa[p[2]], bb[(p[2] + (u ^ 2)) % 3])
					aa[p[2]] -= x
					bb[(p[2] + (u ^ 2)) % 3] -= x
				mi = min(mi, sum(aa))
print(mi, ma)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
from collections import deque, Counter, OrderedDict, defaultdict
from itertools import permutations, combinations
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split())

def msi():
	return map(str, input().strip().split())

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
from collections import deque, Counter, OrderedDict, defaultdict
from math import *
from itertools import permutations, combinations
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
vow = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def expo(x, y, m):
	if y == 0:
		return 1
	elif y % 2 == 0:
		return expo(x * x % m, y / 2, m)
	else:
		return x * expo(x * x % m, (y - 1) / 2, m) % m

def gcd(a, b):
	if a == 0:
		return (b, 0, 1)
	(gc, x1, y1) = gcd(b % a, a)
	x = y1 - b // a * x1
	y = x1
	return (gc, x, y)

def sieve(n):
	arr = [True] * (n + 1)
	arr[0] = False
	arr[1] = False
	for i in range(4, n + 1, 2):
		arr[i] = False
	for i in range(3, int(sqrt(n)) + 1, 2):
		if arr[i] == True:
			for j in range(i * i, n + 1, i):
				arr[j] = False
	return arr

def modInverse(x, y):
	(gc, x1, y1) = gcd(x, y)
	return (y1 + y) % y

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	n = ii()
	(a, b, c) = mi()
	(d, e, f) = mi()
	val = min(a, e) + min(b, f) + min(c, d)
	val1 = max(0, a - d - f) + max(b - e - d, 0) + max(0, c - e - f)
	print(val1, val)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
alice = []
alice = [int(j) for j in input().split()]
bob = []
bob = [int(j) for j in input().split()]
mins = [0] * 3
mins[0] = alice[0] - bob[0] - bob[2]
mins[1] = alice[1] - bob[1] - bob[0]
mins[2] = alice[2] - bob[2] - bob[1]
maxa = min(alice[0], bob[1]) + min(alice[1], bob[2]) + min(alice[2], bob[0])
print(str(max(0, max(mins))) + ' ' + str(maxa))


from itertools import permutations

def calc(a, b):
	if b[0] <= a[0] and a[1] <= b[1]:
		return a[1] - a[0] + 1
	if a[0] <= b[0] and b[1] <= a[1]:
		return b[1] - b[0] + 1
	return max(0, min(b[1] - a[0], a[1] - b[0]) + 1)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(ans1, ans2) = (n, 0)
for t1 in permutations(range(3)):
	alice = {}
	s = 0
	for i in range(3):
		if t1[i] == 0:
			alice['r'] = [s, s + a[0] - 1]
			s += a[0]
		elif t1[i] == 1:
			alice['s'] = [s, s + a[1] - 1]
			s += a[1]
		else:
			alice['p'] = [s, s + a[2] - 1]
			s += a[2]
	for t2 in permutations(range(3)):
		bob = {}
		s = 0
		for i in range(3):
			if t2[i] == 0:
				bob['r'] = [s, s + b[0] - 1]
				s += b[0]
			elif t2[i] == 1:
				bob['s'] = [s, s + b[1] - 1]
				s += b[1]
			else:
				bob['p'] = [s, s + b[2] - 1]
				s += b[2]
		win = calc(alice['r'], bob['s']) + calc(alice['s'], bob['p']) + calc(alice['p'], bob['r'])
		ans1 = min(ans1, win)
		ans2 = max(ans2, win)
print(ans1, ans2)


n = int(input())
(r1, s1, p1) = map(int, input().split())
(r2, s2, p2) = map(int, input().split())
win = min(r1, s2) + min(p1, r2) + min(s1, p2)
loss = r1 - min(r1, r2 + p2) + p1 - min(p1, s2 + p2) + s1 - min(s1, r2 + s2)
print(loss, win)


import sys

def max_win_rounds(a1, a2, a3, b1, b2, b3):
	return min(a1, b2) + min(a2, b3) + min(a3, b1)

def max_loses(a1, a2, a3, b1, b2, b3):
	res = [0]
	if a1 > 0:
		step = min(a1, b1)
		if step > 0:
			res.append(step + max_loses(a1 - step, a2, a3, b1 - step, b2, b3))
		step = min(a1, b3)
		if step > 0:
			res.append(step + max_loses(a1 - step, a2, a3, b1, b2, b3 - step))
	if a2 > 0:
		step = min(a2, b2)
		if step > 0:
			res.append(step + max_loses(a1, a2 - step, a3, b1, b2 - step, b3))
		step = min(a2, b1)
		if step > 0:
			res.append(step + max_loses(a1, a2 - step, a3, b1 - step, b2, b3))
	if a3 > 0:
		step = min(a3, b3)
		if step > 0:
			res.append(step + max_loses(a1, a2, a3 - step, b1, b2, b3 - step))
		step = min(a3, b2)
		if step > 0:
			res.append(step + max_loses(a1, a2, a3 - step, b1, b2 - step, b3))
	return max(res)

def main():
	n = int(sys.stdin.readline().strip())
	(a1, a2, a3) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
	(b1, b2, b3) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
	min_wins = n - max_loses(a1, a2, a3, b1, b2, b3)
	max_wins = max_win_rounds(a1, a2, a3, b1, b2, b3)
	print(min_wins, max_wins)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mini = 0
maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
if a[0] > b[0] + b[2]:
	mini = a[0] - b[2] - b[0]
elif a[1] > b[1] + b[0]:
	mini = a[1] - b[1] - b[0]
elif a[2] > b[2] + b[1]:
	mini = a[2] - b[2] - b[1]
else:
	mini = 0
print(mini, maxi)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mn = max(a[0] - b[0] - b[2], a[1] - b[1] - b[0], a[2] - b[2] - b[1], 0)
print(mn, mx)


n = int(input())
Alice = list(map(int, input().split()))
Bob = list(map(int, input().split()))
maior = menor = 0
maior = min(Alice[0], Bob[1]) + min(Alice[1], Bob[2]) + min(Alice[2], Bob[0])
temp = Bob[0] - (Alice[0] + Alice[1])
if temp < 0:
	temp = 0
menor += temp
temp = Bob[1] - (Alice[1] + Alice[2])
if temp < 0:
	temp = 0
menor += temp
temp = Bob[2] - (Alice[2] + Alice[0])
if temp < 0:
	temp = 0
menor += temp
print(menor, maior)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import deque
n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
maxnum = min(alice[0], bob[1]) + min(alice[1], bob[2]) + min(alice[2], bob[0])
a = [('r', alice[0]), ('s', alice[1]), ('p', alice[2])]
b = [('r', bob[0]), ('s', bob[1]), ('p', bob[2])]
posa = [(a[0], a[1], a[2]), (a[0], a[2], a[1]), (a[1], a[2], a[0]), (a[1], a[0], a[2]), (a[2], a[1], a[0]), (a[2], a[0], a[1])]
posb = [(b[0], b[1], b[2]), (b[0], b[2], b[1]), (b[1], b[0], b[2]), (b[1], b[2], b[0]), (b[2], b[0], b[1]), (b[2], b[1], b[0])]
minans = 10 ** 9 + 1
k = 0
for s in range(6):
	perm1 = posa[s]
	for i in range(6):
		perm2 = posb[i]
		ans = 0
		leftover = deque([])
		prev = deque([])
		cv = deque([])
		for j in range(3):
			a1 = perm1[j]
			b1 = perm2[j]
			c1 = a1[1]
			c2 = b1[1]
			if len(leftover) > 0:
				while len(leftover) > 0:
					if cv[0] == 0:
						v1 = min(leftover[0], c2)
						if prev[0] == 'r' and b1[0] == 's':
							ans += v1
						elif prev[0] == 's' and b1[0] == 'p':
							ans += v1
						elif prev[0] == 'p' and b1[0] == 'r':
							ans += v1
						c2 -= v1
						leftover[0] -= v1
					else:
						v1 = min(leftover[0], c1)
						if prev[0] == 'r' and a1[0] == 'p':
							ans += v1
						elif prev[0] == 's' and a1[0] == 'r':
							ans += v1
						elif prev[0] == 'p' and a1[0] == 's':
							ans += v1
						c1 -= v1
						leftover[0] -= v1
					if leftover[0] == 0:
						leftover.popleft()
						cv.popleft()
						prev.popleft()
					elif v1 == 0:
						break
			v0 = min(c1, c2)
			c1 -= v0
			c2 -= v0
			if a1[0] == 'r' and b1[0] == 's':
				ans += v0
			elif a1[0] == 's' and b1[0] == 'p':
				ans += v0
			elif a1[0] == 'p' and b1[0] == 'r':
				ans += v0
			if c1 > 0:
				leftover.append(c1)
				cv.append(0)
				prev.append(a1[0])
			elif c2 > 0:
				leftover.append(c2)
				cv.append(1)
				prev.append(b1[0])
		minans = min(minans, ans)
print(minans, maxnum)


from itertools import permutations
n = int(input())
(ar, asis, apap) = [int(i) for i in input().split()]
(br, bsis, bpap) = [int(i) for i in input().split()]
ma = min(ar, bsis) + min(asis, bpap) + min(apap, br)
mi = max(ar - br - bpap, 0) + max(asis - bsis - br, 0) + max(apap - bpap - bsis, 0)
print(mi, ma)


def main():
	turnNum = int(input())
	aliceChoices = list(map(int, input().split(' ')))
	bobChoices = list(map(int, input().split(' ')))
	bobChoices.append(bobChoices.pop(0))
	(minWin, maxWin) = [0, 0]
	for (i, choice) in enumerate(aliceChoices):
		maxWin += min([choice, bobChoices[i]])
	maximum = max(bobChoices)
	for (i, choice) in enumerate(bobChoices):
		if choice == maximum and choice + aliceChoices[i] > minWin:
			minWin = choice + aliceChoices[i]
	maximum = max(aliceChoices)
	for (i, choice) in enumerate(aliceChoices):
		if choice == maximum and choice + bobChoices[i] > minWin:
			minWin = choice + bobChoices[i]
	minWin = minWin - turnNum if minWin > turnNum else 0
	print(f'{minWin} {maxWin}')
main()


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
mi = n - min(a1, n - b2) - min(a2, n - b3) - min(a3, n - b1)
print(mi, ma)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = b[0]
b[0] = b[1]
b[1] = b[2]
b[2] = q
Min = 0
Max = 0
for i in range(3):
	Min += max(a[i] - b[(i + 1) % 3] - b[(i + 2) % 3], 0)
	Max += min(a[i], b[i])
print(Min, Max)


import itertools
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
win = min(a1, b2) + min(a2, b3) + min(a3, b1)
mx = 0
pt = -1
mx = 0
for lists in itertools.permutations(range(6)):
	ct = 0
	aa1 = a1
	aa2 = a2
	aa3 = a3
	bb1 = b1
	bb2 = b2
	bb3 = b3
	for pt in lists:
		L = [min(aa1, bb1), min(aa1, bb3), min(aa2, bb1), min(aa2, bb2), min(aa3, bb2), min(aa3, bb3)]
		if pt == 0:
			aa1 -= L[0]
			bb1 -= L[0]
		if pt == 1:
			aa1 -= L[1]
			bb3 -= L[1]
		if pt == 2:
			aa2 -= L[2]
			bb1 -= L[2]
		if pt == 3:
			aa2 -= L[3]
			bb2 -= L[3]
		if pt == 4:
			aa3 -= L[4]
			bb2 -= L[4]
		if pt == 5:
			aa3 -= L[5]
			bb3 -= L[5]
		ct += L[pt]
	if ct > mx:
		mx = ct
print(n - mx, win)


from sys import stdout, stdin
n = int(stdin.readline())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
v = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
u = n - (min(b[0], a[0] + a[1]) + min(b[1], a[1] + a[2]) + min(b[2], a[2] + a[0]))
stdout.write(str(u) + ' ' + str(v))


def find_max(alice, bob):
	max1 = 0
	if alice[0] >= bob[0] + bob[2]:
		max1 = alice[0]
	elif alice[1] >= bob[1] + bob[0]:
		max1 = alice[1]
	else:
		max1 = alice[2]
	return max1
var = input()
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
maximum_win = 0
minimum_win = 0
sum1 = 0
if alice[0] >= bob[1]:
	sum1 = bob[1]
else:
	sum1 = alice[0]
sum2 = 0
if alice[1] >= bob[2]:
	sum2 = bob[2]
else:
	sum2 = alice[1]
sum3 = 0
if alice[2] >= bob[0]:
	sum3 = bob[0]
else:
	sum3 = alice[2]
maximum_win = sum1 + sum2 + sum3
index = 0
mainvar = 0
index = alice.index(find_max(alice, bob))
mainvar = alice[index]
mainvar -= bob[index]
if index == 0:
	mainvar -= bob[2]
elif index == 1:
	mainvar -= bob[0]
else:
	mainvar -= bob[1]
minimum_win = mainvar
if minimum_win < 0:
	minimum_win = 0
print(minimum_win)
print(maximum_win)


import os
import sys
from io import BytesIO, IOBase

def solution():
	n = int(input())
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	val1 = min(a3, b1)
	val2 = min(a1, b2)
	val3 = min(a2, b3)
	ans = val1 + val2 + val3
	val1 = b1 + b3
	val2 = b1 + b2
	val3 = b2 + b3
	print(max(a1 - val1, a2 - val2, a3 - val3, 0), ans)
	return

def main():
	testcases = 1
	for _ in range(testcases):
		solution()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


a = int(input())
(d, r, l) = map(int, input().split(' '))
(z, j, k) = map(int, input().split(' '))
maxx = min(l, z) + min(d, j) + min(r, k)
minn = max(0, l - (j + k)) + max(0, d - (z + k)) + max(0, r - (z + j))
print(minn, maxx)


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	n = int(input())
	a = [int(o) for o in input().split()]
	b = [int(o) for o in input().split()]
	s = 0
	for i in range(3):
		s += min(a[i], b[(i + 1) % 3])
	m = 0
	for i in range(3):
		m += max(0, a[i] - (b[i] + b[(i - 1) % 3]))
	print(m, s)
sync_with_stdio(False)
main()


import sys
input = sys.stdin.readline
t = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
maxwin = min(alice[0], bob[1]) + min(alice[1], bob[2]) + min(alice[2], bob[0])
minlose = alice[0] - min(alice[0], bob[0] + bob[2]) + (alice[1] - min(alice[1], bob[1] + bob[0])) + (alice[2] - min(alice[2], bob[2] + bob[1]))
print(minlose, maxwin)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
for _ in range(1):
	n = int(input())
	a = inp()
	b = inp()
	mxans = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	mnans = max(0, a[0] - b[2] - b[0]) + max(0, a[1] - b[1] - b[0]) + max(0, a[2] - b[2] - b[1])
	print(mnans, mxans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maximum = 0
minimum = n
for i in range(3):
	maximum += min(a[i], b[(i + 1) % 3])
for i in range(3):
	minimum -= min(a[i], n - b[(i + 1) % 3])
print('{} {}'.format(minimum, maximum))


n = int(input(''))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mxsol = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mn = 0
if a[0] > b[2] + b[0]:
	mn = max(mn, a[0] - b[2] - b[0])
if a[1] > b[1] + b[0]:
	mn = max(mn, a[1] - b[1] - b[0])
if a[2] > b[2] + b[1]:
	mn = max(mn, a[2] - b[2] - b[1])
print(mn, mxsol)


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve(d1, d2):
	(ans1, ans2) = (0, 0)
	for i in ['R', 'S', 'P']:
		x = 0
		for j in ['R', 'S', 'P']:
			if win[i] != j:
				x += d2[j]
		ans1 += min(d1[i], x)
		for j in ['R', 'S', 'P']:
			if win[i] == j:
				ans2 += min(d1[i], d2[j])
	return [n - ans1, ans2]
for _ in range(t):
	n = int(input())
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	d1 = {}
	d1['R'] = a1
	d1['S'] = a2
	d1['P'] = a3
	d2 = {}
	d2['R'] = b1
	d2['S'] = b2
	d2['P'] = b3
	win = {}
	win['R'] = 'S'
	win['S'] = 'P'
	win['P'] = 'R'
	print(*solve(d1, d2))


from queue import Queue, LifoQueue, PriorityQueue, deque
from collections import namedtuple
INF = 4557430888798830399
MAXN = 10

class Edge:

	def __init__(self, cap, fm, to):
		self.cap = cap
		self.to = to
		self.fm = fm
		self.re = None
edges = [[] for i in range(MAXN)]
q = Queue(maxsize=0)
path = [None] * MAXN
flow = [INF] * MAXN

def bfs(start, end):
	global path, flow
	q.queue.clear()
	path.clear()
	path = [None] * MAXN
	flow[start] = INF
	q.put_nowait(start)
	while not q.empty():
		u = q.get_nowait()
		if u == end:
			break
		for edge in edges[u]:
			v = edge.to
			if v != start and path[v] is None and (edge.cap > 0):
				flow[v] = min(flow[u], edge.cap)
				q.put_nowait(v)
				path[v] = edge
	if path[end] is None:
		return None
	return flow[end]

def Edmonds_Karp(start, end):
	global edges
	max_flow = 0
	while True:
		res = bfs(start, end)
		if res is None:
			break
		max_flow += res
		now = end
		while now != start:
			edge = path[now]
			pre = edge.fm
			edge.cap -= res
			edge.re.cap += res
			now = pre
	return max_flow

def build_pipe(cap, fm, to, edges=edges):
	e_a = Edge(cap, fm, to)
	e_b = Edge(0, to, fm)
	e_a.re = e_b
	e_b.re = e_a
	edges[fm].append(e_a)
	edges[to].append(e_b)
n = int(input())
(ast, ajd, abu) = map(int, input().split())
(bst, bjd, bbu) = map(int, input().split())
build_pipe(ajd, 0, 1)
build_pipe(ast, 0, 2)
build_pipe(abu, 0, 3)
build_pipe(INF, 1, 4)
build_pipe(INF, 1, 5)
build_pipe(INF, 2, 5)
build_pipe(INF, 2, 6)
build_pipe(INF, 3, 6)
build_pipe(INF, 3, 4)
build_pipe(bjd, 4, 7)
build_pipe(bst, 5, 7)
build_pipe(bbu, 6, 7)
ans = min(ajd, bbu) + min(ast, bjd) + min(abu, bst)
print(n - Edmonds_Karp(0, 7), ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lowest = 0
highest = 0
for i in range(2):
	if a[i] <= b[i + 1]:
		highest += a[i]
	else:
		highest += b[i + 1]
if a[2] <= b[0]:
	highest += a[2]
else:
	highest += b[0]
possible = []
for i in range(1, 3):
	possible.append(a[i] - b[i] - b[i - 1])
possible.append(a[0] - b[0] - b[2])
lowest = max(possible)
lowest = max(lowest, 0)
print(lowest, highest)


def win(x, y):
	if x >= y:
		return y
	else:
		return x

def lose(x, y):
	L = []
	if x >= y:
		L.append(x - y)
		L.append(0)
	else:
		L.append(0)
		L.append(y - x)
	return L
n = int(input())
win_pairs = {0: 1, 1: 2, 2: 0}
lose_pairs = {0: 2, 1: 0, 2: 1}
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 3
least = most = 0
for i in range(0, k):
	x = win(A[i], B[win_pairs[i]])
	most += x
for i in range(0, k):
	if A[i] - B[i] > 0:
		A[i] -= B[i]
	else:
		A[i] = 0
for i in range(0, k):
	(A[i], B[lose_pairs[i]]) = lose(A[i], B[lose_pairs[i]])
least = sum(A)
print(least, ' ', most)


from __future__ import division, print_function
from io import BytesIO, IOBase
import os, sys, math, heapq, copy
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from itertools import permutations, combinations, combinations_with_replacement
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 1000000007

def get_int():
	return int(sys.stdin.readline().strip())

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

def get_float():
	return float(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def get_floats():
	return map(float, sys.stdin.readline().strip().split())

def list_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def list_strs():
	return list(map(str, sys.stdin.readline().strip().split()))

def list_floats():
	return list(map(float, sys.stdin.readline().strip().split()))

def fun(index, r1, p1, s1, r2, p2, s2):
	if index == 0:
		if r1 == 0:
			fun(index + 1, r1, p1, s1, r2, p2, s2)
		else:
			x = min(r1, r2)
n = get_int()
(r1, s1, p1) = get_ints()
(r2, s2, p2) = get_ints()
m1 = 0
m2 = 0
m1 += max(0, r1 - (r2 + p2))
m1 += max(0, s1 - (s2 + r2))
m1 += max(0, p1 - (p2 + s2))
if r1 != 0:
	m2 += min(r1, s2)
if s1 != 0:
	m2 += min(s1, p2)
if p1 != 0:
	m2 += min(p1, r2)
print(m1, m2)


from itertools import permutations
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = min(A[0], B[1]) + min(A[1], B[2]) + min(A[2], B[0])
b = float('inf')
order = range(6)
for idxs in permutations(order, 6):
	temp_A = A[:]
	temp_B = B[:]
	for idx in idxs:
		if idx == 0:
			val = min(temp_A[0], temp_B[0])
			temp_A[0] -= val
			temp_B[0] -= val
		elif idx == 1:
			val = min(temp_A[1], temp_B[1])
			temp_A[1] -= val
			temp_B[1] -= val
		elif idx == 2:
			val = min(temp_A[2], temp_B[2])
			temp_A[2] -= val
			temp_B[2] -= val
		elif idx == 3:
			val = min(temp_B[0], temp_A[1])
			temp_A[1] -= val
			temp_B[0] -= val
		elif idx == 4:
			val = min(temp_B[1], temp_A[2])
			temp_A[2] -= val
			temp_B[1] -= val
		elif idx == 5:
			val = min(temp_B[2], temp_A[0])
			temp_A[0] -= val
			temp_B[2] -= val
	res = min(temp_A[0], temp_B[1]) + min(temp_A[1], temp_B[2]) + min(temp_A[2], temp_B[0])
	b = min(res, b)
print(b, a)


n = int(input())
a = [int(a) for a in input().split()]
b = [int(b) for b in input().split()]
max_sum = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
min_sum = min(a[0], n - b[1]) + min(a[1], n - b[2]) + min(a[2], n - b[0])
print(n - min_sum, max_sum)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt
import math
from itertools import permutations

def main():
	n = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	ma = min(c[0], d[1]) + min(c[1], d[2]) + min(c[2], d[0])
	m = 0
	for i in permutations([0, 1, 2, 3, 4, 5]):
		ans = 0
		a = c[:]
		b = d[:]
		for j in i:
			if j < 3:
				x = min(a[j], b[j])
				a[j] -= x
				b[j] -= x
				ans += x
			else:
				x = min(b[j - 3], a[(j - 2) % 3])
				b[j - 3] -= x
				a[(j - 2) % 3] -= x
				ans += x
		m = max(m, ans)
	mi = n - m
	print(mi, ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
maxWin = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])

def dfs(remainingTotal, remainingCombinations):
	if len(remainingCombinations) == 0:
		minWins.append(sum(remainingTotal[:3]))
		return
	for i in range(len(remainingCombinations)):
		remainingCombinations2 = remainingCombinations.copy()
		remainingTotal2 = remainingTotal.copy()
		(x, y) = remainingCombinations2.pop(i)
		subtract = min(remainingTotal2[x], remainingTotal2[y])
		remainingTotal2[x] -= subtract
		remainingTotal2[y] -= subtract
		dfs(remainingTotal2, remainingCombinations2)
arr = a + b
combinations = [(0, 3), (0, 5), (1, 4), (1, 3), (2, 5), (2, 4)]
minWins = []
dfs(arr, combinations)
minWin = min(minWins)
print('{} {}'.format(minWin, maxWin))


from itertools import *
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
res_max = 0
for i in range(len(A)):
	res_max += min(A[i], B[(i + 1) % len(A)])
possible_pairs = [(0, 0), (0, 2), (1, 1), (1, 0), (2, 2), (2, 1)]
res_min = float('inf')
for pairs in permutations(possible_pairs):
	(tempA, tempB) = (A[:], B[:])
	for (a, b) in pairs:
		temp = min(tempA[a], tempB[b])
		tempA[a] -= temp
		tempB[b] -= temp
	res_min = min(res_min, sum(tempA))
print(res_min, res_max)


import os
import sys
from io import BytesIO, IOBase
import math
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
(a1, a2, a3) = map(int, input().split(' '))
(b1, b2, b3) = map(int, input().split(' '))
x = min(a1, b2) + min(a2, b3) + min(a3, b1)
y = max(0, a1 - b1 - b3) + max(0, a2 - b2 - b1) + max(0, a3 - b3 - b2)
print(y, x)


n = int(input())
(a1, a2, a3) = [int(i) for i in input().split()]
(b1, b2, b3) = [int(i) for i in input().split()]
maxi = min(a1, b2) + min(a2, b3) + min(a3, b1)
mini = max(0, b1 - a1 - a2, b2 - a2 - a3, b3 - a3 - a1)
print(mini, maxi)


n = int(input())
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
k1 = min(t1[0], t2[1]) + min(t1[1], t2[2]) + min(t1[2], t2[0])
k2 = min(t1[0], n - t2[1]) + min(t1[1], n - t2[2]) + min(t1[2], n - t2[0])
print(n - k2, k1)


n = int(input())
(R, S, P) = map(int, input().split())
(r, s, p) = map(int, input().split())
maxx = min(R, s) + min(S, p) + min(P, r)
minn = 0
minn += max(0, R - (p + r))
minn += max(0, S - (s + r))
minn += max(0, P - (p + s))
print(minn, maxx)


import sys

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

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
N = INT()
A = LIST()
B = LIST()
ans1 = 0
for i in range(3):
	ans1 += min(A[i], B[(i + 1) % 3])
ans2 = 0
for i in range(3):
	ans2 += min(A[i], B[i] + B[(i - 1) % 3])
ans2 = N - ans2
print(ans2, ans1)


import bisect
import array
import functools
import math
n = int(input())
a = array.array('i', map(int, input().split()))
b = array.array('i', map(int, input().split()))
ans1 = max(a[0] - b[0] - b[2], 0) + max(a[1] - b[1] - b[0], 0) + max(a[2] - b[2] - b[1], 0)
ans2 = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
print(ans1, ans2)


import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	blst = list(map(int, input().split()))
	max_ = 0
	min_ = 0
	for i in range(3):
		max_ += min(alst[i], blst[(i + 1) % 3])
		min_ += max(0, alst[i] - blst[(i - 1) % 3] - blst[i])
	print(min_, max_)
main()


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
(a1, a2, a3) = inputnums()
(b1, b2, b3) = inputnums()
mn = min(a1, b1 + b3) + min(a2, b2 + b1) + min(a3, b3 + b2)
mx = min(a1, b2) + min(a2, b3) + min(a3, b1)
print(n - mn, mx)


import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp

class MinCostFlowwithDijkstra:
	INF = 1 << 60

	def __init__(self, N):
		self.N = N
		self.Edge = [[] for _ in range(N)]

	def add_edge(self, st, en, cap, cost):
		self.Edge[st].append([en, cap, cost, len(self.Edge[en])])
		self.Edge[en].append([st, 0, -cost, len(self.Edge[st]) - 1])

	def get_mf(self, so, si, fl):
		N = self.N
		INF = self.INF
		res = 0
		Pot = [0] * N
		geta = N
		prv = [None] * N
		prenum = [None] * N
		while fl:
			dist = [INF] * N
			dist[so] = 0
			Q = [so]
			while Q:
				(cost, vn) = divmod(hpp(Q), geta)
				if dist[vn] < cost:
					continue
				for enum in range(len(self.Edge[vn])):
					(vf, cap, cost, _) = self.Edge[vn][enum]
					cc = dist[vn] + cost - Pot[vn] + Pot[vf]
					if cap > 0 and dist[vf] > cc:
						dist[vf] = cc
						prv[vf] = vn
						prenum[vf] = enum
						hp(Q, cc * geta + vf)
			if dist[si] == INF:
				return -1
			for i in range(N):
				Pot[i] -= dist[i]
			cfl = fl
			vf = si
			while vf != so:
				cfl = min(cfl, self.Edge[prv[vf]][prenum[vf]][1])
				vf = prv[vf]
			fl -= cfl
			res -= cfl * Pot[si]
			vf = si
			while vf != so:
				e = self.Edge[prv[vf]][prenum[vf]]
				e[1] -= cfl
				self.Edge[vf][e[3]][1] += cfl
				vf = prv[vf]
		return res
N = int(readline())
(ra, sa, pa) = map(int, readline().split())
(rb, sb, pb) = map(int, readline().split())
maxwin = min(ra, sb) + min(sa, pb) + min(pa, rb)
D = MinCostFlowwithDijkstra(8)
D.add_edge(0, 1, ra, 0)
D.add_edge(0, 2, sa, 0)
D.add_edge(0, 3, pa, 0)
D.add_edge(4, 7, rb, 0)
D.add_edge(5, 7, sb, 0)
D.add_edge(6, 7, pb, 0)
D.add_edge(1, 4, N, 0)
D.add_edge(1, 5, N, 1)
D.add_edge(1, 6, N, 0)
D.add_edge(2, 4, N, 0)
D.add_edge(2, 5, N, 0)
D.add_edge(2, 6, N, 1)
D.add_edge(3, 4, N, 1)
D.add_edge(3, 5, N, 0)
D.add_edge(3, 6, N, 0)
print(D.get_mf(0, 7, N), maxwin)


num_rounds = int(input())
(a_r, a_s, a_p) = [int(i) for i in input().split()]
(b_r, b_s, b_p) = [int(i) for i in input().split()]
max_win = min(a_r, b_s) + min(a_s, b_p) + min(a_p, b_r)
min_win = max(a_r - (b_r + b_p), a_p - (b_p + b_s), a_s - (b_s + b_r), 0)
print(f'{min_win} {max_win}')


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
(r1, s1, p1) = map(int, input().split())
(r2, s2, p2) = map(int, input().split())
m1 = 0
m1 += min(r1, s2) + min(p1, r2) + min(s1, p2)
a = min(r1, r2 + p2)
b = min(p1, p2 + s2)
c = min(s1, s2 + r2)
m3 = min(r2, r1) + min(p2, p1) + min(s2, s1)
print(n - a - b - c, m1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(RL())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	n = N()
	arra = RLL()
	arrb = RLL()
	ma = min(arrb[0], arra[2]) + min(arrb[1], arra[0]) + min(arrb[2], arra[1])
	mi = n - (min(arra[0], arrb[0] + arrb[2]) + min(arra[1], arrb[1] + arrb[0]) + min(arra[2], arrb[2] + arrb[1]))
	print(mi, ma)
main()


import sys

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

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)

class Dinic:
	INF = 10 ** 18

	def __init__(self, n):
		self.n = n
		self.links = [[] for _ in range(n)]
		self.depth = None
		self.progress = None
		self.pos = []

	def copy(self):
		res = Dinic(self.n)
		res.links = [[a[:] for a in b] for b in self.links]
		res.pos = [a[:] for a in self.pos]
		return res

	def add_edge(self, _from, to, cap):
		self.pos.append((_from, len(self.links[_from])))
		self.links[_from].append([cap, to, len(self.links[to])])
		self.links[to].append([0, _from, len(self.links[_from]) - 1])

	def bfs(self, s):
		from collections import deque
		depth = [-1] * self.n
		depth[s] = 0
		q = deque([s])
		while q:
			v = q.popleft()
			for (cap, to, _) in self.links[v]:
				if cap > 0 and depth[to] < 0:
					depth[to] = depth[v] + 1
					q.append(to)
		self.depth = depth

	def dfs(self, v, t, flow):
		if v == t:
			return flow
		links_v = self.links[v]
		for i in range(self.progress[v], len(links_v)):
			self.progress[v] = i
			(cap, to, rev) = link = links_v[i]
			if cap == 0 or self.depth[v] >= self.depth[to]:
				continue
			d = self.dfs(to, t, min(flow, cap))
			if d == 0:
				continue
			link[0] -= d
			self.links[to][rev][0] += d
			return d
		return 0

	def flow(self, s, t):
		INF = Dinic.INF
		flow = 0
		while True:
			self.bfs(s)
			if self.depth[t] < 0:
				return flow
			self.progress = [0] * self.n
			current_flow = self.dfs(s, t, INF)
			while current_flow > 0:
				flow += current_flow
				current_flow = self.dfs(s, t, INF)

	def get_edge(self, i):
		e = self.links[self.pos[i][0]][self.pos[i][1]]
		re = self.links[e[1]][e[2]]
		return (self.pos[i][0], e[1], e[0] + re[0], re[0])

	def get_edges(self):
		M = len(self.pos)
		res = []
		for i in range(M):
			res.append(self.get_edge(i))
		return res
N = INT()
M = 3
A = LIST()
B = LIST()
ans1 = 0
for i in range(M):
	ans1 += min(A[i], B[(i + 1) % M])
ans2 = 0
dinic = Dinic(2 * M + 2)
s = 2 * M
t = 2 * M + 1
for i in range(M):
	dinic.add_edge(s, i, N)
	dinic.add_edge(M + i, t, B[i])
	dinic.add_edge(i, M + i, A[i])
	dinic.add_edge(i, M + (i - 1) % M, A[i])
ans2 = N - dinic.flow(s, t)
print(ans2, ans1)


n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
if min(a1, b2) > min(a2, b3) and min(a1, b2) > min(a3, b1):
	print(max(0, a1 - b1 - b3), min(a1, b2) + min(a2, b3) + min(a3, b1))
elif min(a2, b3) > min(a1, b2) and min(a2, b3) > min(a3, b1):
	print(max(0, a2 - b2 - b1), min(a1, b2) + min(a2, b3) + min(a3, b1))
elif min(a3, b1) > min(a1, b2) and min(a3, b1) > min(a2, b3):
	print(max(0, a3 - b3 - b2), min(a1, b2) + min(a2, b3) + min(a3, b1))
else:
	print(0, min(a1, b2) + min(a2, b3) + min(a3, b1))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
minnie = n - (min(a[0], b[0] + b[2]) + min(a[1], b[1] + b[0]) + min(a[2], b[2] + b[1]))
print(minnie, maxi)


from math import *
from sys import *
from bisect import *
from collections import *
n = int(stdin.readline())
(r1, s1, p1) = map(int, stdin.readline().split())
(r2, s2, p2) = map(int, stdin.readline().split())
mx = min(r1, s2) + min(p1, r2) + min(s1, p2)
mn = 0
x = r1 - r2 - p2
y = s1 - s2 - r2
z = p1 - p2 - s2
mn = max(x, y, z, 0)
print(mn, mx)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	(a, b, c) = inpt()
	(p, q, r) = inpt()
	mn = 0
	ans1 = max(a - (p + r), b - (q + p), c - (r + q), mn)
	ans2 = min(a, q) + min(b, r) + min(c, p)
	print(ans1, ans2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	n = int(input())
	(x, y, z) = inar()
	(a, b, c) = inar()
	mn = 0
	mx = 0
	mx += min(x, b)
	mx += min(y, c)
	mx += min(z, a)
	mn += max(0, a - (x + y), b - (y + z), c - (x + z))
	print(mn, mx)
main()


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	mn = n - min(a[0], b[0] + b[2]) - min(a[1], b[1] + b[0]) - min(a[2], b[2] + b[1])
	print(mn, mx)
t = 1
for _ in range(0, t):
	solve()


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
c1 = a1 - (b3 + b1)
c2 = a2 - (b1 + b2)
c3 = a3 - (b2 + b3)
s = 0
if c1 > 0:
	s += c1
if c2 > 0:
	s += c2
if c3 > 0:
	s += c3
print(s, end=' ')
print(min(a1, b2) + min(a2, b3) + min(a3, b1))


n = int(input())
(r1, s1, p1) = map(int, input().split())
(r2, s2, p2) = map(int, input().split())
max_win = min(r1, s2) + min(s1, p2) + min(p1, r2)
min_win = max(s1 - r2 - s2, p1 - p2 - s2, r1 - r2 - p2, 0)
print(min_win, max_win)


import sys
if not sys.warnoptions:
	import warnings
	warnings.simplefilter('ignore')

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
n = ii()
a = li()
b = li()
maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mini = max(0, a[0] + b[1] - n) + max(0, a[1] + b[2] - n) + max(0, a[2] + b[0] - n)
print(mini, maxi)


import copy
t = int(input())
t = 1
while t:
	t -= 1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a[1], a[2]) = (a[2], a[1])
	(b[1], b[2]) = (b[2], b[1])
	ma = 1000000000000000
	mi = 0
	for i in range(3):
		mi += min(a[i], b[i - 1])
	for i in range(3):
		if b[i] >= a[i] + a[i - 1]:
			ma = min(b[i] - a[i] - a[i - 1], ma)
	if ma == 1000000000000000:
		ma = 0
	print(ma, mi)


def naiveSolve(n, a, b):
	(minWin, maxWin) = (inf, 0)
	arrA = [0] * a[0] + [1] * a[1] + [2] * a[2]
	for mask in range(3 ** n):
		arrB = []
		for _ in range(n):
			arrB.append(mask % 3)
			mask //= 3
		if arrB.count(0) == b[0] and arrB.count(1) == b[1] and (arrB.count(2) == b[2]):
			wins = 0
			for i in range(n):
				if arrA[i] == 0 and arrB[i] == 1:
					wins += 1
				if arrA[i] == 1 and arrB[i] == 2:
					wins += 1
				if arrA[i] == 2 and arrB[i] == 0:
					wins += 1
			minWin = min(minWin, wins)
			maxWin = max(maxWin, wins)
	return (minWin, maxWin)

def main():
	n = int(input())
	a = readIntArr()
	b = readIntArr()
	maxWin = 0
	for i in range(3):
		maxWin += min(a[i], b[(i + 1) % 3])
	minWin = max(0, a[0] - b[0] - b[2]) + max(0, a[1] - b[1] - b[0]) + max(0, a[2] - b[2] - b[1])
	print('{} {}'.format(minWin, maxWin))
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
cap = [[0] * 8 for i in range(8)]
visited = [False] * 8

def find_path(u, vol):
	if u == 7:
		return vol
	if visited[u]:
		return 0
	visited[u] = True
	for i in range(8):
		if cap[u][i] > 0:
			curt = find_path(i, min(vol, cap[u][i]))
			if curt > 0:
				cap[u][i] -= curt
				cap[i][u] += curt
				return curt
	return 0
n = inp()
(a1, a2, a3) = invr()
(b1, b2, b3) = invr()
max_win = min(a1, b2) + min(a2, b3) + min(a3, b1)
cap[0][1] = a1
cap[0][2] = a2
cap[0][3] = a3
cap[4][7] = b1
cap[5][7] = b2
cap[6][7] = b3
cap[1][4] = cap[1][6] = cap[2][4] = cap[2][5] = cap[3][5] = cap[3][6] = n
flow = 0
while True:
	visited = [False] * 8
	curt_flow = find_path(0, n)
	if curt_flow == 0:
		break
	flow += curt_flow
min_win = n - flow
print(min_win, max_win)


import sys
import math
input = sys.stdin.readline
t = int(input())
(r1, s1, p1) = list(map(int, input().split()))
(r2, s2, p2) = list(map(int, input().split()))
ans = min(r1, s2) + min(s1, p2) + min(p1, r2)
import itertools
l1 = list(itertools.permutations([1, 2, 3]))
(a1, a2, a3) = (r1, s1, p1)
(b1, b2, b3) = (r2, s2, p2)
ans2 = 99999999999999999
for i in range(6):
	(r1, s1, p1) = (a1, a2, a3)
	(r2, s2, p2) = (b1, b2, b3)
	for op in l1[i]:
		if op == 1:
			x = min(r2, r1)
			r2 -= x
			r1 -= x
			x = min(r2, s1)
			r2 -= x
			s1 -= x
		if op == 2:
			x = min(s2, s1)
			s2 -= x
			s1 -= x
			x = min(s2, p1)
			s2 -= x
			p1 -= x
		if op == 3:
			x = min(p2, p1)
			p2 -= x
			p1 -= x
			x = min(p2, r1)
			p2 -= x
			r1 -= x
	best = r1 + s1 + p1
	ans2 = min(best, ans2)
print(ans2, ans)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	n = ii()
	a = li()
	b = li()
	ans = 0
	ans = max(ans, a[0] + b[1] - n)
	ans = max(ans, a[1] + b[2] - n)
	ans = max(ans, a[2] + b[0] - n)
	print(ans, end=' ')
	ans = 0
	x = min(a[0], b[1])
	ans += x
	x = min(a[1], b[2])
	ans += x
	x = min(a[2], b[0])
	ans += x
	print(ans)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
n = int(input())
(rock1, paper1, sci1) = list(map(int, input().split()))
(rock2, paper2, sce2) = list(map(int, input().split()))
mn = min(rock1, paper2) + min(paper1, sce2) + min(sci1, rock2)
mx = max(0, rock1 + paper2 - n, paper1 + sce2 - n, sci1 + rock2 - n)
print(mx, mn)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
a = min(a1, b1 + b3)
b = min(a2, b2 + b1)
c = min(a3, b3 + b2)
mi = n - a - b - c
print(mi, ma)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def solve(a, b):
	mins = 0
	(ar, asc, ap) = a
	(br, bsc, bp) = b
	ar -= min(ar, br)
	ap -= min(ap, bp)
	asc -= min(asc, bsc)
	(ar, bp) = (ar - min(ar, bp), bp - min(ar, bp))
	(ap, bsc) = (ap - min(ap, bsc), bsc - min(ap, bsc))
	(asc, br) = (asc - min(asc, br), br - min(asc, br))
	mins += ap + ar + asc
	maxes = 0
	(ar, asc, ap) = a
	(br, bsc, bp) = b
	maxes += min(ar, bsc)
	maxes += min(asc, bp)
	maxes += min(ap, br)
	print(mins, maxes)
solve(a, b)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
b = gil()
maxi = 0
for i in range(3):
	maxi += min(a[i], b[(i + 1) % 3])

def score(i, j):
	return 1 if (i + 1) % 3 == j else 0
mini = inf

def fun(a, b, ans=0):
	global mini
	if a == b == [0, 0, 0]:
		mini = min(ans, mini)
	else:
		for i in range(3):
			if a[i]:
				for j in range(3):
					if b[j]:
						(na, nb) = (a[:], b[:])
						mul = min(a[i], b[j])
						na[i] -= mul
						nb[j] -= mul
						fun(na, nb, ans + score(i, j) * mul)
fun(a, b)
print(mini, maxi)


from itertools import permutations
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mini = n
permut = [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 0)]
for seq in permutations(permut):
	copy_a = a.copy()
	copy_b = b.copy()
	no_win = 0
	for i in seq:
		a_i = i[1]
		b_i = i[0]
		delta = min(copy_a[a_i], copy_b[b_i])
		no_win += delta
		copy_a[a_i] -= delta
		copy_b[b_i] -= delta
	mini = min(mini, n - no_win)
print(mini, maxi)


n = int(input())
bob = [int(z) for z in input().split()]
alice = [int(z) for z in input().split()]
bobrock = bob[0]
bobscissors = bob[1]
bobpaper = bob[2]
alicerock = alice[0]
alicescissors = alice[1]
alicepaper = alice[2]
minimum = 0
maximum = 0
maximum += min(alicerock, bobpaper)
maximum += min(alicescissors, bobrock)
maximum += min(alicepaper, bobscissors)
minimum = bobrock - alicepaper - alicerock
minimum = max(minimum, bobscissors - alicescissors - alicerock)
minimum = max(minimum, bobpaper - alicepaper - alicescissors)
print(max(0, minimum), maximum)


n = int(input())
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
minw = 0
if a[0] > b[0] + b[2]:
	minw += a[0] - b[0] - b[2]
if a[1] > b[0] + b[1]:
	minw += a[1] - b[0] - b[1]
if a[2] > b[1] + b[2]:
	minw += a[2] - b[1] - b[2]
maxw = min(a[0], b[1]) + min(a[2], b[0]) + min(a[1], b[2])
print(minw, maxw)


n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
mm = min(l[0], d[1]) + min(l[1], d[2]) + min(d[0], l[2])
x = min(l[0], n - d[1]) + min(l[1], n - d[2]) + min(l[2], n - d[0])
print(n - x, mm)


from collections import deque

class Dinic:

	def __init__(self, N):
		self.N = N
		self.G = [[] for i in range(N)]

	def add_edge(self, fr, to, cap):
		forward = [to, cap, None]
		forward[2] = backward = [fr, 0, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def add_multi_edge(self, v1, v2, cap1, cap2):
		edge1 = [v2, cap1, None]
		edge1[2] = edge2 = [v1, cap2, edge1]
		self.G[v1].append(edge1)
		self.G[v2].append(edge2)

	def bfs(self, s, t):
		self.level = level = [None] * self.N
		deq = deque([s])
		level[s] = 0
		G = self.G
		while deq:
			v = deq.popleft()
			lv = level[v] + 1
			for (w, cap, _) in G[v]:
				if cap and level[w] is None:
					level[w] = lv
					deq.append(w)
		return level[t] is not None

	def dfs(self, v, t, f):
		if v == t:
			return f
		level = self.level
		for e in self.it[v]:
			(w, cap, rev) = e
			if cap and level[v] < level[w]:
				d = self.dfs(w, t, min(f, cap))
				if d:
					e[1] -= d
					rev[1] += d
					return d
		return 0

	def flow(self, s, t):
		flow = 0
		INF = 10 ** 18
		G = self.G
		while self.bfs(s, t):
			(*self.it,) = map(iter, self.G)
			f = INF
			while f:
				f = self.dfs(s, t, INF)
				flow += f
		return flow
(N,) = map(int, input().split())
(a, b, c) = map(int, input().split())
(x, y, z) = map(int, input().split())
INF = 10 ** 9
dnc = Dinic(8)
dnc.add_edge(0, 1, a)
dnc.add_edge(0, 2, b)
dnc.add_edge(0, 3, c)
dnc.add_edge(1, 4, INF)
dnc.add_edge(2, 5, INF)
dnc.add_edge(3, 6, INF)
dnc.add_edge(1, 6, INF)
dnc.add_edge(2, 4, INF)
dnc.add_edge(3, 5, INF)
dnc.add_edge(4, 7, x)
dnc.add_edge(5, 7, y)
dnc.add_edge(6, 7, z)
print(N - dnc.flow(0, 7), min(a, y) + min(b, z) + min(c, x))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')

def solve(steps, a1, a2, a3, b1, b2, b3):
	for step in steps:
		if step == 1:
			temp = min(a1, b3)
			(a1, b3) = (a1 - temp, b3 - temp)
		elif step == 2:
			temp = min(a2, b1)
			(a2, b1) = (a2 - temp, b1 - temp)
		elif step == 3:
			temp = min(a3, b2)
			(a3, b2) = (a3 - temp, b2 - temp)
		elif step == 4:
			temp = min(a1, b1)
			(a1, b1) = (a1 - temp, b1 - temp)
		elif step == 5:
			temp = min(a2, b2)
			(a2, b2) = (a2 - temp, b2 - temp)
		else:
			temp = min(a3, b3)
			(a3, b3) = (a3 - temp, b3 - temp)
	return a1 + a2 + a3
t = 1
for _ in range(t):
	n = ip()
	(a1, a2, a3) = inp()
	(b1, b2, b3) = inp()
	maxans = 0
	maxans += min(a1, b2) + min(a2, b3) + min(a3, b1)
	st = [i for i in range(1, 7)]
	st = permutations(st)
	minans = float('inf')
	for i in st:
		minans = min(minans, solve(i, int(a1), int(a2), int(a3), int(b1), int(b2), int(b3)))
	print(minans, maxans)


from itertools import permutations
n = int(input())
(a, b, c) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
maxi = min(a, y) + min(b, z) + min(c, x)

def solve(p, q):
	temp = min(p, q)
	p -= temp
	q -= temp
	return (p, q)
lis = permutations([0, 1, 2, 3, 4, 5])
mini = maxi
for num in lis:
	arr1 = [a, b, c]
	arr2 = [x, y, z]
	arr = [[0, 0], [0, 2], [1, 1], [1, 0], [2, 2], [2, 1]]
	for i in range(6):
		(arr1[arr[num[i]][0]], arr2[arr[num[i]][1]]) = solve(arr1[arr[num[i]][0]], arr2[arr[num[i]][1]])
	mini = min(mini, (sum(arr1) + sum(arr2)) // 2)
print(mini, maxi)


n = int(input())
(a, b, c) = map(int, input().split())
(a1, b1, c1) = map(int, input().split())
m = min(a, b1) + min(b, c1) + min(c, a1)
s1 = a1 - a - b
s2 = b1 - b - c
s3 = c1 - c - a
if max(s1, s2, s3) < 0:
	print(0, m)
else:
	print(max(s1, s2, s3), m)


from sys import stdin
input = stdin.readline
from collections import defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	t = [min(a[0], b[1]), min(a[1], b[2]), min(a[2], b[0])]
	maxindex = sorted([0, 1, 2], key=lambda x: t[x], reverse=True)
	for i in maxindex:
		i %= 3
		a[i] -= min(a[i], b[i])
		b[i] -= min(a[i], b[i])
		a[i] -= min(a[i], b[i - 1])
		b[i - 1] -= min(a[i], b[i - 1])
	mn = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	print(mn, mx)
solve()


n = int(input())
s = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
low = max(b[0] - s[0] - s[1], 0) + max(b[1] - s[2] - s[1], 0) + max(b[2] - s[0] - s[2], 0)
high = min(s[0], b[1]) + min(s[1], b[2]) + min(s[2], b[0])
print(low, high)


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

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

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
n = iinp()
(a1, a2, a3) = ninp()
(b1, b2, b3) = ninp()
w = min(a1, b2) + min(a2, b3) + min(a3, b1)
l = min(a1, n - b2) + min(a2, n - b3) + min(a3, n - b1)
print(n - l, w)


import sys
from collections import deque
from math import ceil, sqrt, gcd, factorial
from bisect import bisect_right, bisect_left
mod = 1000000007
INF = 10 ** 18
NINF = -INF

def INT():
	return int(input())

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

def LIST():
	return list(map(int, input().split()))

def modi(x):
	return pow(x, mod - 2, mod)

def lcm(x, y):
	return x * y // gcd(x, y)

def write(l):
	for i in l:
		print(i, end=' ')
	print()
n = int(input())
(r, s, p) = MAP()
(rr, ss, pp) = MAP()
maxa = min(r, ss) + min(s, pp) + min(p, rr)
mini = min(r, rr + pp) + min(s, ss + rr) + min(p, pp + ss)
print(n - mini, maxa)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var, end='\n'):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def recur(ra, sa, pa, rb, sb, pb):
	if ra + sa + pa + rb + sb + pb == 0:
		return 0
	answer = 0
	if ra:
		if rb:
			m = min(ra, rb)
			answer = max(answer, recur(ra - m, sa, pa, rb - m, sb, pb))
		if sb:
			m = min(ra, sb)
			answer = max(answer, recur(ra - m, sa, pa, rb, sb - m, pb) + m)
		if pb:
			m = min(ra, pb)
			answer = max(answer, recur(ra - m, sa, pa, rb, sb, pb - m))
	if sa:
		if rb:
			m = min(sa, rb)
			answer = max(answer, recur(ra, sa - m, pa, rb - m, sb, pb))
		if sb:
			m = min(sa, sb)
			answer = max(answer, recur(ra, sa - m, pa, rb, sb - m, pb))
		if pb:
			m = min(sa, pb)
			answer = max(answer, recur(ra, sa - m, pa, rb, sb, pb - m) + m)
	if pa:
		if rb:
			m = min(pa, rb)
			answer = max(answer, recur(ra, sa, pa - m, rb - m, sb, pb) + m)
		if sb:
			m = min(pa, sb)
			answer = max(answer, recur(ra, sa, pa - m, rb, sb - m, pb))
		if pb:
			m = min(pa, pb)
			answer = max(answer, recur(ra, sa, pa - m, rb, sb, pb - m))
	return answer
n = int(data())
(a1, b1, c1) = sp()
(a2, b2, c2) = sp()
print(max(0, a1 - a2 - c2, b1 - b2 - a2, c1 - b2 - c2), recur(a1, b1, c1, a2, b2, c2))


def cal(n, alice, bob):
	(min_alice, max_alice) = (0, 0)
	temp_bob = 0
	for i in range(3):
		alice_i = (i + 1) % 3
		win = min(bob[i], alice[alice_i])
		draw = min(alice[i], bob[i] - win)
		temp_bob += win + draw
	for i in range(3):
		bob_i = (i + 1) % 3
		max_alice += min(alice[i], bob[bob_i])
	min_alice = n - temp_bob
	print(min_alice, max_alice)
n = int(input())
alice = list(map(int, input().split()))
bob = list(map(int, input().split()))
cal(n, alice, bob)


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col

def solve():
	N = getInt()
	(A1, A2, A3) = getInts()
	(B1, B2, B3) = getInts()
	best = min(A1, B2) + min(A2, B3) + min(A3, B1)
	worst = max(A1 - (B1 + B3), A2 - (B2 + B1), A3 - (B3 + B2), 0)
	print(worst, best)
	return
solve()


def solve(n, a, b):
	maxi = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	mini = max(a[0] + b[1] - n, 0) + max(a[1] + b[2] - n, 0) + max(a[2] + b[0] - n, 0)
	print(mini, maxi)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
solve(n, a, b)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxA = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
minA = max(0, a[0] - b[0] - b[2], a[1] - b[0] - b[1], a[2] - b[2] - b[1])
print(minA, maxA)


def maxV(first, second):
	return str(min(first[0], second[1]) + min(first[1], second[2]) + min(first[2], second[0]))

def minV(first, second):
	vitPedra = first[0] - (second[0] + second[2])
	vitTesoura = first[1] - (second[0] + second[1])
	vitPapel = first[2] - (second[1] + second[2])
	return str(max(vitPedra, 0) + max(vitTesoura, 0) + max(vitPapel, 0))
n = int(input())
alice = [int(k) for k in input().split()]
bob = [int(k) for k in input().split()]
print(minV(alice, bob), maxV(alice, bob))


import math
from collections import deque
from collections import defaultdict
n = int(input())
(a1, a2, a3) = map(int, input().strip().split(' '))
(b1, b2, b3) = map(int, input().strip().split(' '))
(d1, d2, d3) = (a1, a2, a3)
(e1, e2, e3) = (b1, b2, b3)
mxa = min(a1, b2) + min(a2, b3) + min(a3, b1)
c4 = min(a1, b1)
c5 = min(a2, b2)
c6 = min(a3, b3)
a1 -= c4
a2 -= c5
a3 -= c6
c1 = min(b1, a2)
b1 -= c1
a2 -= c1
c2 = min(b2, a3)
b2 -= c2
a3 -= c2
c3 = min(b3, a1)
b3 -= c3
a1 -= c3
c1 = min(e1, d2)
e1 -= c1
d2 -= c1
c2 = min(e2, d3)
e2 -= c2
d3 -= c2
c3 = min(e3, d1)
e3 -= c3
d1 -= c3
c4 = min(d1, e1)
c5 = min(d2, e2)
c6 = min(d3, e3)
e1 -= c4
e2 -= c5
e3 -= c6
print(min(a1 + a2 + a3, e1 + e2 + e3), mxa)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	(a1, a2, a3) = sep()
	(b1, b2, b3) = sep()
	a = [a1, a2, a3]
	b = [b1, b2, b3]
	ans = 0
	ans += min(a1, b2) + min(a2, b3) + min(a3, b1)
	ans1 = 0
	for i in range(3):
		ans1 += max(0, a[i] + b[(i + 1) % 3] - n)
	print(ans1, ans)
testcase(1)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
mx = min(a1, b2) + min(a2, b3) + min(a3, b1)
if a1 >= b1 + b3:
	mn = a1 - (b1 + b3)
elif a2 >= b2 + b1:
	mn = a2 - (b2 + b1)
elif a3 >= b3 + b2:
	mn = a3 - (b3 + b2)
else:
	mn = 0
print(mn, mx)


n1 = int(input())
(x, y, z) = map(int, input().strip().split())
(m, n, o) = map(int, input().strip().split())
a = min(x, n) + min(y, o) + min(z, m)
b = min(n1 - n, x) + min(n1 - m, z) + min(n1 - o, y)
j = n1 - b
if j < 0:
	j = 0
print(j, a)


n = int(input())
z = list(map(int, input().split()))
a1 = z[0]
a2 = z[1]
a3 = z[2]
z = list(map(int, input().split()))
b1 = z[0]
b2 = z[1]
b3 = z[2]
d = a1
e = a2
f = a3
minn = n
maxn = max(min(a1, b2), 0) + max(min(a2, b3), 0) + max(min(a3, b1), 0)
minn -= min(a1, b3)
a1 -= min(a1, b3)
b3 -= min(a1, b3)
minn -= min(a1, b1)
a1 -= min(a1, b1)
b1 -= min(a1, b1)
minn -= min(a2, b1)
a2 -= min(a2, b1)
b1 -= min(a2, b1)
minn -= min(a2, b2)
a2 -= min(a2, b2)
b2 -= min(a2, b2)
minn -= min(a3, b3)
a3 -= min(a3, b3)
b3 -= min(a3, b3)
minn -= min(a3, b2)
a3 -= min(a3, b2)
b2 -= min(a3, b2)
minn2 = n
b1 = z[0]
b2 = z[1]
b3 = z[2]
a1 = d
a2 = e
a3 = f
minn2 -= min(a2, b1)
a2 -= min(a2, b1)
b1 -= min(a2, b1)
minn2 -= min(a2, b2)
a2 -= min(a2, b2)
b2 -= min(a2, b2)
minn2 -= min(a1, b1)
a1 -= min(a1, b1)
b1 -= min(a1, b1)
minn2 -= min(a1, b3)
a1 -= min(a1, b3)
b3 -= min(a1, b3)
minn2 -= min(a3, b3)
a3 -= min(a3, b3)
b3 -= min(a3, b3)
minn2 -= min(a3, b2)
a3 -= min(a3, b2)
b2 -= min(a3, b2)
minn3 = n
b1 = z[0]
b2 = z[1]
b3 = z[2]
minn3 -= min(a3, b3)
a3 -= min(a3, b3)
b3 -= min(a3, b3)
minn3 -= min(a3, b2)
a3 -= min(a3, b2)
b2 -= min(a3, b2)
minn3 -= min(a1, b1)
a1 -= min(a1, b1)
b1 -= min(a1, b1)
minn3 -= min(a1, b3)
a1 -= min(a1, b3)
b3 -= min(a1, b3)
minn3 -= min(a2, b1)
a2 -= min(a2, b1)
b1 -= min(a2, b1)
minn3 -= min(a2, b2)
a2 -= min(a2, b2)
b2 -= min(a2, b2)
a1 = d
a2 = e
a3 = f
print(min(minn3, minn2, minn), maxn)


import math
import itertools
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))
ans = 0
n = inp()
a = inlt()
b = inlt()
c = [a[1], b[2]]
d = [a[2], b[0]]
e = [a[0], b[1]]
x = [b[0], a[1]]
y = [b[1], a[2]]
z = [b[2], a[0]]
m = itertools.permutations([(0, 0), (0, 2), (1, 1), (1, 0), (2, 2), (2, 1)])
res = 9 ** 99
for val in m:
	ans = 0
	array = a[:]
	array2 = b[:]
	f = n
	for i in range(6):
		(j, k) = map(int, val[i])
		array[j] -= min(array[j], array2[k])
		array2[k] -= min(array[j], array2[k])
	res = min(res, min(array[0], array2[1]) + min(array[1], array2[2]) + min(array[2], array2[0]))
print(res, min(c) + min(d) + min(e))


n = int(input())
(ra, sa, pa) = map(int, input().split())
(rb, sb, pb) = map(int, input().split())
maxa = min(ra, sb) + min(sa, pb) + min(pa, rb)
(rbsb, sbpb, pbrb) = (rb + sb, sb + pb, pb + rb)
l = [[ra, 0], [sa, 1], [pa, 2]]
l2 = [rb, sb, pb]
l3 = [i[:] for i in l]
l4 = l2[:]
l.sort(reverse=True)
l3.sort()
(mina, mina2) = (0, 0)
for i in l:
	pq = min(i[0], l2[i[1]])
	i[0] = max(0, i[0] - pq)
	l2[i[1]] = max(0, l2[i[1]] - pq)
	pq1 = min(i[0], l2[(i[1] + 2) % 3])
	i[0] = max(0, i[0] - pq1)
	l2[(i[1] + 2) % 3] = max(0, l2[(i[1] + 2) % 3] - pq1)
	mina += pq1 + pq
for i in l3:
	pq = min(i[0], l4[i[1]])
	i[0] = max(0, i[0] - pq)
	l4[i[1]] = max(0, l4[i[1]] - pq)
	pq1 = min(i[0], l4[(i[1] + 2) % 3])
	i[0] = max(0, i[0] - pq1)
	l4[(i[1] + 2) % 3] = max(0, l4[(i[1] + 2) % 3] - pq1)
	mina2 += pq1 + pq
print(min(n - mina, n - mina2), maxa)


n = int(input())
arr = input().split()
brr = input().split()
sz = len(arr)
(ans1, ans2) = (0, 0)
for i in range(sz):
	arr[i] = int(arr[i])
	brr[i] = int(brr[i])
ans1 = n - (min(arr[0], brr[0] + brr[2]) + min(arr[1], brr[1] + brr[0]) + min(arr[2], brr[2] + brr[1]))
ans2 = min(arr[0], brr[1]) + min(arr[1], brr[2]) + min(arr[2], brr[0])
print(ans1, ans2)


n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())

def ma(a1, a2, a3, b1, b2, b3):
	if b1 >= a1 + a2:
		return a1 + a2 + min(b2 + b3, a3)
	if b2 >= a2 + a3:
		return a2 + a3 + min(b3 + b1, a1)
	if b3 >= a3 + a1:
		return a3 + a1 + min(b1 + b2, a2)
	return b1 + b2 + b3
maxx = min(a1, b2) + min(a2, b3) + min(a3, b1)
minn = n - ma(a1, a2, a3, b1, b2, b3)
print(minn, maxx)


def maxVitoriasP1(p1, p2):
	[pedra1, tesoura1, papel1] = p1
	[pedra2, tesoura2, papel2] = p2
	return str(min(pedra1, tesoura2) + min(tesoura1, papel2) + min(papel1, pedra2))

def minVitoriasP1(p1, p2):
	[pedra1, tesoura1, papel1] = p1
	[pedra2, tesoura2, papel2] = p2
	vitoriaCertaPedra = pedra1 - (pedra2 + papel2)
	vitoriaCertaTesoura = tesoura1 - (pedra2 + tesoura2)
	vitoriaCertaPapel = papel1 - (tesoura2 + papel2)
	return str(max(vitoriaCertaPedra, 0) + max(vitoriaCertaTesoura, 0) + max(vitoriaCertaPapel, 0))
n = int(input())
alice = [int(i) for i in input().split()]
bob = [int(i) for i in input().split()]
print(minVitoriasP1(alice, bob) + ' ' + maxVitoriasP1(alice, bob))


def rps(n, a, b):
	win = [1, 2, 0]
	lose = [[0, 2], [1, 0], [2, 1]]
	amax = 0
	amin = 0
	for i in range(len(a)):
		amax += min(a[i], b[win[i]])
		amin += max(0, a[i] - b[lose[i][0]] - b[lose[i][1]])
	return [amin, amax]
n = int(input())
ali = list(map(int, input().split()))
bob = list(map(int, input().split()))
print(*rps(n, ali, bob))


n = int(input())
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
d = [[a[q], b[q]] for q in range(3)]
small = 0
large = 0
for i in range(3):
	large += min(d[i][0], d[(i + 1) % 3][1])
	small += max(0, d[i][0] - n + d[(i + 1) % 3][1])
print(small, large)


n_rounds = int(input())
(rock_a, scissors_a, paper_a) = [int(i) for i in input().split()]
(rock_b, scissors_b, paper_b) = [int(i) for i in input().split()]
max_total = 0
min_total = 0
if scissors_b <= rock_a:
	max_total += scissors_b
else:
	max_total += rock_a
if paper_b <= scissors_a:
	max_total += paper_b
else:
	max_total += scissors_a
if rock_b <= paper_a:
	max_total += rock_b
else:
	max_total += paper_a
min_total = max([0, scissors_b - paper_a - scissors_a, paper_b - rock_a - paper_a, rock_b - scissors_a - rock_a])
print('{} {}'.format(min_total, max_total))


import sys
input = sys.stdin.readline
x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
MAX = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
MIN = 0
tmp = min(a[0], b[0] + b[2])
a[0] -= tmp
ttmp = min(a[1], b[0] + b[1])
a[1] -= ttmp
tttmp = min(a[2], b[1] + b[2])
a[2] -= tttmp
print(sum(a), MAX)


class FordFulkerson:

	def __init__(self, N):
		self.N = N
		self.edge = [[] for i in range(N)]

	def add_edge(self, fr, to, cap):
		forward = [to, cap, None]
		forward[2] = backward = [fr, 0, forward]
		self.edge[fr].append(forward)
		self.edge[to].append(backward)

	def add_multi_edge(self, v1, v2, cap1, cap2):
		edge1 = [v2, cap1, None]
		edge1[2] = edge2 = [v1, cap2, edge1]
		self.edge[v1].append(edge1)
		self.edge[v2].append(edge2)

	def dfs(self, v, t, f):
		if v == t:
			return f
		used = self.used
		used[v] = 1
		for e in self.edge[v]:
			(w, cap, rev) = e
			if cap and (not used[w]):
				d = self.dfs(w, t, min(f, cap))
				if d:
					e[1] -= d
					rev[1] += d
					return d
		return 0

	def flow(self, s, t):
		flow = 0
		f = INF = 10 ** 9 + 7
		N = self.N
		while f:
			self.used = [False] * N
			f = self.dfs(s, t, INF)
			flow += f
		return flow
import sys
readline = sys.stdin.readline
INF = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
maxi = min(B[0], A[2]) + min(B[1], A[0]) + min(B[2], A[1])
ff = FordFulkerson(8)
for i in range(1, 4):
	ff.add_edge(0, i, A[i - 1])
	ff.add_edge(3 + i, 7, B[i - 1])
dic = {1: 6, 2: 4, 3: 5}
for i in range(3):
	ff.add_edge(i + 1, dic[i + 1], INF)
	ff.add_edge(i + 1, 3 + (i + 1), INF)
mini = N - ff.flow(0, 7)
print(mini, maxi)


def count_wins(a1, a2, a3, b1, b2, b3):
	return min(a1, b2) + min(a2, b3) + min(a3, b1)

def solve_e(a1, a2, a3, b1, b2, b3):
	wins = count_wins(a1, a2, a3, b1, b2, b3)
	loses = max(0, a1 - b1 - b3) + max(0, a2 - b2 - b1) + max(0, a3 - b2 - b3)
	return (loses, wins)
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
print(*solve_e(*a, *b))


t = int(input())
(a, b, c) = [int(x) for x in input().split()]
(d, e, f) = [int(x) for x in input().split()]
max = min(a, e) + min(b, f) + min(c, d)
min = min(a, t - e) + min(b, t - f) + min(c, t - d)
print(t - min, max)


n = int(input())
(ra, sa, pa) = map(int, input().split())
(rb, sb, pb) = map(int, input().split())
maxw = min(ra, sb) + min(sa, pb) + min(pa, rb)
minw = n - (min(rb, ra + sa) + min(sb, sa + pa) + min(pb, ra + pa))
print(minw, maxw)


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(1):
	n = int(input())
	(a1, a2, a3) = put()
	(b1, b2, b3) = put()
	mx = min(a1, b2) + min(a2, b3) + min(a3, b1)
	mn = n
	if a1 <= b3:
		mn -= min(a1, b3)
		a1 = 0
		b3 -= a1
	else:
		mn -= min(a1, b3)
		b3 = 0
		a1 -= b3
	if a2 <= b1:
		mn -= min(a2, b1)
		a2 = 0
		b1 -= a2
	else:
		mn -= min(a2, b1)
		b1 = 0
		a2 -= b1
	if a3 <= b2:
		mn -= min(a3, b2)
		a3 = 0
		b2 -= a3
	else:
		mn -= min(a3, b2)
		b2 = 0
		a3 -= b2
	print(max(0, mn - min(a1, b1) - min(a2, b2) - min(a3, b3)), mx)


n = int(input())
(a1, a3, a2) = map(int, input().split())
(b1, b3, b2) = map(int, input().split())
maxx = min(a1, b3) + min(a2, b1) + min(a3, b2)
minn = max(0, a1 - b1 - b2) + max(0, a2 - b2 - b3) + max(0, a3 - b3 - b1)
print(minn, maxx)


import os
from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.readlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx].strip()
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def has_next(self):
		return self.idx < len(self.lines)

def known_cases(func):
	inpt = Input()
	(cases,) = inpt.array()
	for case in range(cases):
		func(inpt)

def unknown_cases(func):
	inpt = Input()
	while inpt.has_next():
		func(inpt)
import math

@unknown_cases
def solve(inpt):
	(n,) = inpt.array()
	a = inpt.array()
	b = inpt.array()
	mx = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	mn = [min(a[0] - (n - b[1]), b[1]), min(a[1] - (n - b[2]), b[2]), min(a[2] - (n - b[0]), b[0])]
	print(max(0, *mn), mx)


import math
teststring = '686\n479 178 29\n11 145 530\n'
online = __file__ != '/home/jhli/py/674/Problem_E.py'
(true, false) = (True, False)
if True:

	def spitout():
		for c in teststring.splitlines():
			yield c
	_ito = spitout()
	if not online:

		def input():
			return next(_ito)

	def build_enum(*a):
		built = dict()
		for (i, c) in enumerate(a):
			built[c] = i
		return lambda x: built[x]
T = int(input())
a = []
b = []
a.extend(map(int, input().split(' ')))
b.extend(map(int, input().split(' ')))
M = min(a[1], b[2]) + min(a[2], b[0]) + min(a[0], b[1])
m = 0
if b[0] + b[1] <= a[1]:
	m = a[1] - b[0] - b[1]
elif b[1] + b[2] <= a[2]:
	m = a[2] - b[1] - b[2]
elif b[2] + b[0] <= a[0]:
	m = a[0] - b[2] - b[0]
print(' '.join(map(str, [m, M])))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
n = N()
a = RLL()
b = RLL()
ma = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
mi = max(0, a[0] - b[0] - b[2], a[1] - b[1] - b[0], a[2] - b[2] - b[1])
print(mi, ma)


n = int(input())
(a1, b1, c1) = map(int, input().split())
(a2, b2, c2) = map(int, input().split())
mx = min(a1, b2) + min(b1, c2) + min(c1, a2)
mxb = min(a2, b1) + min(b2, c1) + min(c2, a1)
mn1 = a2 - a1 - b1
mn2 = b2 - c1 - b1
mn3 = c2 - a1 - c1
print(max(0, mn1, mn2, mn3), mx)


n = int(input())
for _ in range(1):
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	ansa = min(a1, b2) + min(a2, b3) + min(a3, b1)
	ansb = min(a1, n - b2) + min(a2, n - b3) + min(a3, n - b1)
	print(n - ansb)
	print(ansa)


n = int(input())
(k1, n1, b1) = map(int, input().split())
(k2, n2, b2) = map(int, input().split())
max = min(k1, n2) + min(n1, b2) + min(b1, k2)
min = min(k1, n - n2) + min(n1, n - b2) + min(b1, n - k2)
print(n - min, max)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	ans2 = min(a1, b2) + min(a2, b3) + min(a3, b1)
	(p, q, r, s, t, u) = (a1, a2, a3, b1, b2, b3)
	ans = 696969696969696
	from itertools import permutations
	for pp in permutations([1, 2, 3, 4, 5, 6]):
		(a1, a2, a3, b1, b2, b3) = (p, q, r, s, t, u)
		for i in pp:
			if i == 1:
				x = min(a1, b1)
				a1 -= x
				b1 -= x
			if i == 2:
				x = min(a1, b3)
				a1 -= x
				b3 -= x
			if i == 3:
				x = min(a2, b2)
				a1 -= x
				b2 -= x
			if i == 4:
				x = min(a2, b1)
				a2 -= x
				b1 -= x
			if i == 5:
				x = min(a3, b3)
				a3 -= x
				b3 -= x
			if i == 6:
				x = min(a3, b2)
				a3 -= x
				b2 -= x
		ans = min(ans, a1 + a2 + a3)
	print(ans, ans2)


import sys
import math
from collections import defaultdict, Counter
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
s1 = min(b1, a2)
s2 = min(b2, a3)
s3 = min(b3, a1)
mi = s1 + s2 + s3
mi = min(b1, a2) + min(b2, a3) + min(b3, a1)
mi += min(a1, b1 - s1) + min(a2, b2 - s2) + min(a3, b3 - s3)
print(n - mi, ma)


def main():
	n = int(input())
	a = map(int, input().split(' '))
	b = map(int, input().split(' '))
	a = [i for i in a]
	b = [i for i in b]
	ma = 0
	mi = 0
	ma = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	if min(a[0], b[1]) > min(a[1], b[2]) and min(a[0], b[1]) > min(a[2], b[0]):
		mi = a[0] - b[0] - b[2]
		if mi < 0:
			mi = 0
	elif min(a[1], b[2]) > min(a[0], b[1]) and min(a[1], b[2]) > min(a[2], b[0]):
		mi = a[1] - b[1] - b[0]
		if mi < 0:
			mi = 0
	elif min(a[2], b[0]) > min(a[1], b[2]) and min(a[2], b[0]) > min(a[0], b[1]):
		mi = a[2] - b[2] - b[1]
		if mi < 0:
			mi = 0
	print(mi, ma)
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if a.get_at(m)[0] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
n = int(input())
(a1, a2, a3) = map(int, input().split())
(b1, b2, b3) = map(int, input().split())
ma = min(a1, b2) + min(a2, b3) + min(a3, b1)
a = min(a1, b1 + b3)
b = min(a2, b2 + b1)
c = min(a3, b3 + b2)
mi = n - a - b - c
print(mi, ma)


def findWins(n, a, b):
	maxAliceWins = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	minAliceWins = max(0, b[0] - a[0] - a[1]) + max(0, b[1] - a[1] - a[2]) + max(0, b[2] - a[2] - a[0])
	print(minAliceWins, maxAliceWins)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
findWins(n, a, b)


def find_min(min_wins, a1, a2, a3, b1, b2, b3):
	if a1 != 0 and b3 != 0 and (b1 != 0):
		if a1 > b3 and a1 > b1:
			return min(find_min(min_wins - b3, a1 - b3, a2, a3, b1, b2, 0), find_min(min_wins - b1, a1 - b1, a2, a3, 0, b2, b3))
		elif a1 > b3 and a1 < b1:
			return min(find_min(min_wins - b3, a1 - b3, a2, a3, b1, b2, 0), find_min(min_wins - a1, 0, a2, a3, b1 - a1, b2, b3))
		elif a1 < b3 and a1 > b1:
			return min(find_min(min_wins - a1, 0, a2, a3, b1, b2, b3 - a1), find_min(min_wins - b1, a1 - b1, a2, a3, 0, b2, b3))
		else:
			return min(find_min(min_wins - a1, 0, a2, a3, b1, b2, b3 - a1), find_min(min_wins - a1, 0, a2, a3, b1 - a1, b2, b3))
	elif a1 != 0 and b1 != 0:
		if a1 > b1:
			return find_min(min_wins - b1, a1 - b1, a2, a3, 0, b2, b3)
		else:
			return find_min(min_wins - a1, 0, a2, a3, b1 - a1, b2, b3)
	elif a1 != 0 and b3 != 0:
		if a1 > b3:
			return find_min(min_wins - b3, a1 - b3, a2, a3, b1, b2, 0)
		else:
			return find_min(min_wins - a1, 0, a2, a3, b1, b2, b3 - a1)
	if a2 != 0 and b1 != 0 and (b2 != 0):
		if a2 > b1 and a2 > b2:
			return min(find_min(min_wins - b1, a1, a2 - b1, a3, 0, b2, b3), find_min(min_wins - b2, a1, a2 - b2, a3, b1, 0, b3))
		elif a2 > b1 and a2 < b2:
			return min(find_min(min_wins - b1, a1, a2 - b1, a3, 0, b2, b3), find_min(min_wins - a2, a1, 0, a3, b1, b2 - a2, b3))
		elif a2 < b1 and a2 > b2:
			return min(find_min(min_wins - a2, a1, 0, a3, b1 - a2, b2, b3), find_min(min_wins - b2, a1, a2 - b2, a3, b1, 0, b3))
		else:
			return min(find_min(min_wins - a2, a1, 0, a3, b1 - a2, b2, b3), find_min(min_wins - a2, a1, 0, a3, b1, b2 - a2, b3))
	elif a2 != 0 and b2 != 0:
		if a2 > b2:
			return find_min(min_wins - b2, a1, a2 - b2, a3, b1, 0, b3)
		else:
			return find_min(min_wins - a2, a1, 0, a3, b1, b2 - a2, b3)
	elif a2 != 0 and b1 != 0:
		if a2 > b1:
			return find_min(min_wins - b1, a1, a2 - b1, a3, 0, b2, b3)
		else:
			return find_min(min_wins - a2, a1, 0, a3, b1 - a2, b2, b3)
	if a3 != 0 and b2 != 0 and (b3 != 0):
		if a3 > b2 and a3 > b3:
			return min(find_min(min_wins - b2, a1, a2, a3 - b2, b1, 0, b3), find_min(min_wins - b3, a1, a2, a3 - b3, b1, b2, 0))
		elif a3 > b2 and a3 < b3:
			return min(find_min(min_wins - b2, a1, a2, a3 - b2, b1, 0, b3), find_min(min_wins - a3, a1, a2, 0, b1, b2, b3 - a3))
		elif a3 < b2 and a3 > b3:
			return min(find_min(min_wins - a3, a1, a2, 0, b1, b2 - a3, b3), find_min(min_wins - b3, a1, a2, a3 - b3, b1, b2, 0))
		else:
			return min(find_min(min_wins - a3, a1, a2, 0, b1, b2 - a3, b3), find_min(min_wins - a3, a1, a2, 0, b1, b2, b3 - a3))
	elif a3 != 0 and b3 != 0:
		if a3 > b3:
			return find_min(min_wins - b3, a1, a2, a3 - b3, b1, b2, 0)
		else:
			return find_min(min_wins - a3, a1, a2, 0, b1, b2, b3 - a3)
	elif a3 != 0 and b2 != 0:
		if a3 > b2:
			return find_min(min_wins - b2, a1, a2, a3 - b2, b1, 0, b3)
		else:
			return find_min(min_wins - a3, a1, a2, 0, b1, 0, b3)
	return min_wins
n = int(input())
(a1, a2, a3) = list(map(int, input().split()))
(b1, b2, b3) = list(map(int, input().split()))
max_wins = min(a1, b2) + min(a2, b3) + min(a3, b1)
min_wins = min(find_min(n, a1, a2, a3, b1, b2, b3), find_min(n, a2, a3, a1, b2, b3, b1), find_min(n, a3, a1, a2, b3, b1, b2))
print(min_wins, max_wins)


import sys
n = int(sys.stdin.readline())
(a1, a2, a3) = map(int, sys.stdin.readline().split())
(b1, b2, b3) = map(int, sys.stdin.readline().split())
win = min(a1, b2) + min(a2, b3) + min(a3, b1)
lose = n - min(a1, b1 + b3) - min(a2, b2 + b1) - min(a3, b3 + b2)
print(lose, win)


import os
import sys
from io import BytesIO, IOBase
import math

def main1():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		if n <= 2:
			print(1)
		else:
			n -= 2
			print(1 + math.ceil(n / x))

def main2():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		flag = 0
		for i in range(n):
			mat = []
			for j in range(2):
				mat.append(list(map(int, input().split())))
			if mat[0][1] == mat[1][0]:
				flag = 1
		if m % 2 or flag == 0:
			print('NO')
		else:
			print('YES')

def main3():
	for _ in range(int(input())):
		n = int(input())
		ans = float('inf')
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			ans = min(ans, i - 1 + (n - i + i - 1) // i)
		print(ans)

def main4():
	n = int(input())
	a = list(map(int, input().split()))
	ls = [0] * n
	ls[0] = a[0]
	for i in range(1, n):
		ls[i] = ls[i - 1] + a[i]
	ans = 0
	d = dict()
	d[0] = 0
	d[ls[0]] = 0
	prev_pos = 0
	for i in range(1, n):
		if ls[i] in d:
			pos = d[ls[i]] + 1
			if pos >= prev_pos:
				prev_pos = i
				ans += 1
		d[ls[i]] = i
	print(ans)

def main5():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_win = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	min_win = max(0, a[0] - b[0] - b[2]) + max(0, a[1] - b[1] - b[0]) + max(0, a[2] - b[2] - b[1])
	print(min_win, max_win)

def main6():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main5()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
k = 0
for i in range(3):
	if a[i] - b[i] - b[i - 1] >= 0:
		k = a[i] - b[i] - b[i - 1]
		break
print(k, m)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def reVal(num):
	if num >= 0 and num <= 9:
		return chr(num + ord('0'))
	else:
		return chr(num - 10 + ord('A'))

def strev(str):
	len = len(str)
	for i in range(int(len / 2)):
		temp = str[i]
		str[i] = str[len - i - 1]
		str[len - i - 1] = temp

def fromDeci(res, base, inputNum):
	index = 0
	while inputNum > 0:
		res += reVal(inputNum % base)
		inputNum = int(inputNum / base)
	res = res[::-1]
	return res

def norm(s, l):
	tba = '0' * (l - len(s))
	return tba + s
n = int(input())
(ra, sa, pa) = map(int, input().split())
(rb, sb, pb) = map(int, input().split())
ma = min(ra, sb)
ma += min(sa, pb)
ma += min(pa, rb)
mi = n - min(ra, rb + pb)
mi -= min(sa, sb + rb)
mi -= min(pa, pb + sb)
print(mi, ma)


def min_wins(c, d):

	def compute(arr):
		a = c.copy()
		b = d.copy()
		for i in arr:
			if i == 0:
				m = min(a[0], b[2])
				a[0] -= m
				b[2] -= m
			elif i == 1:
				m = min(a[1], b[0])
				a[1] -= m
				b[0] -= m
			elif i == 2:
				m = min(a[2], b[1])
				a[2] -= m
				b[1] -= m
			elif i == 3:
				m = min(a[0], b[0])
				a[0] -= m
				b[0] -= m
			elif i == 4:
				m = min(a[1], b[1])
				a[1] -= m
				b[1] -= m
			elif i == 5:
				m = min(a[2], b[2])
				a[2] -= m
				b[2] -= m
		return sum(a)

	def check_permute(ind, arr):
		if ind == 5:
			return compute(arr)
		m = 10000000000
		for i in range(ind, 6):
			m = min(m, check_permute(ind + 1, arr[:ind] + arr[i:i + 1] + arr[ind:i] + arr[i + 1:6]))
		return m
	c = check_permute(0, [0, 1, 2, 3, 4, 5])
	return c

def max_wins(a, b):
	return min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(min_wins(a.copy(), b.copy()), end=' ')
	print(max_wins(a, b))
main()