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: interview

Starter code:

Solutions:
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)

__author__ = 'Данила'

n = int(input())
min1, max1 = list(map(int, input().split()))
min2, max2 = list(map(int, input().split()))
min3, max3 = list(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, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))
c1, c2 = list(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())
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())
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())
min1, max1 = map(int, input().split())
min2, max2 = map(int, input().split())
min3, max3 = map(int, input().split())
ans1 = min(n - min2 - min3, max1)
ans2 = min(n - ans1 - min3, max2)
ans3 = min(n - ans1 - ans2, max3)
print(ans1, ans2, ans3)

# A

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())
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]))
    


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)


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())
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))


#!/usr/bin/env python3

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)

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 math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

# Guide:
#   1. construct complex data types while reading (e.g. graph adj list)
#   2. avoid any non-necessary time/memory usage
#   3. avoid templates and write more from scratch
#   4. switch to "flat" implementations

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): # input matrix of integers
    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): # input matrix of strings
    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): # input transposed matrix/array of integers
    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()

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())
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))

n = int(input())
m_1, mx_1 = list(map(int, input().split()))
m_2, mx_2 = list(map(int, input().split()))
m_3, mx_3 = list(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)


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())
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))




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, 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())
min1, max1 = map(int, input().split())
min2, max2 = map(int, input().split())
min3, max3 = map(int, input().split())

d1 = min(n - min2 - min3, max1)
n -= d1
d2 = min(n - min3, max2)
d3 = n - d2
print('{} {} {}'.format(d1, d2, d3))

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)

__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())
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)