Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.

At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.

They also decided that there must be given at least min_1 and at most max_1 diplomas of the first degree, at least min_2 and at most max_2 diplomas of the second degree, and at least min_3 and at most max_3 diplomas of the third degree.

After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.

Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.

It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.


-----Input-----

The first line of the input contains a single integer n (3 ≤ n ≤ 3·10^6) — the number of schoolchildren who will participate in the Olympiad.

The next line of the input contains two integers min_1 and max_1 (1 ≤ min_1 ≤ max_1 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.

The third line of the input contains two integers min_2 and max_2 (1 ≤ min_2 ≤ max_2 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. 

The next line of the input contains two integers min_3 and max_3 (1 ≤ min_3 ≤ max_3 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. 

It is guaranteed that min_1 + min_2 + min_3 ≤ n ≤ max_1 + max_2 + max_3.


-----Output-----

In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.

The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.


-----Examples-----
Input
6
1 5
2 6
3 7

Output
1 2 3 

Input
10
1 2
1 3
1 5

Output
2 3 5 

Input
6
1 3
2 2
2 2

Output
2 2 2

Difficulty: EASY

Solutions:
n = int(input())
(xa, ya) = map(int, input().split(' '))
(xo, yo) = map(int, input().split(' '))
(xe, ye) = map(int, input().split(' '))
(a, o, e) = (xa, xo, xe)
n = n - xa - xo - xe
(ya, yo, ye) = (ya - xa, yo - xo, ye - xe)
if ya > n:
	a = a + n
	n = 0
else:
	a += ya
	n = n - ya
	if yo > n:
		o = o + n
		n = 0
	else:
		o += yo
		n = n - yo
		if ye > n:
			e = e + n
			n = 0
		else:
			e += ye
print(a, o, e)


n = int(input())

def r():
	return [int(i) for i in input().split()]
deg = (r(), r(), r())
l = [i[0] for i in deg]

def remains():
	return n - sum(l)

def better(i):
	nonlocal l
	rem = remains()
	l[i] = min(l[i] + rem, deg[i][1])
for i in range(len(l)):
	better(i)
print(' '.join((str(i) for i in l)))


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
n = ii()
(mi1, ma1) = mi()
(mi2, ma2) = mi()
(mi3, ma3) = mi()
d = [mi1, mi2, mi3]
t = n - mi1 - mi2 - mi3
while t > 0 and d[0] < ma1:
	d[0] += 1
	t -= 1
while t > 0 and d[1] < ma2:
	d[1] += 1
	t -= 1
while t > 0 and d[2] < ma3:
	d[2] += 1
	t -= 1
print(wr(d))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	n = I()
	aa = [LI() for _ in range(3)]
	r = []
	nk = n
	for i in range(3):
		k = nk
		ai = aa[i]
		for j in range(i + 1, 3):
			k -= aa[j][0]
		t = min(ai[1], k)
		r.append(t)
		nk -= t
	return JA(r, ' ')
print(main())


n = int(input())
(min1, max1) = list(map(int, input().split(' ')))
(min2, max2) = list(map(int, input().split(' ')))
(min3, max3) = list(map(int, input().split(' ')))
n1 = min(n - (min2 + min3), max1)
n2 = min(n - (n1 + min3), max2)
n3 = min(n - (n1 + n2), max3)
print('{} {} {}'.format(n1, n2, n3))


n = int(input())
(m1, ma1) = map(int, input().split())
(m2, ma2) = map(int, input().split())
(m3, ma3) = map(int, input().split())
a1 = min(ma1, n - m2 - m3)
a2 = min(ma2, n - a1 - m3)
a3 = n - a1 - a2
print(a1, a2, a3)


n = int(input())
(a, c) = map(int, input().split())
(d, e) = map(int, input().split())
(f, g) = map(int, input().split())
x = min(n - d - f, c)
x = max(x, a)
y = min(n - x - f, e)
y = max(y, d)
z = n - x - y
print(x, y, z)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
n1 = a[0]
n2 = b[0]
n3 = c[0]
n -= a[0] + b[0] + c[0]
n1 += min(a[1] - a[0], n)
n -= min(a[1] - a[0], n)
n2 += min(b[1] - b[0], n)
n -= min(b[1] - b[0], n)
n3 += n
print(n1, n2, n3)


n = int(input())
(min1, max1) = input().split()
(min2, max2) = input().split()
(min3, max3) = input().split()
min1 = int(min1)
min2 = int(min2)
min3 = int(min3)
max1 = int(max1)
max2 = int(max2)
max3 = int(max3)
res1 = max1
res2 = max2
res3 = max3
if res3 > min3 and res1 + res2 + res3 > n:
	if min3 + res2 + res1 >= n:
		res3 = min3
	else:
		res3 = n - res2 - res1
if res2 > min2 and res1 + res2 + res3 > n:
	if min2 + res3 + res1 >= n:
		res2 = min2
	else:
		res2 = n - res1 - res3
if res1 > min1 and res1 + res2 + res3 > n:
	if min1 + res3 + res2 >= n:
		res1 = min1
	else:
		res1 = n - res2 - res3
print(res1, res2, res3)


n = int(input())
rg = []
n1 = [int(x) for x in input().split()]
n2 = [int(x) for x in input().split()]
n3 = [int(x) for x in input().split()]
res = [0, 0, 0]
for i in range(n1[0], n1[1] + 1):
	if n - i <= n2[1] + n3[1]:
		if n - i >= n2[0] + n3[0]:
			res[0] = i
for i in range(n2[0], n2[1] + 1):
	t = n - i - res[0]
	if t >= n3[0]:
		if t <= n3[1]:
			res[1] = i
res[2] = n - sum(res[:2])
print(' '.join(list(map(str, res))))


def main():
	n = int(input())
	((min1, max1), (min2, max2), (min3, max3)) = list((tuple(map(int, input().split())) for _ in range(3)))
	max1 = min(max1, n - min2 - min3)
	max2 = min(max2, n - max1 - min3)
	print(max1, max2, n - max1 - max2)

def __starting_point():
	main()
__starting_point()


import itertools
import math
from collections import defaultdict

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

def solve():
	n = int(input())
	a = [input_ints() for i in range(3)]
	ans = [x[0] for x in a]
	for i in range(3):
		d = min(n - sum(ans), a[i][1] - ans[i])
		ans[i] += d
	print(ans[0], ans[1], ans[2])
solve()


n = int(input())
(mi1, mx1) = [int(i) for i in input().split()]
(mi2, mx2) = [int(i) for i in input().split()]
(mi3, mx3) = [int(i) for i in input().split()]
(a, b, c) = (n - mi2 - mi3, mi2, mi3)
if a > mx1:
	b += a - mx1
	a = mx1
	if b > mx2:
		c += b - mx2
		b = mx2
print('%s %s %s' % (a, b, c))


n = int(input())
(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
(x3, y3) = map(int, input().split())
(a, b, c) = (x1, x2, x3)
s = a + b + c
x = n - s
if x:
	if y1 - x1 < x:
		a += y1 - x1
		x -= y1 - x1
	else:
		a += x
		x = 0
	if y2 - x2 < x:
		b += y2 - x2
		x -= y2 - x2
	else:
		b += x
		x = 0
	if y3 - x3 < x:
		c += y3 - x3
		x -= y3 - x3
	else:
		c += x
		x = 0
print(a, b, c)


n = int(input())
(min1, max1) = [int(c) for c in input().split()]
(min2, max2) = [int(c) for c in input().split()]
(min3, max3) = [int(c) for c in input().split()]
(a, b, c) = (0, 0, 0)
if n - min3 <= max1 + max2:
	c = min3
else:
	c = n - max1 - max2
if n - c - min2 <= max1:
	b = min2
	a = n - c - b
else:
	a = max1
	b = n - c - a
print(str(a) + ' ' + str(b) + ' ' + str(c))


n = int(input())
(a, b) = (int(x) for x in input().split())
(c, d) = (int(x) for x in input().split())
(e, f) = (int(x) for x in input().split())
x = a
y = c
z = e
n -= x + y + z
q = min(n, b - a)
x += q
n -= q
q = min(n, d - c)
y += q
n -= q
q = min(n, f - e)
z += q
n -= q
print(x, y, z)


N = int(input())
mins = []
maxs = []
for i in range(3):
	(mi, ma) = map(int, input().split())
	mins.append(mi)
	maxs.append(ma)
anss = list(mins)
rem = N - sum(anss)
for i in range(3):
	if rem >= 0:
		add = min(rem, maxs[i] - mins[i])
		rem -= add
		anss[i] += add
print(' '.join(map(str, anss)))


I = lambda : map(int, input().split())
n = next(I())
(a, b) = I()
(c, d) = I()
(f, e) = I()
x = min(b, n - c - f)
y = min(d, n - x - f)
print(x, y, n - x - y)


import itertools as ittls
from collections import Counter
import re
import math

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
N = int(input())
(x1, y1) = inputarray()
(x2, y2) = inputarray()
(x3, y3) = inputarray()

def split(N, x1, y1, x2, y2):
	if N - y1 >= x2:
		return (y1, N - y1)
	else:
		return (N - x2, x2)
(a1, x) = split(N, x1, y1, x2 + x3, y2 + y3)
(a2, a3) = split(x, x2, y2, x3, y3)
print(a1, a2, a3)


def main():
	n = int(input())
	(min1, max1) = [int(t) for t in input().split()]
	(min2, max2) = [int(t) for t in input().split()]
	(min3, max3) = [int(t) for t in input().split()]
	s1 = min(max1, n - min2 - min3)
	s2 = min(max2, n - s1 - min3)
	s3 = n - s1 - s2
	print(' '.join((str(s) for s in [s1, s2, s3])))
main()


n = int(input())
(min_1, max_1) = list(map(int, input().split()))
(min_2, max_2) = list(map(int, input().split()))
(min_3, max_3) = list(map(int, input().split()))
a_1 = min(max_1, n - min_2 - min_3)
a_2 = min(max_2, n - a_1 - min_3)
a_3 = n - a_1 - a_2
print(str(a_1) + ' ' + str(a_2) + ' ' + str(a_3))


n = int(input())
(min1, max1) = [int(x) for x in input().split()]
(min2, max2) = [int(x) for x in input().split()]
(min3, max3) = [int(x) for x in input().split()]
st = min1
nd = min2
rd = min3
left = n - (min1 + min2 + min3)
diff = 0
if left < max1 - min1:
	diff = left
else:
	diff = max1 - min1
st += diff
left -= diff
if left < max2 - min2:
	diff = left
else:
	diff = max2 - min2
nd += diff
left -= diff
if left < max3 - min3:
	diff = left
else:
	diff = max3 - min3
rd += diff
left -= diff
print(st, nd, rd)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
n = int(input())
ms = []
for _ in range(3):
	(a, b) = map(int, input().split())
	ms.append([a, b])
c = ms[2][0]
b = ms[1][0]
a = ms[0][0]
r = n - a - b - c
if r:
	a = min(a + r, ms[0][1])
	r = n - a - b - c
if r:
	b = min(b + r, ms[1][1])
	r = n - a - b - c
if r:
	c = min(c + r, ms[2][1])
print(a, b, c)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
ans1 = min1
ans2 = min2
ans3 = min3
n -= min1 + min2 + min3
max1 = max1 - min1
max2 = max2 - min2
max3 = max3 - min3
while n > 0:
	if max1 > 0:
		if max1 >= n:
			ans1 += n
			max1 -= n
			n = 0
		else:
			n = n - max1
			ans1 += max1
			max1 = 0
	elif max2 > 0:
		if max2 >= n:
			ans2 += n
			max2 -= n
			n = 0
		else:
			n = n - max2
			ans2 += max2
			max2 = 0
	elif max3 > 0:
		if max3 >= n:
			ans3 += n
			max3 -= n
			n = 0
		else:
			n = n - max3
			ans3 += max3
			max3 = 0
print(ans1, ans2, ans3)


n = int(input())
(min1, max1) = map(int, input().split(' '))
(min2, max2) = map(int, input().split(' '))
(min3, max3) = map(int, input().split(' '))
(n1, n2, n3) = (min1, min2, min3)
if n1 + n2 + n3 < n:
	n1 = max1
	if n1 + n2 + n3 > n:
		n1 -= n1 + n2 + n3 - n
	else:
		n2 = max2
		if n1 + n2 + n3 > n:
			n2 -= n1 + n2 + n3 - n
		else:
			n3 = max3
			if n1 + n2 + n3 > n:
				n3 -= n1 + n2 + n3 - n
print(n1, n2, n3)


n = int(input())
r = n * 1
(a1, b1) = map(int, input().split())
(a2, b2) = map(int, input().split())
(a3, b3) = map(int, input().split())
(p1, p2, p3) = (a1, a2, a3)
n -= a1 + a2 + a3
k = b1 - a1
if k >= n:
	p1 = a1 + n
else:
	p1 = b1
	n -= k
	k = b2 - a2
	if k >= n:
		p2 = a2 + n
	else:
		p2 = b2
		p3 = r - p1 - p2
print(p1, p2, p3)


n = int(input())
(mi1, ma1) = map(int, input().split())
(mi2, ma2) = map(int, input().split())
(mi3, ma3) = map(int, input().split())
ma = [ma1, ma2, ma3]
res = [mi1, mi2, mi3]
n -= sum(res)
for i in range(3):
	if ma[i] - res[i] > n:
		res[i] += n
		break
	n -= ma[i] - res[i]
	res[i] = ma[i]
print(*res)


n = int(input())
l1 = input().split(' ')
l2 = input().split(' ')
l3 = input().split(' ')
(mn1, mx1) = (int(l1[0]), int(l1[1]))
(mn2, mx2) = (int(l2[0]), int(l2[1]))
(mn3, mx3) = (int(l3[0]), int(l3[1]))
if n - mn2 - mn3 > mx1:
	d1 = mx1
else:
	d1 = n - mn2 - mn3
n -= d1
if n - mn3 > mx2:
	d2 = mx2
else:
	d2 = n - mn3
n -= d2
d3 = n
print(d1, d2, d3, sep=' ')


def split(s):
	for i in range(len(s)):
		if s[i] == ' ':
			return i
n = int(input())
if 3 <= n <= 3 * 10 ** 6:
	s1 = input()
	i = split(s1)
	min1 = int(s1[0:i])
	max1 = int(s1[i + 1:])
	s2 = input()
	i = split(s2)
	min2 = int(s2[0:i])
	max2 = int(s2[i + 1:])
	s3 = input()
	i = split(s3)
	min3 = int(s3[0:i])
	max3 = int(s3[i + 1:])
if 1 <= min1 <= max1 <= 10 ** 6 and 1 <= min2 <= max2 <= 10 ** 6 and (1 <= min3 <= max3 <= 10 ** 6):
	x = max1 + max2 + max3
	a = max1
	b = max2
	c = max3
	if x > n and c != min3:
		x = x - max3 + min3
		c = min3
	if x > n and b != min2 and (c == min3):
		x = x - max2 + min2
		b = min2
	if x > n and a != min1 and (b == min2) and (c == min3):
		x = x - max1 + min1
		a = min1
	while x < n and min1 <= a < max1:
		x = x + 1
		a = a + 1
	while x < n and min2 <= b < max2:
		x = x + 1
		b = b + 1
	while x < n and min3 <= c < max3:
		x = x + 1
		c = c + 1
	print(a, b, c)


n = int(input())
(mn1, mx1) = [int(s) for s in input().split()]
(mn2, mx2) = [int(s) for s in input().split()]
(mn3, mx3) = [int(s) for s in input().split()]
if n - mx1 < mn2 + mn3:
	ans1 = n - (mn3 + mn2)
	n = mn3 + mn2
else:
	n -= mx1
	ans1 = mx1
if n - mx2 < mn3:
	ans2 = n - mn3
	n = mn3
else:
	n -= mx2
	ans2 = mx2
print(ans1, ans2, n)


n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
x = min(a[0][1], n - a[1][0] - a[2][0])
y = min(a[1][1], n - x - a[2][0])
z = n - x - y
print(x, y, z)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
a = min1
b = min2
c = min3
n = n - min1 - min2 - min3
if n + a <= max1:
	a = a + n
else:
	n = n - max1 + a
	a = max1
	if n + b <= max2:
		b = b + n
	else:
		n = n - max2 + b
		b = max2
		c = c + n
print(str(a) + ' ' + str(b) + ' ' + str(c))


(n,) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(3)]
fx = min(a[0][1], n - a[1][0] - a[2][0])
fy = min(a[1][1], n - fx - a[2][0])
fz = n - fx - fy
print(fx, fy, fz)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
x = min(max1, n - min2 - min3)
y = min(max2, n - x - min3)
print(x, y, n - x - y)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
(a, b, c) = (min1, min2, min3)
n = n - min1 - min2 - min3
ra = min(n, max1 - a)
a += ra
n -= ra
rb = min(n, max2 - b)
b += rb
n -= rb
rc = min(n, max3 - c)
c += rc
n -= rc
print(a, b, c)


a = int(input())
(*b,) = map(int, input().split() + input().split() + input().split())
if b[0] + b[2] + b[4] < a:
	if b[1] + b[2] + b[4] < a:
		if b[1] + b[3] + b[4] < a:
			print(b[1], b[3], a - b[1] - b[3])
		else:
			print(b[1], a - b[1] - b[4], b[4])
	else:
		print(a - b[2] - b[4], b[2], b[4])
else:
	print(b[0], b[2], b[4])


n = int(input())
(min1, max1) = list(map(int, input().split()))
(min2, max2) = list(map(int, input().split()))
(min3, max3) = list(map(int, input().split()))

def good(a, b, c, n):
	return a + b + c == n

def find_val(n, min1, max1, min2, max2, min3, max3):
	minn = min1 + min2 + min3
	maxx = max1 + max2 + max3
	if minn == n:
		return (min1, min2, min3)
	elif maxx == n:
		return (max1, max2, max3)
	else:
		(v1, v2, v3) = (max1 - min1, max2 - min2, max3 - min3)
		s = min1 + min2 + min3
		d = n - s
		if d <= v1:
			min1 += d
		elif d <= v1 + v2:
			min1 += v1
			min2 += d - v1
		else:
			min1 += v1
			min2 += v2
			min3 += d - v1 - v2
		return (min1, min2, min3)
(a, b, c) = find_val(n, min1, max1, min2, max2, min3, max3)
print(str(a) + ' ' + str(b) + ' ' + str(c))


import sys
n = int(input())
(min1, max1) = map(int, sys.stdin.readline().split())
(min2, max2) = map(int, sys.stdin.readline().split())
(min3, max3) = map(int, sys.stdin.readline().split())
first_max = n - min2 - min3
first = 0
second = 0
third = 0
if first_max <= max1:
	first = first_max
else:
	first = max1
n = n - first
second_max = n - min3
if second_max <= max2:
	second = second_max
else:
	second = max2
third = n - second
print(first, second, third)


from sys import stdin
from sys import exit
live = True
if not live:
	stdin = open('data.in', 'r')
n = int(stdin.readline().strip())
(ans1, max1) = list(map(int, stdin.readline().strip().split()))
(ans2, max2) = list(map(int, stdin.readline().strip().split()))
(ans3, max3) = list(map(int, stdin.readline().strip().split()))
total = ans1 + ans2 + ans3
if total == n:
	print(ans1, ans2, ans3)
	exit(0)
n -= total
total = min(n, max1 - ans1)
ans1 += total
if total == n:
	print(ans1, ans2, ans3)
	exit(0)
n -= total
total = min(n, max2 - ans2)
ans2 += total
if total == n:
	print(ans1, ans2, ans3)
	exit(0)
n -= total
total = min(n, max3 - ans3)
ans3 += total
print(ans1, ans2, ans3)
if not live:
	stdin.close()


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


import unittest
import sys
import re

class Diploma:

	def __init__(self, args):
		self.list = args
		self.n = args[0]
		self.ranges = args[1:]
		self.range = [0, 0, 0]

	def set_range(self):
		reminder = self.n
		min0 = reminder - self.ranges[2][0] - self.ranges[1][0]
		self.range[0] = min(min0, self.ranges[0][1])
		reminder -= self.range[0]
		self.range[1] = min(reminder - self.ranges[2][0], self.ranges[1][1])
		reminder -= self.range[1]
		self.range[2] = min(reminder, self.ranges[2][1])

	def calculate(self):
		self.set_range()
		result = self.range
		return str(' '.join([str(n) for n in result]))

def get_inputs(test_inputs=None):
	it = iter(test_inputs.split('\n')) if test_inputs else None

	def uinput():
		if it:
			return next(it)
		else:
			return input()
	num = int(uinput())
	nums = [[int(s) for s in uinput().split()] for i in range(3)]
	inputs = []
	inputs.append(num)
	inputs += nums
	return inputs

def calculate(test_inputs=None):
	return Diploma(get_inputs(test_inputs)).calculate()

class unitTests(unittest.TestCase):

	def test_sample_tests(self):
		test = '6\n1 5\n2 6\n3 7'
		self.assertEqual(calculate(test), '1 2 3')
		self.assertEqual(get_inputs(test), [6, [1, 5], [2, 6], [3, 7]])
		test = '10\n1 2\n1 3\n1 5'
		self.assertEqual(calculate(test), '2 3 5')
		test = '6\n1 3\n2 2\n2 2'
		self.assertEqual(calculate(test), '2 2 2')

	def test_Diploma_class__basic_functions(self):
		d = Diploma([6, [1, 5], [2, 6], [3, 7]])
		self.assertEqual(d.list[0], 6)
		self.assertEqual(d.n, 6)
		self.assertEqual(d.ranges[0], [1, 5])
		d.set_range()
		self.assertEqual(d.range, [1, 2, 3])
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
print(calculate())


__author__ = 'darinflar'
n = int(input())
(x1, x2) = map(int, input().split())
(y1, y2) = map(int, input().split())
(z1, z2) = map(int, input().split())
perv = min(n - z1 - y1, x2)
vtor = min(n - perv - z1, y2)
tret = n - perv - vtor
print(perv, vtor, tret)


x = int(input())
f = [0, 0]
s = [0, 0]
t = [0, 0]
str = input().split(' ')
f[0] = int(str[0])
f[1] = int(str[1])
str = input().split(' ')
s[0] = int(str[0])
s[1] = int(str[1])
str = input().split(' ')
t[0] = int(str[0])
t[1] = int(str[1])
maxf = x - s[0] - t[0]
if maxf > f[1]:
	maxf = f[1]
maxs = x - maxf - t[0]
if maxs > s[1]:
	maxs = s[1]
maxt = x - maxs - maxf
print('{0} {1} {2}'.format(maxf, maxs, maxt))


n = int(input())
temp = [int(n) for n in input().split()]
min1 = temp[0]
max1 = temp[1]
temp = [int(n) for n in input().split()]
min2 = temp[0]
max2 = temp[1]
temp = [int(n) for n in input().split()]
min3 = temp[0]
max3 = temp[1]
diplomas = [0, 0, 0]
diplomas[0] = min1
diplomas[1] = min2
diplomas[2] = min3
diplomas[0] += min(max1 - min1, n - sum(diplomas))
diplomas[1] += min(max2 - min2, n - sum(diplomas))
diplomas[2] += min(max3 - min3, n - sum(diplomas))
print(diplomas[0], diplomas[1], diplomas[2])


n = int(input())
(a, b) = map(int, input().split(' '))
(c, d) = map(int, input().split(' '))
(e, f) = map(int, input().split(' '))
while a + c + e < n and a < b:
	a += 1
while a + c + e < n and c < d:
	c += 1
m = n - a - c
print(a, c, m)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
a = max1
b = max2
c = min3
s = a + b + c
if s < n:
	c += n - s
elif s > n:
	b -= min(s - n, max2 - min2)
	a -= max(0, s - n - max2 + min2)
print(a, b, c)


__author__ = 'Bian'
n = int(input())
(a1, a2) = [int(x) for x in input().split()]
(b1, b2) = [int(x) for x in input().split()]
(c1, c2) = [int(x) for x in input().split()]
a = min(a2, n - b1 - c1)
b = min(b2, n - a - c1)
c = n - a - b
print(a, b, c)


n = int(input())
(mn1, mx1) = map(int, input().split())
(mn2, mx2) = map(int, input().split())
(mn3, mx3) = map(int, input().split())
a = min(mx1, n - mn2 - mn3)
b = min(mx2, n - a - mn3)
c = n - a - b
print(a, b, c)


n = int(input())
(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
(e, f) = map(int, input().split())
co = 0
n -= a + c + e
for i in range(n):
	if a < b:
		a += 1
	elif c < d:
		c += 1
	elif e < f:
		e += 1
print(a, c, e)


n = int(input())
(a1, a2) = map(int, input().split())
(b1, b2) = map(int, input().split())
(c1, c2) = map(int, input().split())
a = a1
b = b1
c = c1
s = a + b + c
if a2 - a1 < n - s:
	a = a2
	s += a2 - a1
	if b2 - b1 < n - s:
		b = b2
		s += b2 - b1
		if c2 - c1 < n - s:
			c = c2
		else:
			c += n - s
	else:
		b += n - s
else:
	a += n - s
print(a, b, c)


n = int(input())
(l1, r1) = map(int, input().split())
(l2, r2) = map(int, input().split())
(l3, r3) = map(int, input().split())
(k1, k2, k3) = (l1, l2, l3)
n -= l1 + l2 + l3
for i in range(l1 + 1, r1 + 1):
	if n > 0:
		n -= 1
		k1 += 1
	else:
		break
for i in range(l2 + 1, r2 + 1):
	if n > 0:
		n -= 1
		k2 += 1
	else:
		break
for i in range(l3 + 1, r3 + 1):
	if n > 0:
		n -= 1
		k3 += 1
	else:
		break
print(k1, k2, k3)


n = int(input())
(lows, values) = ([], [])
sum = 0
for i in range(3):
	(low, high) = map(int, input().split())
	lows.append(low)
	values.append(high)
	sum += high
pos = 3
while True:
	pos -= 1
	excess = min(sum - n, values[pos] - lows[pos])
	values[pos] -= excess
	sum -= excess
	if sum == n:
		break
print(' '.join(map(str, values)))


n = int(input())
(min1, max1) = [int(k) for k in input().split()]
(min2, max2) = [int(k) for k in input().split()]
(min3, max3) = [int(k) for k in input().split()]
p1 = max1
p2 = max2
p3 = max3
while p1 + p2 + p3 > n:
	if p3 > min3:
		p3 -= 1
	elif p2 > min2:
		p2 -= 1
	elif p1 > min1:
		p1 -= 1
print(p1, p2, p3)


n = int(input())
(m1, M1) = map(int, input().split())
(m2, M2) = map(int, input().split())
(m3, M3) = map(int, input().split())
(f, s, t) = (m1, m2, m3)
n -= m1 + m2 + m3
if n > 0:
	x = min(M1 - m1, n)
	n -= x
	f += x
if n > 0:
	x = min(M2 - m2, n)
	n -= x
	s += x
if n > 0:
	x = min(M3 - m3, n)
	n -= x
	t += x
print(f, s, t, end=' ')


n = int(input())
(minis, maxis) = ([], [])
for i in range(3):
	s = list(map(int, input().split()))
	minis.append(s[0])
	maxis.append(s[1])
left = n
diploms = [0 for i in range(3)]
for i in range(3):
	diploms[i] = minis[i]
	left -= minis[i]
for i in range(3):
	d = min(left, maxis[i] - minis[i])
	diploms[i] += d
	left -= d
print(' '.join(map(str, diploms)))


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
d1 = min(n - min2 - min3, max1)
d2 = min(n - d1 - min3, max2)
d3 = n - d1 - d2
print(d1, d2, d3)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
sum = min1 + min2 + min3
diplomas = [min1, min2, min3]
(max1_t, max2_t, max3_t) = (max1, max2, max3)
while diplomas[0] < max1 and sum < n:
	max1_t -= 1
	diplomas[0] += 1
	sum += 1
while diplomas[1] < max2 and sum < n:
	max2_t -= 1
	diplomas[1] += 1
	sum += 1
while diplomas[2] < max3 and sum < n:
	max3_t -= 1
	diplomas[2] += 1
	sum += 1
print(' '.join([str(i) for i in diplomas]))


n = int(input())
[a, b] = [int(x) for x in input().split()]
[c, d] = [int(x) for x in input().split()]
[e, f] = [int(x) for x in input().split()]

def func(a, b, c, d, e, f, n):
	sum = a + c + e
	a = [a, c, e]
	b = [b, d, f]
	if n == sum:
		for j in a:
			print(j, end=' ')
		return
	if n == b[0] + b[1] + b[2]:
		for j in b:
			print(j, end=' ')
		return
	for i in range(0, 3):
		if n - sum <= b[i] - a[i]:
			a[i] += n - sum
			sum += n - sum
			for j in a:
				print(j, end=' ')
			return
		else:
			sum += b[i] - a[i]
			a[i] = b[i]
	for j in a:
		print(j, end=' ')
	return
func(a, b, c, d, e, f, n)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = iinput()
(min1, max1) = rinput()
(min2, max2) = rinput()
(min3, max3) = rinput()
if min1 + min2 + min3 == n:
	print(min1, min2, min3)
elif max1 + max2 + max3 == n:
	print(max1, max2, max3)
else:
	while min1 + min2 + min3 != n:
		while min1 < max1 and min1 + min2 + min3 != n:
			min1 += 1
		while min2 < max2 and min1 + min2 + min3 != n:
			min2 += 1
		while min3 < max3 and min1 + min2 + min3 != n:
			min3 += 1
	print(min1, min2, min3)


def main():
	n = int(input())
	x = [tuple((int(strnum) for strnum in input().split())) for ct in range(3)]
	u = min(x[0][1], n - x[1][0] - x[2][0])
	v = min(x[1][1], n - u - x[2][0])
	print(u, v, n - u - v)
main()


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 prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	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())
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	ans = a + c + e
	oof = [a, c, e]
	if ans < n:
		mx = min(n - ans, b - a)
		ans += mx
		oof[0] += mx
	if ans < n:
		mx = min(n - ans, d - c)
		ans += mx
		oof[1] += mx
	if ans < n:
		mx = min(n - ans, f - e)
		ans += mx
		oof[2] += mx
	print(*oof)


n = int(input())
m1 = list(map(int, input().split()))
m2 = list(map(int, input().split()))
m3 = list(map(int, input().split()))
a1 = m1[0]
a2 = m2[0]
a3 = m3[0]
if a1 + a2 + a3 == n:
	print(a1, a2, a3)
elif m1[1] + a2 + a3 >= n:
	a1 = n - a2 - a3
	print(a1, a2, a3)
else:
	a1 = m1[1]
	if a1 + m2[1] + a3 >= n:
		a2 = n - a1 - a3
		print(a1, a2, a3)
	else:
		a2 = m2[1]
		a3 = n - a1 - a2
		print(a1, a2, a3)


n = int(input())
d1 = input().split()
(min1, max1) = (int(d1[0]), int(d1[1]))
d1 = input().split()
(min2, max2) = (int(d1[0]), int(d1[1]))
d1 = input().split()
(min3, max3) = (int(d1[0]), int(d1[1]))
di1 = min1
di2 = min2
di3 = min3
di1 += min(max1 - min1, n - (di1 + di2 + di3))
di2 += min(max2 - min2, n - (di1 + di2 + di3))
di3 += min(max3 - min3, n - (di1 + di2 + di3))
print(di1, di2, di3)


n = int(input())
(a1, a2) = map(int, input().split())
(b1, b2) = map(int, input().split())
(c1, c2) = map(int, input().split())
a = min(a2, n - b1 - c1)
b = min(b2, n - a - c1)
c = n - a - b
print(a, b, c)


n = int(input())
(m_1, mx_1) = map(int, input().split())
(m_2, mx_2) = map(int, input().split())
(m_3, mx_3) = map(int, input().split())
ans = [m_1, m_2, m_3]
s = sum(ans)
if s == n:
	print(*ans)
else:
	ans[0] += min(n - s, mx_1 - m_1)
	if ans[0] == mx_1:
		s += mx_1 - m_1
		ans[1] += min(n - s, mx_2 - m_2)
		if ans[1] == mx_2:
			s += mx_2 - m_2
			ans[2] += min(n - s, mx_3 - m_3)
	print(*ans)


r = lambda : map(int, input().split())
n = int(input())
(min1, max1) = r()
(min2, max2) = r()
(min3, max3) = r()
r3 = max(min3, n - max2 - max1)
r2 = max(min2, n - r3 - max1)
r1 = n - r3 - r2
print(r1, r2, r3)


n = int(input())
(mn1, mx1) = map(int, input().split())
(mn2, mx2) = map(int, input().split())
(mn3, mx3) = map(int, input().split())
fd = n - mn2 - mn3
if fd > mx1:
	fd = mx1
n -= fd
sd = n - mn3
if sd > mx2:
	sd = mx2
td = n - sd
print(fd, sd, td)


import math
import sys
n = int(input())
inp = list(map(int, input().split()))
m1 = inp[0]
M1 = inp[1]
inp = list(map(int, input().split()))
m2 = inp[0]
M2 = inp[1]
inp = list(map(int, input().split()))
m3 = inp[0]
M3 = inp[1]
ans = []
rest = n - m2 - m3
ans = [rest, m2, m3]
rest = n - M1 - m3
if rest >= m2 and rest <= M2:
	ans = [M1, rest, m3]
rest = n - M1 - M2
if rest >= m3 and rest <= M3:
	ans = [M1, M2, rest]
print(str(ans[0]) + ' ' + str(ans[1]) + ' ' + str(ans[2]))


n = int(input())
(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
(e, f) = map(int, input().split())
b += 1
while a < b - 1:
	m = (a + b) // 2
	if m + c + e <= n:
		a = m
	else:
		b = m
d += 1
while c < d - 1:
	m = (c + d) // 2
	if n - a - m >= e:
		c = m
	else:
		d = m
print(a, c, n - a - c)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
first_diplomas = n - min2 - min3
if first_diplomas > max1:
	first_diplomas = max1
remaining = n - first_diplomas
second_diplomas = remaining - min3
if second_diplomas > max2:
	second_diplomas = max2
third_diplomas = remaining - second_diplomas
print(first_diplomas, second_diplomas, third_diplomas)


n = int(input())
dip = []
rewarded = [0] * 3
for _ in range(3):
	a = list(map(int, input().split()))
	a[1] = a[1] - a[0]
	dip.append(a)
for i in range(3):
	n -= dip[i][0]
	rewarded[i] += dip[i][0]
while n > 0:
	if dip[0][1] > 0:
		if n >= dip[0][1]:
			rewarded[0] += dip[0][1]
			n -= dip[0][1]
			dip[0][1] = 0
		else:
			rewarded[0] += n
			n = 0
			dip[0][1] = 0
	elif dip[1][1] > 0:
		if n >= dip[1][1]:
			rewarded[1] += dip[1][1]
			n -= dip[1][1]
			dip[1][1] = 0
		else:
			rewarded[1] += n
			n = 0
			dip[1][1] = 0
	else:
		rewarded[2] += n
		n = 0
for i in rewarded:
	print(str(i), end=' ')


n = int(input())
(mn1, mx1) = map(int, input().split())
(mn2, mx2) = map(int, input().split())
(mn3, mx3) = map(int, input().split())
(x1, x2, x3) = (mn1, mn2, mn3)
r = n - (x1 + x2 + x3)
x1 += min(r, mx1 - mn1)
r -= min(r, mx1 - mn1)
x2 += min(r, mx2 - mn2)
r -= min(r, mx2 - mn2)
x3 += min(r, mx3 - mn3)
print(x1, x2, x3)


__author__ = 'myduomilia'
n = int(input())
a = [0 for i in range(3)]
b = [0 for i in range(3)]
for i in range(3):
	(a[i], b[i]) = list(map(int, input().split()))
	n -= a[i]
	b[i] -= a[i]
for i in range(3):
	if n > 0:
		if b[i] > n:
			a[i] += n
			n = 0
		else:
			a[i] += b[i]
			n -= b[i]
			b[i] = 0
for i in range(3):
	print(a[i], end=' ')


n = int(input())
R = lambda : map(int, input().split())
(Min1, Max1) = R()
(Min2, Max2) = R()
(Min3, Max3) = R()
a = Max1
b = Max2
c = n - a - b
if c < Min3:
	c = Min3
	b = n - a - c
if b < Min2:
	b = Min2
	a = n - b - c
print(a, b, c)


def sinput():
	s = input().split()
	return (int(s[0]), int(s[1]))
n = int(input())
(mina, maxa) = sinput()
(minb, maxb) = sinput()
(minc, maxc) = sinput()
la = max(mina, n - maxb - maxc)
ra = maxa + 1
while ra - la > 1:
	m = int((la + ra) / 2)
	if n - m in range(minb + minc, maxb + maxc + 1):
		la = m
	else:
		ra = m
n -= la
lb = max(minb, n - maxc)
rb = maxb + 1
while rb - lb > 1:
	m = int((lb + rb) / 2)
	if n - m in range(minc, maxc + 1):
		lb = m
	else:
		rb = m
print(la, lb, n - lb)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
a1 = min(max1, n - min2 - min3)
n -= a1
a2 = min(max2, n - min3)
a3 = n - a2
print(a1, a2, a3)


n = int(input())
(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
(i, j) = map(int, input().split())
x = min(b, n - c - i)
y = min(d, n - x - i)
print(x, y, n - x - y)


n = int(input())
a = []
for i in range(3):
	a.append(list(map(int, input().split())))
k = a[0][0] + a[1][0] + a[2][0]
m = a[0][1] + a[1][1] + a[2][1]
x = n - k
for i in range(3):
	y = a[i][1] - a[i][0]
	if x < y:
		y = max(0, x)
	print(a[i][0] + y, end=' ')
	x -= y


n = int(input())
m = [[None] * 2 for i in range(3)]
for i in range(3):
	(m[i][0], m[i][1]) = map(int, input().split())
a = m[0][0]
b = m[1][0]
c = m[2][0]
n -= a + b + c
x = min(n, m[0][1] - m[0][0])
a += x
n -= x
if n < 0:
	n = 0
x = min(n, m[1][1] - m[1][0])
b += x
n -= x
if n < 0:
	n = 0
x = min(n, m[2][1] - m[2][0])
c += x
n -= x
print(a, b, c)


t = int(input())
(min1, max1) = [int(x) for x in input().split()]
(min2, max2) = [int(x) for x in input().split()]
(min3, max3) = [int(x) for x in input().split()]
v1 = max1 - min1
v2 = max2 - min2
v3 = max3 - min3
r = t - (min1 + min2 + min3)
if r <= v1:
	print(min1 + r, min2, min3)
elif r > v1 and r <= v1 + v2:
	print(min1 + v1, min2 + (r - v1), min3)
else:
	print(min1 + v1, min2 + v2, min3 + (r - v1 - v2))


n = int(input())
res = [0, 0, 0]
maxi = [0, 0, 0]
for i in range(3):
	(a, b) = map(int, input().split())
	res[i] = a
	maxi[i] = b
	n -= a
for i in range(3):
	if n > 0:
		mi = min(n, maxi[i] - res[i])
		res[i] += mi
		n -= mi
print(*res)


n = int(input())
(min1, max1) = [int(i) for i in input().split(' ')]
(min2, max2) = [int(i) for i in input().split(' ')]
(min3, max3) = [int(i) for i in input().split(' ')]
res1 = min(max1, n - min3 - min2)
res2 = min(max2, n - min3 - res1)
res3 = n - res2 - res1
print(res1, res2, res3)


N = int(input())
(min1, max1) = tuple(map(int, input().split(' ')))
(min2, max2) = tuple(map(int, input().split(' ')))
(min3, max3) = tuple(map(int, input().split(' ')))
(ans1, ans2, ans3) = (min1, min2, min3)

def left():
	return N - (ans1 + ans2 + ans3)
ans1 += min(left(), max1 - ans1)
ans2 += min(left(), max2 - ans2)
ans3 += min(left(), max3 - ans3)
print(ans1, ans2, ans3)


A = 10 ** 15
n = int(input())
c = []
o = [0] * 3
for i in range(3):
	(a, b) = map(int, input().split())
	n = n - a
	c.append(b - a)
	o[i] = a
o[0] = o[0] + min(c[0], n)
n = n - min(c[0], n)
o[1] = o[1] + min(c[1], n)
n = n - min(c[1], n)
o[2] = o[2] + min(c[2], n)
n = n - min(c[2], n)
print(o[0], o[1], o[2])


n = int(input())
(a1, b1) = [int(x) for x in input().split()]
(a2, b2) = [int(x) for x in input().split()]
(a3, b3) = [int(x) for x in input().split()]
ans = [a1, a2, a3]
n -= a1 + a2 + a3
if n >= b1 - a1:
	ans[0] = b1
	n -= b1 - a1
	if n >= b2 - a2:
		ans[1] = b2
		n -= b2 - a2
		ans[2] = min(a3 + n, b3)
	else:
		ans[1] += n
else:
	ans[0] += n
print(' '.join([str(x) for x in ans]))


__author__ = 'Andrey'

def solve(n):
	nonlocal min_1
	nonlocal min_2
	nonlocal min_3
	nonlocal max_1
	nonlocal max_2
	nonlocal max_3
	(c_1, c_2, c_3) = (0, 0, 0)
	c_2 += min_2
	c_3 += min_3
	n -= min_2 + min_3
	firsts = min(n, max_1)
	c_1 += firsts
	n -= firsts
	if n == 0:
		return (c_1, c_2, c_3)
	else:
		seconds = min(max_2 - min_2, n)
		n -= seconds
		c_2 += seconds
		if n == 0:
			return (c_1, c_2, c_3)
		else:
			thirds = min(max_3 - min_3, n)
			n -= thirds
			c_3 += thirds
			if n == 0:
				return (c_1, c_2, c_3)
n = int(input())
(min_1, max_1) = map(int, input().split())
(min_2, max_2) = map(int, input().split())
(min_3, max_3) = map(int, input().split())
print(*solve(n))


n = int(input())
arr = [list(map(int, input().split())) for i in range(3)]
x = min(arr[0][1], n - arr[1][0] - arr[2][0])
y = min(arr[1][1], n - x - arr[2][0])
z = n - x - y
print(x, y, z)


n = int(input())
inp = input().split()
min1 = int(inp[0])
max1 = int(inp[1])
inp = input().split()
min2 = int(inp[0])
max2 = int(inp[1])
inp = input().split()
min3 = int(inp[0])
max3 = int(inp[1])
r1 = min1
r2 = min2
r3 = min3
l = n - r1 - r2 - r3
if l > 0:
	if r1 + l <= max1:
		r1 += l
	else:
		l -= max1 - r1
		r1 = max1
		if r2 + l <= max2:
			r2 += l
			l = 0
		else:
			l -= max2 - r2
			r2 = max2
		r3 += l
print(r1, r2, r3)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
(x, y, z, w) = (min1, min2, min3, min1 + min2 + min3)
while w < n:
	if x < max1:
		x += 1
	elif y < max2:
		y += 1
	elif z < max3:
		z += 1
	w += 1
print(x, y, z)


n = int(input())
(g1, M1) = map(int, input().split())
(g2, M2) = map(int, input().split())
(g3, M3) = map(int, input().split())
g1 += min(M1 - g1, n - (g1 + g2 + g3))
g2 += min(M2 - g2, n - (g1 + g2 + g3))
g3 += min(M3 - g3, n - (g1 + g2 + g3))
print(g1, g2, g3)


import sys
n = int(input())
(min1, max1) = map(int, input().split(' '))
(min2, max2) = map(int, input().split(' '))
(min3, max3) = map(int, input().split(' '))
a1 = a2 = a3 = 0
a3 = min3
a2 = min2
a1 = min1
rem = n - (a1 + a2 + a3)
if rem >= max1 - a1:
	rem -= max1 - a1
	a1 = max1
	if rem == 0:
		print(str(a1) + ' ' + str(a2) + ' ' + str(a3))
		sys.exit(0)
	elif rem >= max2 - a2:
		rem -= max2 - a2
		a2 = max2
		if rem == 0:
			print(str(a1) + ' ' + str(a2) + ' ' + str(a3))
			sys.exit(0)
		else:
			a3 += rem
			print(str(a1) + ' ' + str(a2) + ' ' + str(a3))
			sys.exit(0)
	else:
		a2 += rem
		print(str(a1) + ' ' + str(a2) + ' ' + str(a3))
		sys.exit(0)
else:
	a1 += rem
print(str(a1) + ' ' + str(a2) + ' ' + str(a3))


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
l1 = min(max1, n - min2 - min3)
l2 = min(max2, n - l1 - min3)
l3 = n - l1 - l2
print(l1, l2, l3)


n = int(input())
a = []
for i in range(3):
	(k, m) = map(int, input().split())
	a.append([k, m])
b = [0] * 3
if n - a[1][0] - a[2][0] > a[0][1]:
	b[0] = a[0][1]
	n -= b[0]
else:
	b[0] = n - a[1][0] - a[2][0]
	n -= b[0]
if n - a[2][0] > a[1][1]:
	b[1] = a[1][1]
	n -= b[1]
else:
	b[1] = n - a[2][0]
	n -= b[1]
b[2] = n
print(*b)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
k1 = min(max1, n - min2 - min3)
k2 = min(max2, n - k1 - min3)
print(k1, k2, n - k1 - k2)


n = int(input())
arr = []
for i in range(3):
	(a, b) = map(int, input().split(' '))
	arr.append((a, b))
a1 = 0
a2 = arr[1][0]
a3 = arr[2][0]
a1 = min(n - a2 - a3, arr[0][1])
a2 = min(n - a1 - a3, arr[1][1])
a3 = min(n - a1 - a2, arr[2][1])
print(a1, a2, a3)


n = int(input())
(min1, max1) = (int(x) for x in input().split())
(min2, max2) = (int(x) for x in input().split())
(min3, max3) = (int(x) for x in input().split())
a1 = max1
a2 = max2
a3 = n - a1 - a2
if a3 < min3:
	a2 -= min3 - a3
	a3 = min3
if a2 < min2:
	a1 -= min2 - a2
	a2 = min2
print(a1, a2, a3)


n = int(input())
l_lm = list()
for _ in range(3):
	l_lm.append(list(map(int, input().split())))
n += -l_lm[0][0] - l_lm[1][0] - l_lm[2][0]
l_t = list([l_lm[0][0], l_lm[1][0], l_lm[2][0]])
for i in range(3):
	l_t[i] += min(n, l_lm[i][1] - l_lm[i][0])
	n -= min(n, l_lm[i][1] - l_lm[i][0])
print(' '.join((str(x) for x in l_t)))


n = int(input())
(m1, M1) = map(int, input().split())
(m2, M2) = map(int, input().split())
(m3, M3) = map(int, input().split())
first = min(n - m2 - m3, M1)
n -= first
second = min(n - m3, M2)
n -= second
third = n
print(first, second, third)


n = int(input())
max1 = list(map(int, input().split())) + [0]
max2 = list(map(int, input().split())) + [0]
max3 = list(map(int, input().split())) + [0]
max1[2] = max1[1] - max1[0]
max2[2] = max2[1] - max2[0]
max3[2] = max3[1] - max3[0]
n = n - max1[0] - max2[0] - max3[0]
print(max1[0] + min(n, max1[2]), end=' ')
print(max2[0] + max(0, min(n - max1[2], max2[2])), end=' ')
print(max3[0] + max(0, min(n - max1[2] - max2[2], max3[2])), end=' ')


n = int(input())
(min1, max1) = [int(i) for i in input().split()]
(min2, max2) = [int(i) for i in input().split()]
(min3, max3) = [int(i) for i in input().split()]
(count1, count2, count3) = (0, 0, 0)
n -= min1 + min2 + min3
count1 = min1
count2 = min2
count3 = min3
max1 -= min1
max2 -= min2
max3 -= min3
if n > 0 and n >= max1:
	count1 += max1
	n -= max1
	if n > 0 and n >= max2:
		count2 += max2
		n -= max2
		if n > 0:
			count3 += n
	elif n > 0 and n < max2:
		count2 += n
		n = 0
elif n > 0 and n < max1:
	count1 += n
	n = 0
print(count1, count2, count3, sep=' ')


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

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

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

def LIST(n, m=None):
	return [0] * n if m is None else [[0] * m for i in range(n)]

def ELIST(n):
	return [[] for i in range(n)]

def MI(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = VI()
	return arr

def MS(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = input()
	return arr

def MIT(n=None, m=None):
	if n is None:
		(n, m) = VI()
	a = MI(n, m)
	arr = LIST(m, n)
	for (i, l) in enumerate(a):
		for (j, x) in enumerate(l):
			arr[j][i] = x
	return arr

def run(n, x, l, r):
	s = 0
	curr = 1
	for i in range(n):
		skip = (l[i] - curr) // x
		s += r[i] - curr - skip * x + 1
		curr = r[i] + 1
	print(s)

def main(info=0):
	n = I()
	(an, ax) = VI()
	(bn, bx) = VI()
	(cn, cx) = VI()
	m = [an, bn, cn]
	if sum(m) < n and ax > an:
		m[0] += min(ax - an, n - sum(m))
	if sum(m) < n and bx > bn:
		m[1] += min(bx - bn, n - sum(m))
	if sum(m) < n and cx > cn:
		m[2] += min(cx - cn, n - sum(m))
	print(m[0], m[1], m[2])

def __starting_point():
	main()
__starting_point()


n = int(input())
(min1, max1) = map(int, input().split(' ')[0:2])
(min2, max2) = map(int, input().split(' ')[0:2])
(min3, max3) = map(int, input().split(' ')[0:2])
n1 = min1
n -= min1
n2 = min2
n -= min2
n3 = min3
n -= min3
n1 += min(max1 - min1, n)
n -= min(max1 - min1, n)
n2 += min(max2 - min2, n)
n -= min(max2 - min2, n)
n3 += min(max3 - min3, n)
n -= min(max3 - min3, n)
print(n1, n2, n3)


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


import sys
(n, x_min, x_max, y_min, y_max, z_min, z_max) = [int(i) for i in sys.stdin.read().split()]
x = min(x_max, n - (z_min + y_min))
y = min(y_max, n - (z_min + x))
z = n - (x + y)
print(x, y, z)


int_total_diplomas = int(input())
degree_1 = list(map(int, list(input().split())))
degree_2 = list(map(int, list(input().split())))
degree_3 = list(map(int, list(input().split())))
min_degree_1 = degree_1[0]
max_degree_1 = degree_1[1]
min_degree_2 = degree_2[0]
max_degree_2 = degree_2[1]
min_degree_3 = degree_3[0]
max_degree_3 = degree_3[1]
degree_1_total = min_degree_1
degree_2_total = min_degree_2
degree_3_total = min_degree_3

def calculate_diplomas(int_total_diplomas, degree_1_total, degree_2_total, degree_3_total, max_degree_1, max_degree_2):
	if int_total_diplomas <= degree_2_total + degree_3_total + max_degree_1:
		degree_1_total = int_total_diplomas - degree_2_total - degree_3_total
		print(degree_1_total, degree_2_total, degree_3_total)
		return
	else:
		degree_1_total = max_degree_1
	if int_total_diplomas <= degree_1_total + degree_3_total + max_degree_2:
		degree_2_total = int_total_diplomas - degree_1_total - degree_3_total
		print(degree_1_total, degree_2_total, degree_3_total)
		return
	else:
		degree_2_total = max_degree_2
	degree_3_total = int_total_diplomas - degree_2_total - degree_1_total
	print(degree_1_total, degree_2_total, degree_3_total)
	return
calculate_diplomas(int_total_diplomas, degree_1_total, degree_2_total, degree_3_total, max_degree_1, max_degree_2)


ttl = int(input())
mx1 = [int(i) for i in list(input().split(' '))]
mx2 = [int(i) for i in list(input().split(' '))]
mx3 = [int(i) for i in list(input().split(' '))]
min1 = mx1[0]
min2 = mx2[0]
min3 = mx3[0]
max1 = mx1[1] - min1
max2 = mx2[1] - min2
max3 = mx3[1] - min3
ttl -= mx1[0] + mx2[0] + mx3[0]
while ttl > 0:
	if ttl >= max1 and ttl > 0:
		ttl -= max1
		min1 += max1
	else:
		min1 += ttl
		ttl = 0
	if ttl >= max2 and ttl > 0:
		ttl -= max2
		min2 += max2
	else:
		min2 += ttl
		ttl = 0
	if ttl >= max3 and ttl > 0:
		ttl -= max3
		min3 += max3
	else:
		min3 += ttl
		ttl = 0
print(str(min1) + ' ' + str(min2) + ' ' + str(min3))


def result(a, b, c: int) -> None:
	print(a, end=' ')
	print(b, end=' ')
	print(c)
people = int(input())
mini = []
maxi = []
for i in range(3):
	temp = input().split(' ')
	mini.append(int(temp[0]))
	maxi.append(int(temp[1]))
mini_sum = 0
maxi_sum = 0
for i in range(3):
	mini_sum += mini[i]
	maxi_sum += maxi[i]
if mini_sum == people:
	for i in range(3):
		print(mini[i], end=' ')
elif maxi_sum == people:
	for i in range(3):
		print(maxi[i], end=' ')
elif people > maxi[0] + maxi[1] + mini[2]:
	result(maxi[0], maxi[1], people - maxi[0] - maxi[1])
elif people > maxi[0] + mini[1] + mini[2]:
	result(maxi[0], people - maxi[0] - mini[2], mini[2])
else:
	result(people - mini[1] - mini[2], mini[1], mini[2])


n = int(input())
m = sum([list(map(int, input().split())) for x in range(3)], [])
(result, n) = (list(m[::2]), n - sum(m[::2]))
for i in range(3):
	temp = min(n, m[2 * i + 1] - m[2 * i])
	result[i] += temp
	n -= temp
print(*result)


n = int(input())
mn = []
mx = []
ans = []
for i in range(1, 4):
	(x, y) = map(int, input().split())
	mn.append(x)
	mx.append(y)
m1 = n - (mn[1] + mn[2])
if m1 < mx[0]:
	ans.append(m1)
else:
	ans.append(mx[0])
n -= ans[0]
m2 = n - mn[2]
if m2 < mx[1]:
	ans.append(m2)
else:
	ans.append(mx[1])
ans.append(n - ans[1])
for i in range(len(ans)):
	print(ans[i], end=' ')


__author__ = 'Данила'
n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
ans1 = min(max1, n - min2 - min3)
n -= ans1
ans2 = min(max2, n - min3)
ans3 = n - ans2
print(ans1, ans2, ans3)


n = int(input())
(a1, b1) = map(int, input().split())
(a2, b2) = map(int, input().split())
(a3, b3) = map(int, input().split())
k1 = a1
k2 = a2
k3 = a3
n = n - k1 - k2 - k3
for i in range(n):
	if k1 < b1:
		k1 = k1 + 1
	elif k2 < b2:
		k2 = k2 + 1
	else:
		k3 = k3 + 1
print(k1, k2, k3)


import sys
(sums, ans) = (int(input()), [0] * 4)
mat = [[int(i) for i in line.split()] for line in sys.stdin]
for i in range(len(mat)):
	ans[i] = mat[i][0]
	sums -= ans[i]
for i in range(3):
	if sums > 0 and ans[i] < mat[i][1]:
		tmp = min(sums, mat[i][1] - ans[i])
		ans[i] += tmp
		sums -= tmp
print(ans[0], ans[1], ans[2])


from sys import stdin
n = int(stdin.readline())
k = []
a = []
for i in range(0, 3):
	(vmin, vmax) = map(int, stdin.readline().split())
	a.append(vmax)
	n -= vmin
	k.append(vmin)
for i in range(0, 3):
	z = min(a[i] - k[i], n)
	k[i] += z
	n -= z
print(' '.join([str(i) for i in k]))


n = int(input())
(min1, max1) = list(map(int, input().split()))
(min2, max2) = list(map(int, input().split()))
(min3, max3) = list(map(int, input().split()))
x = n - min1 - min2 - min3
ans1 = min(max1, x + min1)
x = x - (ans1 - min1)
ans2 = min(max2, x + min2)
x = x - (ans2 - min2)
ans3 = min3 + x
print(ans1, ans2, ans3)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
v = [min1, min2, min3]
n -= min1 + min2 + min3
for i in range(min1, max1):
	if n <= 0:
		break
	v[0] += 1
	n -= 1
for i in range(min2, max2):
	if n <= 0:
		break
	v[1] += 1
	n -= 1
for i in range(min3, max3):
	if n <= 0:
		break
	v[2] += 1
	n -= 1
print(*v)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
r = max1 + 1
while r > max1:
	r = n - min2 - min3
	if r > max1 and min2 < max2:
		min2 = min2 + 1
	elif r > max1 and min3 < max3:
		min3 = min3 + 1
	else:
		break
print(r, min2, min3)


n = int(input())
(o1, o2) = map(int, input().split())
(s1, s2) = map(int, input().split())
(t1, t2) = map(int, input().split())
(a1, a2, a3) = (o1, s1, t1)
sum = o1 + t1 + s1
if sum == n:
	print(a1, a2, a3)
else:
	remain = n - sum
	if o2 - o1 < remain:
		a1 = o2
		remain = remain - (o2 - o1)
		if s2 - s1 < remain:
			a2 = s2
			remain = remain - (s2 - s1)
			if t2 - t1 < remain:
				a3 = t2
			else:
				a3 += remain
		else:
			a2 += remain
	else:
		a1 += remain
	print(a1, a2, a3)


n = int(input())
(a1, a2) = map(int, input().split())
(b1, b2) = map(int, input().split())
(c1, c2) = map(int, input().split())
A = min(a2, n - b1 - c1)
B = min(b2, n - A - c1)
C = n - A - B
print(A, B, C)


i = int(input())
(a, a1) = map(int, input().split())
(b, b1) = map(int, input().split())
(c, c1) = map(int, input().split())
i -= a + b + c
if i > 0:
	a += i
	if a > a1:
		i = a - a1
		a = a1
	else:
		i = 0
	b += i
	if b > b1:
		i = b - b1
		b = b1
	else:
		i = 0
	c += i
	if c > c1:
		i = c - c1
		c = c1
	else:
		i = 0
print(a, b, c)


n = int(input())
(a, b) = list(map(int, input().split()))
(c, d) = list(map(int, input().split()))
(e, f) = list(map(int, input().split()))
x = min(b, n - c - e)
y = min(d, n - x - e)
print(x, y, n - x - y)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
answer = [min1, min2, min3]
if sum(answer) < n:
	answer[0] += min(max1 - min1, n - sum(answer))
if sum(answer) < n:
	answer[1] += min(max2 - min2, n - sum(answer))
if sum(answer) < n:
	answer[2] += min(max3 - min3, n - sum(answer))
print(answer[0], answer[1], answer[2])


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
remaining1 = max1 - min1
remaining2 = max2 - min2
remaining3 = max3 - min3
sum1 = min1
sum2 = min2
sum3 = min3
remaining_sum = n - min1 - min2 - min3
if remaining_sum == 0:
	print(sum1, sum2, sum3)
else:
	if remaining_sum <= remaining1:
		sum1 += remaining_sum
	else:
		sum1 += remaining1
		remaining_sum -= remaining1
		if remaining_sum <= remaining2:
			sum2 += remaining_sum
		else:
			sum2 += remaining2
			sum3 += remaining_sum - remaining2
	print(sum1, sum2, sum3)


n = int(input())
minimum = []
maximum = []
for x in range(3):
	string = input()
	numbers = string.split()
	minimum.append(int(numbers[0]))
	maximum.append(int(numbers[1]))
diplomas = []
for x in range(3):
	minimum[x] = 0
	a = min([n - sum(minimum), maximum[x]])
	minimum[x] = a
	diplomas.append(a)
print(' '.join(map(str, diplomas)))


from sys import stdin, stdout

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

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

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

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
(min1, max1) = ei()
(min2, max2) = ei()
(min3, max3) = ei()
minsum = min1 + min2 + min3
if minsum == n:
	print(min1, min2, min3)
	exit()
else:
	li = []
	first = n - (min2 + min3)
	if first <= max1:
		li.append(first)
	else:
		li.append(max1)
		first = max1
	if n - (first + min3) <= max2:
		second = n - (first + min3)
		li.append(second)
	else:
		li.append(max2)
		second = max2
	if n - (first + second) <= max3:
		li.append(n - (first + second))
	else:
		li.append(max3)
print(*li)


n = int(input())
li = []
for i in range(3):
	li.append(list(map(int, input().split())))
ans = []
t = 0
for i in range(3):
	ans.append(li[i][0])
	t += li[i][0]
n -= t
for i in range(3):
	ans[i] += min(n, li[i][1] - li[i][0])
	n -= min(n, li[i][1] - li[i][0])
print(*ans)


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


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
s = min1 + min2 + min3
if s < n:
	min1 = min(max1, min1 + n - s)
s = min1 + min2 + min3
if s < n:
	min2 = min(max2, min2 + n - s)
s = min1 + min2 + min3
if s < n:
	min3 = min(max3, min3 + n - s)
print(min1, min2, min3)


def main():
	n = int(input())
	(min1, max1) = [int(i) for i in input().split()]
	(min2, max2) = [int(i) for i in input().split()]
	(min3, max3) = [int(i) for i in input().split()]
	for x in range(min(n - 1, max1), min1 - 1, -1):
		if min3 <= n - x - max2 <= max3:
			print(x, max2, n - x - max2)
			return
		if min2 <= n - x - min3 <= max2:
			print(x, n - x - min3, min3)
			return
main()


n = int(input())
(mi1, ma1) = map(int, input().split())
(mi2, ma2) = map(int, input().split())
(mi3, ma3) = map(int, input().split())
(a1, a2, a3) = (mi1, mi2, mi3)
while a1 < ma1 and a1 + a2 + a3 < n:
	a1 += 1
while a2 < ma2 and a1 + a2 + a3 < n:
	a2 += 1
while a3 < ma3 and a1 + a2 + a3 < n:
	a3 += 1
print(a1, a2, a3)


n = int(input())
c = list((list(map(int, input().split())) for _ in range(3)))
d = list((x[0] for x in c))
r = sum(d)
for i in range(3):
	if r < n:
		d[i] = min(d[i] + n - r, c[i][1])
		r += d[i] - c[i][0]
print(' '.join(map(str, d)))


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
if max1 + max2 + max3 == n:
	print(str(max1), str(max2), str(max3))
	quit()
if max1 + max2 + min3 <= n:
	print(str(max1), str(max2), str(n - max1 - max2))
	quit()
if max1 + min2 + min3 <= n:
	print(str(max1), str(n - max1 - min3), str(min3))
	quit()
print(str(n - min2 - min3), str(min2), str(min3))


from functools import reduce
n = int(input())
mn = []
mx = []
for i in range(3):
	line = input().split()
	mn.append(int(line[0]))
	mx.append(int(line[1]))
n -= reduce(lambda a, b: a + b, mn)
for i in range(3):
	mx[i] -= mn[i]
i = 0
while n > 0:
	temp = min(n, mx[i])
	mn[i] += temp
	n -= temp
	i += 1
print(f'{mn[0]} {mn[1]} {mn[2]}')


n = int(input())
(l, out) = ([], [])
for i in range(3):
	(l1, l2) = input().split()
	out.append(int(l1))
	l.append(int(l2))
k = sum(out)
if k == n:
	for i in range(3):
		print(out[i], '', end='')
else:
	k = n - k
	i = 0
	while i < 3:
		if k >= l[i] - out[i]:
			k -= l[i] - out[i]
			out[i] = l[i]
		else:
			out[i] += k
			break
		i += 1
	for i in range(3):
		print(out[i], '', end='')


n = int(input())
(min1, max1) = map(int, input().split(' '))
(min2, max2) = map(int, input().split(' '))
(min3, max3) = map(int, input().split(' '))
x1 = min(n - min3 - min2, max1)
n -= x1
x2 = min(n - min3, max2)
x3 = n - x2
print(x1, x2, x3)


n = int(input())
(l1, r1) = map(int, input().split())
(l2, r2) = map(int, input().split())
(l3, r3) = map(int, input().split())
k1 = 0
k2 = 0
for i in range(l1, r1 + 1):
	if n - i >= l2 + l3 and n - i <= r2 + r3:
		k1 = i
for i in range(l2, r2 + 1):
	if i <= n - k1 and n - i - k1 >= l3 and (n - i - k1 <= r3):
		k2 = i
print(k1, k2, n - k1 - k2)


import sys
n = int(input())
(min1, max1) = map(int, sys.stdin.readline().split())
(min2, max2) = map(int, sys.stdin.readline().split())
(min3, max3) = map(int, sys.stdin.readline().split())
nb1 = min(max1, n - min2 - min3)
n -= nb1
nb2 = min(max2, n - min3)
nb3 = n - nb2
print(nb1, nb2, nb3)


n = int(input())
(x1, x2) = map(int, input().split())
(y1, y2) = map(int, input().split())
(z1, z2) = map(int, input().split())
ans1 = x1
ans2 = y1
ans3 = z1
n -= ans1 + ans2 + ans3
if n > 0:
	ans1 += min(n, x2 - x1)
	n -= x2 - x1
if n > 0:
	ans2 += min(n, y2 - y1)
	n -= y2 - y1
if n > 0:
	ans3 += min(n, z2 - z1)
	n -= z2 - z1
print(ans1, ans2, ans3)


def solve(arr, n):
	res = []
	for i in arr:
		res.append(i[0])
		n -= i[0]
	for (i, v) in enumerate(arr):
		if not n:
			return res
		temp = min(v[1] - res[i], n)
		n -= temp
		res[i] += temp
	return res

def main():
	n = int(input())
	arr = []
	for _ in range(3):
		arr.append(list(map(int, list(input().split(' ')))))
	print(*solve(arr, n))
main()


(n, mind, v) = (int(input()), [0] * 3, [0] * 3)
for i in range(3):
	(mind[i], v[i]) = map(int, input().split())
t = sum(v)
for i in range(2, -1, -1):
	c = max(0, min(t - n, v[i] - mind[i]))
	v[i] -= c
	t -= c
print(v[0], v[1], v[2])


n = int(input())
(min, max, sub) = ([0] * 4, [0] * 4, [0] * 4)
for i in range(1, 4):
	s = [int(x) for x in input().split(' ')]
	(min[i], max[i]) = (s[0], s[1])
	sub[i] = max[i] - min[i]
n -= sum(min)
x = min
for i in range(1, 4):
	x[i] += sub[i] if n - sub[i] >= 0 else n
	n -= sub[i] if n - sub[i] >= 0 else n
print(' '.join([str(i) for i in x[1:]]))


n = int(input())
d = {}
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
(ans1, ans2, ans3) = (min1, min2, min3)
while ans1 < max1 and ans1 + ans2 + ans3 < n:
	ans1 += 1
while ans2 < max2 and ans1 + ans2 + ans3 < n:
	ans2 += 1
while ans3 < max3 and ans1 + ans2 + ans3 < n:
	ans3 += 1
print(ans1, ans2, ans3)


n = int(input())
(min_1, max_1) = map(int, input().split())
(min_2, max_2) = map(int, input().split())
(min_3, max_3) = map(int, input().split())
if max_1 + min_2 + min_3 >= n:
	print(str(n - min_2 - min_3) + ' ' + str(min_2) + ' ' + str(min_3))
elif max_1 + max_2 + min_3 >= n:
	print(str(max_1) + ' ' + str(n - max_1 - min_3) + ' ' + str(min_3))
else:
	print(str(max_1) + ' ' + str(max_2) + ' ' + str(n - max_1 - max_2))


n = int(input())
(a, b) = [int(x) for x in input().split()]
(c, d) = [int(x) for x in input().split()]
(e, f) = [int(x) for x in input().split()]
(x, y, z) = (0, 0, 0)
if b + c + e >= n:
	(x, y, z) = (n - c - e, c, e)
elif b + d + e >= n:
	(x, y, z) = (b, n - b - e, e)
else:
	(x, y, z) = (b, d, n - b - d)
print(x, y, z)


n = int(input())
a = [0] * 3
b = [0] * 3
(a[0], b[0]) = map(int, input().split())
(a[1], b[1]) = map(int, input().split())
(a[2], b[2]) = map(int, input().split())
if sum(a) < n:
	n -= sum(a)
	m1 = min(n, b[0] - a[0])
	n -= m1
	m2 = min(n, b[1] - a[1])
	n -= m2
	m3 = min(n, b[2] - a[2])
	n -= m3
	a[0] += m1
	a[1] += m2
	a[2] += m3
print(a[0], a[1], a[2])


n = int(input())
first = input().split()
firstmin = int(first[0])
firstmax = int(first[1])
extrafirst = firstmax - firstmin
second = input().split()
secondmin = int(second[0])
secondmax = int(second[1])
extrasecond = secondmax - secondmin
third = input().split()
thirdmin = int(third[0])
thirdmax = int(third[1])
extrathird = thirdmax - thirdmin
firsttotal = firstmin
secondtotal = secondmin
thirdtotal = thirdmin
leftover = n - firstmin - secondmin - thirdmin
if extrafirst >= leftover:
	firsttotal += leftover
else:
	firsttotal = firstmax
	leftover -= extrafirst
	if extrasecond >= leftover:
		secondtotal += leftover
	else:
		secondtotal = secondmax
		leftover -= extrasecond
		thirdtotal += leftover
print(str(firsttotal) + ' ' + str(secondtotal) + ' ' + str(thirdtotal))


n = int(input())
(amin, amax) = map(int, input().split())
(bmin, bmax) = map(int, input().split())
(cmin, cmax) = map(int, input().split())
temp1 = min(amax, n - bmin - cmin)
n -= temp1
temp2 = min(bmax, n - cmin)
n -= temp2
temp3 = n
print(temp1, temp2, temp3)


n = input()
(min1, max1) = input().split()
(min2, max2) = input().split()
(min3, max3) = input().split()
if int(min3) <= int(n) - int(max1) - int(max2):
	n1 = max1
	n2 = max2
	n3 = int(n) - int(n1) - int(n2)
elif int(min2) <= int(n) - int(max1) - int(min3):
	n1 = max1
	n3 = min3
	n2 = int(n) - int(n1) - int(n3)
else:
	n2 = min2
	n3 = min3
	n1 = int(n) - int(n2) - int(n3)
print(str(n1) + ' ' + str(n2) + ' ' + str(n3))


n = int(input())

def getOpt(n, ma, test):
	if n - test <= ma:
		return n - test
	else:
		return ma
(a1, a2) = map(int, input().split())
(b1, b2) = map(int, input().split())
(c1, c2) = map(int, input().split())
k1 = getOpt(n, a2, b1 + c1)
k2 = getOpt(n - k1, b2, c1)
k3 = n - k1 - k2
print(k1, k2, k3)


n = int(input())
(min1, max1) = map(int, input().split())
(min2, max2) = map(int, input().split())
(min3, max3) = map(int, input().split())
a1 = min1
a2 = min2
a3 = min3
n = n - a1 - a2 - a3
max1 -= min1
max2 -= min2
max3 -= min3
if n > max1:
	a1 += max1
	n -= max1
else:
	a1 += n
	n = 0
if n > max2:
	a2 += max2
	n -= max2
else:
	a2 += n
	n = 0
if n > max3:
	a3 += max3
	n -= max3
else:
	a3 += n
	n = 0
print(a1, a2, a3)


def f(n, l):
	(l1, r1) = l[0]
	(l2, r2) = l[1]
	(l3, r3) = l[2]
	c1 = min(r1, n - l2 - l3)
	c2 = min(r2, n - c1 - l3)
	c3 = n - c1 - c2
	return [c1, c2, c3]
n = int(input())
l = [list(map(int, input().split())) for _ in range(3)]
print(*f(n, l))


n = int(input())
(minArray, maxArray) = ([0] * 3, [0] * 3)
for i in range(0, 3):
	tempString = input()
	tempList = tempString.split()
	(minArray[i], maxArray[i]) = (int(tempList[0]), int(tempList[1]))

def testPosible(array, n, minArray, maxArray):
	if sum(array) <= n:
		for i in range(0, 3):
			if minArray[i] > array[i] or array[i] > maxArray[i]:
				return False
		return True
	else:
		return False
price = minArray
if testPosible([maxArray[0], minArray[1], minArray[2]], n, minArray, maxArray):
	price[0] = maxArray[0]
else:
	price[0] = n - price[1] - price[2]
if testPosible([price[0], maxArray[1], price[2]], n, minArray, maxArray):
	price[1] = maxArray[1]
else:
	price[1] = n - price[0] - price[2]
if testPosible([price[0], price[1], maxArray[2]], n, minArray, maxArray):
	price[2] = maxArray[2]
else:
	price[2] = n - price[0] - price[1]
print(price[0], price[1], price[2])


__author__ = 'tka4a'
n = int(input())

def getOpt(n, ma, test):
	if n - test >= ma:
		return ma
	else:
		return n - test
(a1, b1) = map(int, input().split())
(a2, b2) = map(int, input().split())
(a3, b3) = map(int, input().split())
k1 = getOpt(n, b1, a2 + a3)
k2 = getOpt(n - k1, b2, a3)
k3 = n - k1 - k2
print(k1, k2, k3)


n = int(input())
a = [None] * 3
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
total = 0
b = [None] * 3
for i in range(3):
	total += a[i][0]
	b[i] = a[i][0]
while total < n:
	if b[0] < a[0][1]:
		k = a[0][1] - b[0]
		if total + k > n:
			b[0] += n - total
			total = n
		else:
			b[0] += k
			total += k
	if b[1] < a[1][1]:
		k = a[1][1] - b[1]
		if total + k > n:
			b[1] += n - total
			total = n
		else:
			b[1] += k
			total += k
	if b[2] < a[2][1]:
		k = a[2][1] - b[2]
		if total + k > n:
			b[2] += n - total
			total = n
		else:
			b[2] += k
			total += k
print(b[0], b[1], b[2])


n = int(input())
(mi1, ma1) = map(int, input().split())
(mi2, ma2) = map(int, input().split())
(mi3, ma3) = map(int, input().split())
if ma1 + mi2 + mi3 >= n:
	print(n - mi2 - mi3, mi2, mi3)
else:
	x = n - ma1 - mi2 - mi3
	if x < ma2 - mi2:
		print(ma1, mi2 + x, mi3)
	else:
		print(ma1, ma2, n - ma1 - ma2)


from sys import stdin
from sys import stdout
n = int(stdin.readline())
(min1, max1) = map(int, stdin.readline().split())
(min2, max2) = map(int, stdin.readline().split())
(min3, max3) = map(int, stdin.readline().split())
day1 = min(n - min2 - min3, max1)
day2 = min(n - day1 - min3, max2)
day3 = n - day1 - day2
stdout.write(str(day1) + ' ' + str(day2) + ' ' + str(day3))