A. Ilya and Diplomas



time limit per test



memory limit per test



input



output



n

each of the n

min1 and at most max1 diplomas of the first degree, at least min2 and at mostmax2 diplomas of the second degree, and at least min3 and at most max3

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.

nparticipants of the Olympiad will receive a diploma of some degree.



Input



n (3 ≤ n ≤ 3·106) — the number of schoolchildren who will participate in the Olympiad.

min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.

min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.

min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.

min1 + min2 + min3 ≤ n ≤ max1 + max2 + 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.



Sample test(s)



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



贪心,注意mini的存在


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int a[5][5],ans[5];
int main()
{
freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
int n;
cin>>n;
For(i,3) For(j,2) cin>>a[i][j];
For(i,3) ans[i]=a[i][1],n-=ans[i];

For(i,3)
{
if (n>0&&ans[i]<a[i][2])
{
int p=min(n,a[i][2]-ans[i]);
ans[i]+=p;
n-=p;
}
}

cout<<ans[1];
Fork(i,2,3) cout<<' '<<ans[i];
cout<<endl;

return 0;
}