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*<sub class="lower-index">1</sub> and at most *max*<sub class="lower-index">1</sub> diplomas of the first degree, at least *min*<sub class="lower-index">2</sub> and at most *max*<sub class="lower-index">2</sub> diplomas of the second degree, and at least *min*<sub class="lower-index">3</sub> and at most *max*<sub class="lower-index">3</sub> 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.
The first line of the input contains a single integer *n* (3 ≤ *n* ≤ 3·10<sup class="upper-index">6</sup>) — the number of schoolchildren who will participate in the Olympiad.

The next line of the input contains two integers *min*<sub class="lower-index">1</sub> and *max*<sub class="lower-index">1</sub> (1 ≤ *min*<sub class="lower-index">1</sub> ≤ *max*<sub class="lower-index">1</sub> ≤ 10<sup class="upper-index">6</sup>) — 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*<sub class="lower-index">2</sub> and *max*<sub class="lower-index">2</sub> (1 ≤ *min*<sub class="lower-index">2</sub> ≤ *max*<sub class="lower-index">2</sub> ≤ 10<sup class="upper-index">6</sup>) — 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*<sub class="lower-index">3</sub> and *max*<sub class="lower-index">3</sub> (1 ≤ *min*<sub class="lower-index">3</sub> ≤ *max*<sub class="lower-index">3</sub> ≤ 10<sup class="upper-index">6</sup>) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. 

It is guaranteed that *min*<sub class="lower-index">1</sub> + *min*<sub class="lower-index">2</sub> + *min*<sub class="lower-index">3</sub> ≤ *n* ≤ *max*<sub class="lower-index">1</sub> + *max*<sub class="lower-index">2</sub> + *max*<sub class="lower-index">3</sub>.
#!/usr/bin/env python
# 557A_diploma.py - Codeforces.com 557A Diploma quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Input

The first line of the input contains a single integer n - the number of
schoolchildren who will participate in the Olympiad.

The next line of the input contains two integers min1 and max1
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 min2 and max2

The next line of the input contains two integers min3 and max3

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.
"""

# Standard libraries
import unittest
import sys
import re

# Additional libraries


###############################################################################
# Diploma Class
###############################################################################


class Diploma:
    """ Diploma representation """

    def __init__(self, args):
        """ Default constructor """

        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):
        """ Main calcualtion function of the class """

        self.set_range()
        result = self.range

        return str(" ".join([str(n) for n in result]))


###############################################################################
# Executable code
###############################################################################


def get_inputs(test_inputs=None):

    it = iter(test_inputs.split("\n")) if test_inputs else None

    def uinput():
        """ Unit-testable input function wrapper """
        if it:
            return next(it)
        else:
            return input()

    # Getting string inputs. Place all uinput() calls here
    num = int(uinput())
    nums = [[int(s) for s in uinput().split()] for i in range(3)]

    # Decoding inputs into a list
    inputs = []
    inputs.append(num)
    inputs += nums

    return inputs


def calculate(test_inputs=None):
    """ Base class calculate method wrapper """
    return Diploma(get_inputs(test_inputs)).calculate()


###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_sample_tests(self):
        """ Quiz sample tests. Add \n to separate lines """

        # Sample test 1
        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]])

        # Other tests
        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):
        """ Diploma class basic functions testing """

        # Constructor test
        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])

        # Calculate ranges
        d.set_range()
        self.assertEqual(d.range, [1, 2, 3])


if __name__ == "__main__":

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    print(calculate())
