#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,num,count=0,ze=0,one=0,count1=0,count0=0;
	vector <int> a;
	cin>> n;
	for(i=0;i<n;i++){
		cin >>num;
		a.push_back(num);
		if(num==0)
			ze++;
		else
			one++;
	}
	for(i=0;i<n;i++){
		count++;
		if(a[i]==0){
			count0++;
		}
		else if(a[i]==1){
			count1++;
		}
		if(count0==ze || count1==one)
			break;
	}
	cout<<count;
}


#include<iostream>
using namespace std;
int a[200001],n,x,y;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n;i>=1;i--)
    {
        if(a[i])x++;
			else ++y;
        if(x&&y)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int left=0,right=0;
	int *all=new int [n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>all[i];
		if(0==all[i])
			left++;
		else
			right++;
	}
	int l=0,r=0;
	for(int i=1;i<=n;i++)
	{
		if(0==all[i])
			l++;
		else
			r++;
		if(l==left)
		{
			cout<<i;
			break;
		}
		if(r==right)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}


// luogu-judger-enable-o2
#include<iostream>
using namespace std;

int main (){

	long long n, k;
	long long v[200001];
	cin >> k;
	for (int j = 0;j < k;j++){
		cin >> v[j];
	}

	int zuo = 0, you = 0;
	for(int l = 0;l < n;l++){
		if(v[l] == '0') zuo++;
		else you++;
	}

	int sum = 0;
	int z, y;
	for(int i = 1;i <= n;i++){
		if(v[i] == '0'){
			z++;
			sum++;
		}
		else{
			y++;
				sum++;
		}

		if(z == zuo){
			cout << sum << endl;
			break;
		}
		if(y == you){
			cout << sum << endl;
			break;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,n;
int main(){
	cin>>n;
	int i,j;
	int l1,l2;
	for(i=0;i<n;++i){
	    cin>>a;
		if(a==0) l1=i;
		else l2=i;
	}
	cout<<min(l1,l2)+1<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
int n;
int cnt[2];
int a[200007];
int main()
{
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
 {
  scanf("%d",&a[i]);
  cnt[a[i]]++;
 }
 for(int i=1;i<=n;i++)
 {
  cnt[a[i]]--;
  if(cnt[a[i]]==0)
  {
   printf("%d\n",i);
   break;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int a[200005],n;
int ans=2e9,flag[2]={1,1};
int main(){
//	freopen("1143A.in","r",stdin);
//	freopen("1143A.out","w",stdout);
	cin>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=n;i;i--)
		if (flag[a[i]])ans=i,flag[a[i]]=0;

	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
using namespace std;
int a[200005],n;
int ans=2e9,flag[2]={1,1};
int main(){
//	freopen("1143A.in","r",stdin);
//	freopen("1143A.out","w",stdout);
	cin>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=n;i;i--)
		if (flag[a[i]])ans=i,flag[a[i]]=0;
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
int a[200005],n;
int ans=2e9,flag[2]={1,1};
int main(){
//	freopen("1143A.in","r",stdin);
//	freopen("1143A.out","w",stdout);
	cin>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=n;i;i--)
		if (flag[a[i]])ans=i,flag[a[i]]=0;
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 200000 + 5;

int n, s[maxn], a, b;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &s[i]);
		if(s[i] == 0) a++;
		else b++;
	} for(int i = 0; i < n; i++) {
		if(s[i] == 0) a--;
		else b--;
		if(a == 0 || b == 0) {
			printf("%d\n", i + 1);
			return 0;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,a[200001]={0};
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int sum=1;
	for(int i=n;i>=1;i-=1){
		if(a[i]==a[i-1]){
			sum+=1;
		}else{
			break;
		}
	}
	cout<<n-sum;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

const int MAXN = 200005;
int n, x, a[MAXN];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    int x = a[n];
    for (int i = n - 1; i >= 1; i--)
        if (a[i] != x) {
            printf("%d\n", i);
            return 0;
        }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,x,y,o;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&o);
		if (o==0) x=i;
		else y=i;
	}
	printf("%d",min(x,y));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,cn1,cn0,q[10000],cp0,cp1;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>q[i];
		if(q[i]==0)cn0++;
		if(q[i]==1)cn1++;
	}
	for(int i=0;i<n;i++){
		if(q[i]==0)cp0++;
		if(q[i]==1)cp1++;
		if(cp0==cn0||cp1==cn1){
			cout<<i+1;
			return 0;
		}
	}
}


#include<iostream>
#include<cstdio>
#define N 200005
using namespace std;

int main()
{
    int n,door[N],i,flag;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&door[i]);
    }
    flag = door[--i];
    while(door[i--]==flag);
    printf("%d\n",i+2);
    return 0;
}


#include<iostream>
using namespace std;
bool a[200001];
int main()
{
	int n,i,l=0,r=0,l1=0,r1=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(!a[i])
			l++;
		else
			r++;
	}
	for(i=1;i<=n;i++)
	{
		if(!a[i])
			l1++;
		else
			r1++;
		if(l1==l||r1==r)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,a[200001]={0};
	cin>>n;
	for(int i=1;i<=n;i+=1){
		cin>>a[i];
	}
	int sum=1;
	for(int i=n;i>=1;i-=1){
		if(a[i]==a[i-1]){
			sum+=1;
		} else {
			break;
		}
	}
	cout<<n-sum;

	return 0;
}


#include<cstdio>
using namespace std;
int n,a[200001],t;//数组开大呦
int main()
{
    scanf("%d",&n);//输入门的数量
    for(int i=1;i<=n;i++)//输入门
      scanf("%d",&a[i]);
    t=a[n];//t存最后一个门的数
    for(int i=n-1;i>=1;i--)
    {
        if(a[i]!=t)//找到最后一个和a[n]不一样的就可以逃了
        {
            printf("%d",i);//输出结果
            return 0;
        }
    }
    //因为必定有和a[n]不一样的，所以最后不用写 return 0了
 }


#include<bits/stdc++.h>
#define TP int
#define Max 1000009
using namespace std;
inline TP read(){
    char c=getchar();
    TP x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f)x=-x;return x;
}
inline double readdouble(){
    char c=getchar();
    double x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=x*10+(c^48),c=getchar();
    if(!(c^46)){
        double t=1;c=getchar();
        while(isdigit(c))t/=10,x+=t*(c^48),c=getchar();
    }if(f)x=-x;return x;
}
inline bool blank(char c){return !(c&&c^9&&c^10&&c^13&&c^32);}
inline void readstr(char *s){
    char c=getchar();
    while(blank(c))c=getchar();
    while(!blank(c))*s++=c,c=getchar();*s=0;
}
inline bool isendl(char c){return !(c&&c^10&&c^13);}
inline void getstr(char *s){
    char c=getchar();
    while(isendl(c))c=getchar();
    while(!isendl(c))*s++=c,c=getchar();*s=0;
}
int n=read(),qw1,qw2,k;
int main(){
	for(int i=1;i<=n;i++){
		k=read();
		if(k==0){
			qw1=i;
		}
		else{
			qw2=i;
		}
	}
	int ans=min(qw1,qw2);
	cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2222322];
int main(){
	int n;
	int s=0,s1=0,s2=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==1)s2++;
		else s1++;
	}
	int ss1=s1,ss2=s2;
	for(int i=1;i<=n;i++){
		if(a[i]==1)ss2--;
		else ss1--;
		if(ss1==0||ss2==0){
			s=i;
			break;
		}
	}
	for(int i=n;i>0;i--){
		if(a[i]==1)s2--;
		else s1--;
		if(s1==0||s2==0){
			if(i>s)s=i;
			cout<<s;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,b,c;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",strout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
		scanf("%d",&c);
    	if(c==0)  a=i;
    	else    b=i;
    }
    cout<<min(a,b)<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],n,m,x,y,ans;
int main()
{
    cin>>n;
	for ( register int i=1;i<=n;i++ ) cin>>a[i];
	for ( register int i=n;i>=1;i-- )
	{
	    if(a[i]==1) x++;
		else y++;
		if(x&&y)
		{
		    printf("%d",i);
			return 0;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int a[200001];
int l=0,r=0;
int main(){
	int i,j,k,n;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=n;i>=2;i--)
	if(l==0||r==0){
		if(l==0&&a[i]==0)l=i;
		if(r==0&&a[i]==1)r=i;
	}
	else break;
	cout<<min(l,r)<<endl;
	return 0;
}


// luogu-judger-enable-o2
#include<iostream>
using namespace std;

int main (){

	int k, v[200001] = {0};
	cin >> k;
	for (int j = 1;j <= k;j++){
		cin >> v[j];
	}

	int sum = 0;
	for(int i = k;i >= 1;i--){
		if(v[i] == v[i-1]){
			sum++;
		}
		else break;
	}
	cout << k - sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,max1,max2,k;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
	 	scanf("%d",&k);
      	if(k==0){
		  	max1=i;
		}else{
		  	max2=i;
		}
    }
    cout<<min(max1,max2)<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int c,d;
int a[100005];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<= n;i++){
        cin>>a[i];
        if(a[i]==1)c++;
        if(a[i]==0)d++;
    }
    for(int i=1; i<= n;i++){
        if(a[i]==1)c--;
        if(a[i]==0)d--;
        if(c == 0 || d==0){
        cout<<i;
        return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int c,d;
int a[200005];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<= n;i++){
        cin>>a[i];
        if(a[i]==1)c = max(c,i);
        if(a[i]==0)d = max(d,i);
    }
    cout<<min(c,d);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int c,d;
int a[100005];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<= n;i++){
        cin>>a[i];
        if(a[i]==1)c++;
        if(a[i]==0)d++;
    }
    if(c==0||d==0){cout<<0;return 0;}
    for(int i=1; i<= n;i++){
        if(a[i]==1)c--;
        if(a[i]==0)d--;
        if(c == 0 || d==0){
        cout<<i;
        return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int c,d;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int a;
    for(int i=1; i<= n;i++){
        cin>>a;
        if(a==1)c++;
        if(a==0)d++;
    }
    for(int i=1; i<= n;i++){
        if(a==1)c--;
        if(a==0)d--;
        if(c == 0 || d==0){
        cout<<i;
        return 0;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  n,i,q,j,l,k,t;
main(){
	cin>>n;
	long long a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==1)t++;
		else k++;
	}
	for(i=0;i<n;i++){
		q=a[i];
		if(q==0)k--;
		else t--;
		if(q==1){
			if(k==n-i-1)return cout<<i+1,0;
		}
		else {
			if(t==n-i-1)return cout<<i+1,0;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
long long  n,i,q,j,l;
main(){
	cin>>n;
	long long a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		q=a[i];l=0;
		for(j=i+1;j<n;j++){
			if(a[j]!=q)l++;
		}
		if(l==n-(i+1))return cout<<i+1,0;
	}
}


#include<bits/stdc++.h>
using namespace std;
int a[2000002];
int main()
{ int n,g;
cin>>n;
for(int i=1;i<=n;i++)
{
	cin>>a[i];
}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
		{
			g=i;
		}
	}

cout<<g;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2000002];
int main()
{ int n,g;
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
	for(int i=0;i<n;i++)
	{
		if(a[i]='1')
		{
			g=i;
		}
	}

cout<<g;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2000002];
int main()
{ int n,g,cnt=0;
cin>>n;
for(int i=1;i<=n;i++)
{
	cin>>a[i];
}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
		{
		g=i;
		}
		if(a[n]==1)
		{
			cout<<n-1;
			return 0;
		}
	}

cout<<g;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[200001],d[2];
int main(){

		cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		d[a[i]]=i;
	}

	cout<<min(d[0],d[1]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2000002];
int main()
{ int n,g,cnt=0;
cin>>n;
for(int i=1;i<=n;i++)
{
	cin>>a[i];
}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
		{
		cnt++;
		g=i;
		}
		if(a[n]==1 && cnt>1)
		{
			cout<<n-1;
			return 0;
		}
	}

cout<<g;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int main()
{
    double s;
    int n,co=0;
    cin>>n;
    s=floor(n/2);
    for(int i=0;i<n;i++)
    {
        int l;
        cin>>l;
        v.push_back(l);
    }
    int f=v[0];
    for(int i=1;i<n;i++)
    {

       if((v[i]==f)?f=v[i]:co=i)
        f=v[i];

    }
    cout<<co;
    return 0;
}


#include <iostream>
#include <algorithm>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin>>n;
	ll p[n],a,b,c,d,e,sum=0,aa=0,bb=0,cc=0,dd=0,ee=0;
	for(int i=0;i<n;i++)cin>>p[i];
	cin>>a>>b>>c>>d>>e;
	for(int i=0;i<n;i++){
		sum+=p[i];
		while(true){
		if(sum>=a && sum<b){sum-=a;  aa++;}
		else if(sum>=b && sum<c){sum-=b;  bb++;}
		else if(sum>=c && sum<d){sum-=c;  cc++;}
		else if(sum>=d && sum<e){sum-=d;  dd++;}
		else if(sum>=e ){sum-=e;  ee++;}
		else break;
		}
	}
	cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<" "<<ee<<endl;
	cout<<sum<<endl;
}


#include <iostream>
#include <algorithm>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin>>n;
	ll p[n],a,b,c,d,e,sum=0,aa=0,bb=0,cc=0,dd=0,ee=0;
	for(int i=0;i<n;i++)cin>>p[i];
	cin>>a>>b>>c>>d>>e;
	for(int i=0;i<n;i++){
		sum+=p[i];
		while(true){
		if(sum>=a && sum<b){aa+=sum/a; sum%=a;}
		else if(sum>=b && sum<c){bb+=sum/b;  sum%=b;}
		else if(sum>=c && sum<d){cc+=sum/c;  sum%=c;}
		else if(sum>=d && sum<e){dd+=sum/d;  sum%=d;}
		else if(sum>=e ){ee+=sum/d;  sum%=e;}
		else break;
		}
	}
	cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<" "<<ee<<endl;
	cout<<sum<<endl;
}


#include <iostream>
#include <algorithm>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin>>n;
	ll p[n],a,b,c,d,e,sum=0,aa=0,bb=0,cc=0,dd=0,ee=0;
	for(int i=0;i<n;i++)cin>>p[i];
	cin>>a>>b>>c>>d>>e;
	for(int i=0;i<n;i++){
		sum+=p[i];
		while(true){
		if(sum>=e ){ee+=sum/d;  sum%=e;}
		else if(sum>=d && sum<e){dd+=sum/d;  sum%=d;}
		else if(sum>=c && sum<d){cc+=sum/c;  sum%=c;}
		else if(sum>=b && sum<c){bb+=sum/b;  sum%=b;}
		else if(sum>=a && sum<b){aa+=sum/a; sum%=a;}
		else break;
		}
	}
	cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<" "<<ee<<endl;
	cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define fs first
#define sc second
int ABS(int a) {return max(a, -a);}
ll ABS(ll a) {return max(a, -a);}
double ABS(double a) {return max(a, -a);}

/*	ctrl+d -> us word ke saare occurences ko select karna and fir ek jagah type karke saari jagah change karna
	ctrl+shift+d -> us line ke duplicates banana just neeche
	ctrl+l -> ek line select karna
	ctrl+shift+m -> {ye do brackets ke beech ke saare content ko select karna}
	ctrl+shift+enter -> us line ke pehle line insert karna aur cursor inserted line pe le jaana
	ctrl+enter -> us line ke neeche line insert karna aur cursor ko use line pe le jaana
	ctrl+shift+k -> delete that perticular line
*/

const int N = 55;
int a[N], ans[6], n, g[6];

int index(int val)
{
	int id = lower_bound(g + 1, g + 6, val) - g;
	if (id < 1 )
		return -1;
	else if (id > 5)
		return 5;

	if (g[id] == val)
		return id;
	else
		return id - 1;
}

void solve()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= 5; i++)
		cin >> g[i];
	for (int i = 1; i <= 5; i++)
		ans[i] = 0;
	int left = 0;
	for (int i = 1; i <= n; i++)
	{
		left += a[i];
		while (left >= g[1])
		{
			int id = index(left);
			ans[id]++;
			left = left - g[id];
		}

	}

	for (int i = 1; i <= 5; i++)
		cout << ans[i] << " ";
	cout << "\n" << left;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>>t;

	while (t--)
		solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define fs first
#define sc second
int ABS(int a) {return max(a, -a);}
ll ABS(ll a) {return max(a, -a);}
double ABS(double a) {return max(a, -a);}

/*	ctrl+d -> us word ke saare occurences ko select karna and fir ek jagah type karke saari jagah change karna
	ctrl+shift+d -> us line ke duplicates banana just neeche
	ctrl+l -> ek line select karna
	ctrl+shift+m -> {ye do brackets ke beech ke saare content ko select karna}
	ctrl+shift+enter -> us line ke pehle line insert karna aur cursor inserted line pe le jaana
	ctrl+enter -> us line ke neeche line insert karna aur cursor ko use line pe le jaana
	ctrl+shift+k -> delete that perticular line
*/

const int N = 55;
int a[N], ans[6], n, g[6];

int index(int val)
{
	int id = lower_bound(g + 1, g + 6, val) - g;
	if (id < 1 )
		return -1;
	else if (id > 5)
		return 5;

	if (g[id] == val)
		return id;
	else
		return id - 1;
}

void solve()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= 5; i++)
		cin >> g[i];
	for (int i = 1; i <= 5; i++)
		ans[i] = 0;
	int left = 0;
	for (int i = 1; i <= n; i++)
	{
		left += a[i];
		while (left >= g[1])
		{
			int id = index(left);
			if (id == -1)
				break;
			int use = left / g[id];
			ans[id] += use;
			left -= (use * g[id]);
		}
	}

	for (int i = 1; i <= 5; i++)
		cout << ans[i] << " ";
	cout << "\n" << left;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>>t;

	while (t--)
		solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define fs first
#define sc second
int ABS(int a) {return max(a, -a);}
ll ABS(ll a) {return max(a, -a);}
double ABS(double a) {return max(a, -a);}

/*	ctrl+d -> us word ke saare occurences ko select karna and fir ek jagah type karke saari jagah change karna
	ctrl+shift+d -> us line ke duplicates banana just neeche
	ctrl+l -> ek line select karna
	ctrl+shift+m -> {ye do brackets ke beech ke saare content ko select karna}
	ctrl+shift+enter -> us line ke pehle line insert karna aur cursor inserted line pe le jaana
	ctrl+enter -> us line ke neeche line insert karna aur cursor ko use line pe le jaana
	ctrl+shift+k -> delete that perticular line
*/

const int N = 55;
int a[N], n, g[6];
ll ans[6];

int index(int val)
{
	int id = lower_bound(g + 1, g + 6, val) - g;
	if (id < 1 )
		return -1;
	else if (id > 5)
		return 5;

	if (g[id] == val)
		return id;
	else
		return id - 1;
}

void solve()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= 5; i++)
		cin >> g[i];
	for (int i = 1; i <= 5; i++)
		ans[i] = 0;
	int left = 0;
	for (int i = 1; i <= n; i++)
	{
		left += a[i];
		while (left >= g[1])
		{
			int id = index(left);
			if (id == -1)
				break;
			int use = left / g[id];
			ans[id] += use;
			left -= (use * g[id]);
		}
	}

	for (int i = 1; i <= 5; i++)
		cout << ans[i] << " ";
	cout << "\n" << left;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>>t;

	while (t--)
		solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define fs first
#define sc second
int ABS(int a) {return max(a, -a);}
ll ABS(ll a) {return max(a, -a);}
double ABS(double a) {return max(a, -a);}

/*	ctrl+d -> us word ke saare occurences ko select karna and fir ek jagah type karke saari jagah change karna
	ctrl+shift+d -> us line ke duplicates banana just neeche
	ctrl+l -> ek line select karna
	ctrl+shift+m -> {ye do brackets ke beech ke saare content ko select karna}
	ctrl+shift+enter -> us line ke pehle line insert karna aur cursor inserted line pe le jaana
	ctrl+enter -> us line ke neeche line insert karna aur cursor ko use line pe le jaana
	ctrl+shift+k -> delete that perticular line
*/

const int N = 55;
int a[N], ans[6], n, g[6];

int index(int val)
{
	int id = lower_bound(g + 1, g + 6, val) - g;
	if (id < 1 )
		return -1;
	else if (id > 5)
		return 5;

	if (g[id] == val)
		return id;
	else
		return id - 1;
}

void solve()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= 5; i++)
		cin >> g[i];
	for (int i = 1; i <= 5; i++)
		ans[i] = 0;
	int left = 0;
	for (int i = 1; i <= n; i++)
	{
		left += a[i];
		while (left >= g[1])
		{
			int id = index(left);
			if (id == -1)
				break;
			int use = left / g[id];
			ans[id] += use;
			left = left - (use * g[id]);
		}

	}

	for (int i = 1; i <= 5; i++)
		cout << ans[i] << " ";
	cout << "\n" << left;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>>t;

	while (t--)
		solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define fs first
#define sc second
int ABS(int a) {return max(a, -a);}
ll ABS(ll a) {return max(a, -a);}
double ABS(double a) {return max(a, -a);}

/*	ctrl+d -> us word ke saare occurences ko select karna and fir ek jagah type karke saari jagah change karna
	ctrl+shift+d -> us line ke duplicates banana just neeche
	ctrl+l -> ek line select karna
	ctrl+shift+m -> {ye do brackets ke beech ke saare content ko select karna}
	ctrl+shift+enter -> us line ke pehle line insert karna aur cursor inserted line pe le jaana
	ctrl+enter -> us line ke neeche line insert karna aur cursor ko use line pe le jaana
	ctrl+shift+k -> delete that perticular line
*/

const int N = 55;
int a[N], ans[6], n, g[6];

int index(int val)
{
	int id = lower_bound(g + 1, g + 6, val) - g;
	if (id < 1 )
		return -1;
	else if (id > 5)
		return 5;

	if (g[id] == val)
		return id;
	else
		return id - 1;
}

void solve()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= 5; i++)
		cin >> g[i];
	for (int i = 1; i <= 5; i++)
		ans[i] = 0;
	int left = 0;
	for (int i = 1; i <= n; i++)
	{
		left += a[i];
		while (left >= g[1])
		{
			int id = index(left);
			int use = left / g[id];
			ans[id] += use;
			left = left - (use * g[id]);
		}

	}

	for (int i = 1; i <= 5; i++)
		cout << ans[i] << " ";
	cout << "\n" << left;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>>t;

	while (t--)
		solve();

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include<iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <stack>
#include <memory.h>
#include <numeric>
#include <iostream>
#include<climits>
#include <stdio.h>
#include <stdlib.h>
//  vector<vector<int>> b(row_size, vector<int>(col_size,n));   //  n->initialized value
#define printtable(x);		for(int Q=0;Q<x.size();++Q){for (int P = 0; P < x[0].size(); ++P)cout << x[Q][P] <<'\t'; cout << '\n';}
#define MOD 1000000007LL
#define ff first
#define fs second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<long long>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define pii pair<int,int>
#define mii map<int, int>
#define mp make_pair
#define tc                int T;cin>>T;while(T--)
#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
using namespace std;
int main() {
//    unordered_set<int> p= { 1, 2, 4, 8 ,16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824 };
//    int n;cin>>n;
//    unordered_multiset<int> a;int b;
//    for(int i=0;i<n;++i){cin>>b;a.insert(b);}
//    int d=0;
//    for(const int& e:a){
//        fla
//        for(const int& c:p){
//            if(!(a.count(c-e)))++d;
//        }
//    }
//    cout <<d;
//    unsigned short
    int n;
    cin>>n;
    vector<int> points(n,0),cost(5),bought(5,0);
    for(int& e:points)cin>>e;
    for(int& e:cost)cin>>e;
    int runningsum=0;
    for(int i=0;i<n;++i){
        runningsum+=points[i];
        while(runningsum>=cost[0]){
            if(runningsum>=cost[4]){
                ++bought[4];
                runningsum-=cost[4];
            }
            else if(runningsum>=cost[3]){
                ++bought[3];
                runningsum-=cost[3];
            }
            else if(runningsum>=cost[2]){
                ++bought[2];
                runningsum-=cost[2];
            }else if(runningsum>=cost[1]){
                ++bought[1];
                runningsum-=cost[1];
            }
            else if(runningsum>=cost[0]){
                ++bought[0];
                runningsum-=cost[0];
            }
        }
    }
    for(int& e:bought)cout<<e<<' ';
    cout<<'\n';
    cout<<runningsum;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include<iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <stack>
#include <memory.h>
#include <numeric>
#include <iostream>
#include<climits>
#include <stdio.h>
#include <stdlib.h>
//  vector<vector<int>> b(row_size, vector<int>(col_size,n));   //  n->initialized value
#define printtable(x);		for(int Q=0;Q<x.size();++Q){for (int P = 0; P < x[0].size(); ++P)cout << x[Q][P] <<'\t'; cout << '\n';}
#define MOD 1000000007LL
#define ff first
#define fs second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<long long>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define pii pair<int,int>
#define mii map<int, int>
#define mp make_pair
#define tc                int T;cin>>T;while(T--)
#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
using namespace std;
int main() {
//    unordered_set<int> p= { 1, 2, 4, 8 ,16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824 };
//    int n;cin>>n;
//    unordered_multiset<int> a;int b;
//    for(int i=0;i<n;++i){cin>>b;a.insert(b);}
//    int d=0;
//    for(const int& e:a){
//        fla
//        for(const int& c:p){
//            if(!(a.count(c-e)))++d;
//        }
//    }
//    cout <<d;
//    unsigned short
    int n;
    cin>>n;
    vector<ll> points(n,0),cost(5),bought(5,0);
    for(ll& e:points)cin>>e;
    for(ll& e:cost)cin>>e;
    ll  runningsum=0;
    for(int i=0;i<n;++i){
        runningsum+=points[i];
        while(runningsum>=cost[0]){
            if(runningsum>=cost[4]){
                bought[4]+=(runningsum/cost[4]);
                runningsum-=(cost[4]*(runningsum/cost[4]));
            }
            else if(runningsum>=cost[3]){
                bought[3]+=(runningsum/cost[3]);
                runningsum-=(cost[3]*(runningsum/cost[3]));
            }
            else if(runningsum>=cost[2]){
                bought[2]+=(runningsum/cost[2]);
                runningsum-=(cost[2]*(runningsum/cost[2]));
            }else if(runningsum>=cost[1]){
                bought[1]+=(runningsum/cost[1]);
                runningsum-=(cost[1]*(runningsum/cost[1]));            }
            else if(runningsum>=cost[0]){
                bought[0]+=(runningsum/cost[0]);
                runningsum-=(cost[0]*(runningsum/cost[0]));
            }
        }
    }
    for(ll& e:bought)cout<<e<<' ';
    cout<<'\n';
    cout<<runningsum;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include<iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <stack>
#include <memory.h>
#include <numeric>
#include <iostream>
#include<climits>
#include <stdio.h>
#include <stdlib.h>
//  vector<vector<int>> b(row_size, vector<int>(col_size,n));   //  n->initialized value
#define printtable(x);		for(int Q=0;Q<x.size();++Q){for (int P = 0; P < x[0].size(); ++P)cout << x[Q][P] <<'\t'; cout << '\n';}
#define MOD 1000000007LL
#define ff first
#define fs second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<long long>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define pii pair<int,int>
#define mii map<int, int>
#define mp make_pair
#define tc                int T;cin>>T;while(T--)
#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
using namespace std;
int main() {
//    unordered_set<int> p= { 1, 2, 4, 8 ,16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824 };
//    int n;cin>>n;
//    unordered_multiset<int> a;int b;
//    for(int i=0;i<n;++i){cin>>b;a.insert(b);}
//    int d=0;
//    for(const int& e:a){
//        fla
//        for(const int& c:p){
//            if(!(a.count(c-e)))++d;
//        }
//    }
//    cout <<d;
//    unsigned short
    int n;
    cin>>n;
    vector<int> points(n,0),cost(5),bought(5,0);
    for(int& e:points)cin>>e;
    for(int& e:cost)cin>>e;
    ll  runningsum=0;
    for(int i=0;i<n;++i){
        runningsum+=points[i];
        while(runningsum>=cost[0]){
            if(runningsum>=cost[4]){
                bought[4]+=(runningsum/cost[4]);
                runningsum-=(cost[4]*(runningsum/cost[4]));
            }
            else if(runningsum>=cost[3]){
                bought[3]+=(runningsum/cost[3]);
                runningsum-=(cost[3]*(runningsum/cost[3]));
            }
            else if(runningsum>=cost[2]){
                bought[2]+=(runningsum/cost[2]);
                runningsum-=(cost[2]*(runningsum/cost[2]));
            }else if(runningsum>=cost[1]){
                bought[1]+=(runningsum/cost[1]);
                runningsum-=(cost[1]*(runningsum/cost[1]));            }
            else if(runningsum>=cost[0]){
                bought[0]+=(runningsum/cost[0]);
                runningsum-=(cost[0]*(runningsum/cost[0]));
            }
        }
    }
    for(int& e:bought)cout<<e<<' ';
    cout<<'\n';
    cout<<runningsum;
    return 0;
}


#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // y must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//write your code here
int n;
cin>>n;
vector<int> point(n);
for(int i=0;i<n;i++)
{
    cin>>point[i];
}
vector<int> price(5);
for(int i=0;i<5;i++)
{
    cin>>price[i];
}
int mug=0,towel=0,bag=0,bicycle=0,car=0,sum=0;

for(int i=0;i<n;i++)
{
    sum=point[i]+sum;
    while(sum>=price[0])
    {
        if(sum>=price[4])
    {
        sum=sum-price[4];
        //res=sum;
        car++;
    }
    else if(sum>=price[3] && sum < price[4])
    {
        sum=sum-price[3];
        //sum=res;
        bicycle++;
    }
    else if(sum>=price[2] && sum < price[3])
    {
        sum=sum-price[2];
        //sum=res;
        bag++;
    }
     else if(sum>=price[1] && sum < price[2])
    {
        sum=sum-price[1];
        //sum=res;
        towel++;
    }
     else if(sum>=price[0] && sum < price[1])
    {
        sum=sum-price[0];
        //sum=res;
        mug++;
    }
    }
}
cout<<mug<<" "<<towel<<" "<<bag<<" "<<bicycle<<" "<<car<<"\n"<<sum;
return 0;
}


#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // y must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//write your code here
int n;
cin>>n;
vector<int> point(n);
for(int i=0;i<n;i++)
{
    cin>>point[i];
}
vector<int> price(5);
for(int i=0;i<5;i++)
{
    cin>>price[i];
}
long long mug=0,towel=0,bag=0,bicycle=0,car=0,sum=0;

for(int i=0;i<n;i++)
{
    sum=point[i]+sum;

        if(sum>=price[4])
    {
         car=car+ sum/price[4];
        sum=sum%price[4];
        //res=sum;

    }
    if(sum>=price[3] && sum < price[4])
    {
        bicycle= bicycle + sum/price[3];
        sum=sum%price[3];
        //sum=res;

    }
    if(sum>=price[2] && sum < price[3])
    {
        bag= bag + sum/price[2];
        sum=sum%price[2];
        //sum=res;
        ;
    }
     if(sum>=price[1] && sum < price[2])
    {
         towel=towel + sum/price[1];
        sum=sum%price[1];
        //sum=res;

    }
     else if(sum>=price[0] && sum < price[1])
    {
        mug=mug + sum/price[0];
        sum=sum%price[0];
        //sum=res;

    }

}
cout<<mug<<" "<<towel<<" "<<bag<<" "<<bicycle<<" "<<car<<"\n"<<sum;
return 0;
}


#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // y must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//write your code here
int n;
cin>>n;
vector<int> point(n);
for(int i=0;i<n;i++)
{
    cin>>point[i];
}
vector<int> price(n);
for(int i=0;i<5;i++)
{
    cin>>price[i];
}
int mug=0,towel=0,bag=0,bicycle=0,car=0,sum=0;

for(int i=0;i<n;i++)
{
    sum=point[i]+sum;
    while(sum>=price[0])
    {
        if(sum>=price[4])
    {
        sum=sum-price[4];
        //res=sum;
        car++;
    }
    else if(sum>=price[3] && sum < price[4])
    {
        sum=sum-price[3];
        //sum=res;
        bicycle++;
    }
    else if(sum>=price[2] && sum < price[3])
    {
        sum=sum-price[2];
        //sum=res;
        bag++;
    }
     else if(sum>=price[1] && sum < price[2])
    {
        sum=sum-price[1];
        //sum=res;
        towel++;
    }
     else if(sum>=price[0] && sum < price[1])
    {
        sum=sum-price[0];
        //sum=res;
        mug++;
    }
    }
}
cout<<mug<<" "<<towel<<" "<<bag<<" "<<bicycle<<" "<<car<<"\n"<<sum;
return 0;
}


#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // y must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//write your code here
int n;
cin>>n;
vector<int> point(n);
for(int i=0;i<n;i++)
{
    cin>>point[i];
}
vector<int> price(5);
for(int i=0;i<5;i++)
{
    cin>>price[i];
}
long long mug=0,towel=0,bag=0,bicycle=0,car=0,sum=0;

for(int i=0;i<n;i++)
{
    sum=point[i]+sum;

        if(sum>=price[4])
    {
         car=car+ sum/price[4];
        sum=sum%price[4];
        //res=sum;

    }
    if(sum>=price[3] && sum < price[4])
    {
        bicycle= bicycle + sum/price[3];
        sum=sum%price[3];
        //sum=res;

    }
    if(sum>=price[2] && sum < price[3])
    {
        bag= bag + sum/price[2];
        sum=sum%price[2];
        //sum=res;
        ;
    }
     if(sum>=price[1] && sum < price[2])
    {
         towel=towel + sum/price[1];
        sum=sum%price[1];
        //sum=res;

    }
     if(sum>=price[0] && sum < price[1])
    {
        mug=mug + sum/price[0];
        sum=sum%price[0];
        //sum=res;

    }

}
cout<<mug<<" "<<towel<<" "<<bag<<" "<<bicycle<<" "<<car<<"\n"<<sum;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	int a[100], b[10], c[10];
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; i < 5; i++) scanf("%d", &b[i]);
	__int64 tot = 0;
	memset(c, 0, sizeof c);
	for(int i = 0; i < n; i++){
		tot += a[i];
		for(int j = 4; j >= 0; j--){
			if(tot >= b[j]){
				c[j] += (tot / b[j]);
				tot %= b[j];
			}
		}
	}
	for(int i = 0; i < 5; i++){
		if(i) printf(" ");
		printf("%d", c[i]);
	}
	printf("\n%d\n", tot);
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first

using namespace std;
using INT=long long;
using VI=vector<int>;
using pii=pair<int, int>;
template<typename A, typename B> void smin(A &a, const B &b) {if(a>b) a=b;}
template<typename A, typename B> void smax(A &a, const B &b) {if(a<b) a=b;}

int a[6], p[55];
INT ans[6];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", p+i);
	for(int i=1; i<=5; i++) scanf("%d", a+i);

	INT sum=0;
	for(int i=1; i<=n; i++) {
		sum+=p[i];
		for(int j=6; --j; ) {
			ans[j]+=sum/a[j];
			sum%=a[j];
		}
	}
	for(int i=1; i<=5; i++) printf("%I64d ", ans[i]);
	printf("\n%I64d", sum);
}


#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	int a[100], b[10];
	__int64 c[10];
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; i < 5; i++) scanf("%d", &b[i]);
	__int64 tot = 0;
	memset(c, 0, sizeof c);
	for(int i = 0; i < n; i++){
		tot += a[i];
		for(int j = 4; j >= 0; j--){
			if(tot >= b[j]){
				c[j] += (tot / b[j]);
				tot %= b[j];
			}
		}
	}
	for(int i = 0; i < 5; i++){
		if(i) printf(" ");
		printf("%I64d", c[i]);
	}
	printf("\n%I64d\n", tot);
}


#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	int a[100], b[10], c[10];
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; i < 5; i++) scanf("%d", &b[i]);
	int tot = 0;
	memset(c, 0, sizeof c);
	for(int i = 0; i < n; i++){
		tot += a[i];
		for(int j = 4; j >= 0; j--){
			if(tot >= b[j]){
				c[j] += (tot / b[j]);
				tot %= b[j];
			}
		}
	}
	for(int i = 0; i < 5; i++){
		if(i) printf(" ");
		printf("%d", c[i]);
	}
	printf("\n%d\n", tot);
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
typedef double DO;
typedef long long INT;
typedef pair<int,int> pii;
typedef pair<pii,int> pi3;
template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}
int power(int a,int b,int mod,int ans=1){
	for(;b;b>>=1,a=1LL*a*a%mod) if(b&1) ans=1LL*ans*a%mod;
	return ans;
}
int a[1001],b[10];
INT ans[10];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=5;i++) scanf("%d",b+i);
	INT s=0;
	for(int i=1;i<=n;i++){
		a[i]+=a[i-1];
		for(int j=5;j;j--){
			int N=a[i]/b[j];
			ans[j]+=N;
			a[i]-=N*b[j];
		}
	}
	for(int i=1;i<=5;i++) cout<<ans[i]<<' ';
	cout<<endl;
	cout<<a[n]<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define NN 60

using namespace std;
using INT=long long ;
typedef pair<int, int>pii;

int co[NN];
int a[10];
INT cnt[10];
pii p[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)cin>>co[i];
	for(int i=0; i<5; i++)cin>>a[i];
	for(int i=0; i<5; i++)p[i]=pii(a[i], i);
	sort(p, p+5);

	INT ans=0;
	for(int i=1; i<=n; i++){
		ans+=co[i];
		for(int j=4; j>=0; j--){
			int c=p[j].first;
			if(ans>=c){
				INT t=ans/c;
				cnt[p[j].second]+=t;
				ans-=c*t;
			}
		}
	}
	for(int i=0; i<5; i++)cout<<cnt[i]<<" ";
	cout<<endl;
	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))

ll mod = 1000000007;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	ll a,b,c,d,e,ca=0,cb=0,cc=0,cd=0,ce=0;
	cin>>a>>b>>c>>d>>e;

	ll cur = 0;
	for(int i=0;i<n;i++){
		cur += arr[i];
		if(cur>=e){
			ce += cur/e;
			cur = cur%e;
		}
		if(cur>=d){
			cd += cur/d;
			cur = cur%d;
		}
		if(cur>=c){
			cc += cur/c;
			cur = cur%c;
		}
		if(cur>=b){
			cb += cur/b;
			cur = cur%b;
		}
		if(cur>=a){
			ca += cur/a;
			cur = cur%a;
		}
	}
	cout<<ca<<" "<<cb<<" "<<cc<<" "<<cd<<" "<<ce<<endl;
	cout<<cur<<endl;
	return 0;
}

//-------------------------//


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))

ll mod = 1000000007;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int a,b,c,d,e,ca=0,cb=0,cc=0,cd=0,ce=0;
	cin>>a>>b>>c>>d>>e;

	int cur = 0;
	for(int i=0;i<n;i++){
		cur += arr[i];
		if(cur>=e){ce++;cur-=e;}
		else if(cur>=d){cd++;cur-=d;}
		else if(cur>=c){cc++;cur-=c;}
		else if(cur>=b){cb++;cur-=b;}
		else if(cur>=a){ca++;cur-=a;}
	}
	cout<<ca<<" "<<cb<<" "<<cc<<" "<<cd<<" "<<ce<<endl;
	return 0;
}

//-------------------------//


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))

ll mod = 1000000007;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int a,b,c,d,e,ca=0,cb=0,cc=0,cd=0,ce=0;
	cin>>a>>b>>c>>d>>e;

	int cur = 0;
	for(int i=0;i<n;i++){
		cur += arr[i];
		while(cur>=a){
			if(cur>=e){ce++;cur-=e;}
			else if(cur>=d){cd++;cur-=d;}
			else if(cur>=c){cc++;cur-=c;}
			else if(cur>=b){cb++;cur-=b;}
			else if(cur>=a){ca++;cur-=a;}
		}
	}
	cout<<ca<<" "<<cb<<" "<<cc<<" "<<cd<<" "<<ce<<endl;
	cout<<cur<<endl;
	return 0;
}

//-------------------------//


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))

ll mod = 1000000007;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	ll a,b,c,d,e,ca=0,cb=0,cc=0,cd=0,ce=0;
	cin>>a>>b>>c>>d>>e;

	ll cur = 0;
	for(int i=0;i<n;i++){
		cur += arr[i];
		while(cur>=a){
			if(cur>=e){ce++;cur-=e;}
			else if(cur>=d){cd++;cur-=d;}
			else if(cur>=c){cc++;cur-=c;}
			else if(cur>=b){cb++;cur-=b;}
			else if(cur>=a){ca++;cur-=a;}
		}
	}
	cout<<ca<<" "<<cb<<" "<<cc<<" "<<cd<<" "<<ce<<endl;
	cout<<cur<<endl;
	return 0;
}

//-------------------------//


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
using namespace std;

int main()
{
    ll arr[5];
    int n;
    cin>>n;
    ll p[n];
    for(int i=0; i<n; i++) cin>>p[i];
    for(int i=0; i<5; i++) cin>>arr[i];
    sort(arr, arr+5);

    ll now = 0;
    int cnt[5] = {0};
    for(int i=0; i<n; i++)
    {
        now += p[i];
        for(int j=4; now>0 and j>=0; j--)
        {
            cnt[j] += now/arr[j];
            now -= (now/arr[j])*arr[j];
        }
    }
    for(int i=0; i<5; i++)
        cout<<cnt[i]<<" ";
    cout<<endl<<now<<endl;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
using namespace std;

int main()
{
    ll arr[5];
    int n;
    cin>>n;
    ll p[n];
    for(int i=0; i<n; i++) cin>>p[i];
    for(int i=0; i<5; i++) cin>>arr[i];
    sort(arr, arr+5);

    ll now = 0;
    ll cnt[5] = {0};
    for(int i=0; i<n; i++)
    {
        now += p[i];
        for(int j=4; now>0 and j>=0; j--)
        {
            cnt[j] += now/arr[j];
            now -= (now/arr[j])*arr[j];
        }
    }
    for(int i=0; i<5; i++)
        cout<<cnt[i]<<" ";
    cout<<endl<<now<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
using namespace std;

int main()
{
    int tc;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        int n; cin>>n;
        ll c[n];
        for(int i=0; i<n; i++)
            cin>>c[i];
        ll p[5];
        for(int i=0; i<5; i++) cin>>p[i];
        ll cnt[5] = {0};
        ll cur = 0;
        for(int i=0; i<n; i++)
        {
            cur += c[i];
            if(cur >= p[0])
            {
                for(int i=4; i>=0; i--)
                {
                    while(cur >= p[i])
                    {
                        cur -= p[i];
                        cnt[i]++;
                    }
                }
            }
        }
        for(int i=0; i<5; i++) cout<<cnt[i]<<" ";
        cout<<endl;
        cout<<cur<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
using namespace std;

int main()
{
    int tc;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        int n; cin>>n;
        ll c[n];
        for(int i=0; i<n; i++)
            cin>>c[i];
        ll p[5];
        for(int i=0; i<5; i++) cin>>p[i];
        ll cnt[5] = {0};
        ll cur = 0;
        for(int i=0; i<n; i++)
        {
            cur += c[i];
            if(cur >= p[0])
            {
                for(int i=4; i>=0; i--)
                {
                    if(cur >= p[i])
                    {
                        cnt[i] += cur/p[i];
                        cur = cur - (cur/p[i])*p[i];
                    }
                }
            }
        }
        for(int i=0; i<5; i++) cout<<cnt[i]<<" ";
        cout<<endl;
        cout<<cur<<endl;
    }
    return 0;
}


//I know that new situations can be intimidating. You're lookin’ around and it’s all scary and different,
//but y’know … meeting them head-on, charging into ‘em like a bull —
//that’s how we grow as coders.

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define b(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 200001
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll n;
    cin>>n;
    map<ll,ll,greater<ll>> map;
    vl p(n), prize(5), cnt(5,0);
    f(i,0,n) cin>>p[i];
    f(i,0,5){
        cin>>prize[i];
        map.insert({prize[i],i});
    }
    ll curr=0;
    f(i,0,n){
        curr += p[i];
        for(auto j:map){
            while(curr>0 && curr >= j.F){
                curr -= j.F;
                cnt[j.S]++;
            }
        }
    }
    f(i,0,5) cout<<cnt[i]<<" ";
    cout<<endl<<curr;

    return 0;
}


//I know that new situations can be intimidating. You're lookin’ around and it’s all scary and different,
//but y’know … meeting them head-on, charging into ‘em like a bull —
//that’s how we grow as coders.

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define b(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 200001
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll n;
    cin>>n;
    map<ll,ll,greater<ll>> map;
    vl p(n), prize(5), cnt(5,0);
    f(i,0,n) cin>>p[i];
    f(i,0,5){
        cin>>prize[i];
        map.insert({prize[i],i});
    }
    ll curr=0;
    f(i,0,n){
        curr += p[i];
        for(auto j:map){
            if(curr>0 && curr >= j.F){
                ll quo = (curr/j.F);
                curr -= (quo*j.F);
                cnt[j.S]+=quo;
            }
        }
    }
    f(i,0,5) cout<<cnt[i]<<" ";
    cout<<endl<<curr;

    return 0;
}


//I know that new situations can be intimidating. You're lookin’ around and it’s all scary and different,
//but y’know … meeting them head-on, charging into ‘em like a bull —
//that’s how we grow as coders.

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define b(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 200001
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll n;
    cin>>n;
    map<ll,ll,greater<ll>> map;
    vl p(n), prize(5), cnt(5,0);
    f(i,0,n) cin>>p[i];
    f(i,0,5){
        cin>>prize[i];
        map.insert({prize[i],i});
    }
    ll curr=0;
    f(i,0,n){
        curr += p[i];
        for(auto j:map){
            if(curr>0 && curr >= j.F){
                ll quo = (curr/(j.F));
                curr -= (quo*(j.F));
                cnt[j.S]+=quo;
            }
        }
    }
    f(i,0,5) cout<<cnt[i]<<" ";
    cout<<endl<<curr;

    return 0;
}


//		    Su Saheb?

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n ; i++)
	cin >> arr[i];

    ll cost[5];
    for(int i = 0 ; i < 5 ; i++)
	cin >> cost[i];

    ll ans[5] = {0};
    ll bal = 0;

    for(int i = 0 ; i < n ; i++)
    {
	bal += arr[i];
	for(int j = 4 ; j >= 0 ; j--)
	{
	    ll temp = (bal/cost[j]);
	    ans[j] += temp;
	    bal -= (temp*cost[j]);
	}
    }

    for(int i = 0 ; i < 5 ; i++)
	cout << ans[i] << " ";

    cout << endl << bal << endl;

    return 0;
}


//		    Su Saheb?

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n ; i++)
	cin >> arr[i];

    ll cost[5];
    for(int i = 0 ; i < 5 ; i++)
	cin >> cost[i];

    ll ans[5] = {0};
    ll bal = 0;

    for(int i = 0 ; i < n ; i++)
    {
	bal += arr[i];
	while(bal >= cost[0])
	{
	    for(int j = 5 ; j >= 0 ; j--)
	    {
		if(bal >= cost[j])
		{
		    bal -= cost[j];
		    ans[j]++;
		    break;
		}
	    }
	}
    }

    for(int i = 0 ; i < 5 ; i++)
	cout << ans[i] << " ";

    cout << endl << bal << endl;

    return 0;
}


//		    Su Saheb?

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n ; i++)
	cin >> arr[i];

    ll cost[5];
    for(int i = 0 ; i < 5 ; i++)
	cin >> cost[i];

    ll ans[5] = {0};
    ll bal = 0;

    for(int i = 0 ; i < n ; i++)
    {
	bal += arr[i];
	for(int j = 5 ; j >= 0 ; j--)
	{
	    ll temp = (bal/cost[j]);
	    ans[j] += temp;
	    bal -= (temp*cost[j]);
	}
    }

    for(int i = 0 ; i < 5 ; i++)
	cout << ans[i] << " ";

    cout << endl << bal << endl;

    return 0;
}


/*
	███╗   ███╗ █████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗██████╗ ███████╗ █████╗ ███╗   ███╗██████╗ ██╗   ██╗
	████╗ ████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║   ██║██╔══██╗╚════██║██╔══██╗████╗ ████║██╔══██╗╚██╗ ██╔╝
	██╔████╔██║███████║    ██╔╝██╔████╔██║██║   ██║██║   ██║██║  ██║    ██╔╝███████║██╔████╔██║██║  ██║ ╚████╔╝
	██║╚██╔╝██║██╔══██║   ██╔╝ ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║   ██╔╝ ██╔══██║██║╚██╔╝██║██║  ██║  ╚██╔╝
	██║ ╚═╝ ██║██║  ██║   ██║  ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║  ██║  ██║██║ ╚═╝ ██║██████╔╝   ██║
	╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝  ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝    ╚═╝

			“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define SZ(v) ((int)((v).size()))
#define clr(arr,x) memset(arr,x,sizeof arr)
#define endl "\n"
#define un_map unordered_map
#define wait system("pause>nul");
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scll(x)	scanf("%I64d", &x)
#define scll2(x,y) scanf("%I64d %I64d", &x, &y)
#define scll3(x,y,z) scanf("%I64d %I64d %I64d", &x, &y, &z)
#define scans(s) scanf("%[^\n]%*c", &s)
#define prs(s) printf("%s", s.c_str()); //print string
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
const double PI = acos(-1.0);
void Open() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	Ma7moud_7amdy;
	Open_Sesame;
	int n;
	cin >> n;
	vector<int>v(n);
	for (int& i : v)
		cin >> i;
	vector<pair<int, int>>a(5);
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i].first;
		a[i].second = i ;
	}
	sort(allr(a));
	vector<int>buy(5);
	for (int i = 0; i < n; i++)
	{
		while (v[i] >= a[4].first)
		{
			for (int j = 0; j < 5; j++)
			{
				while (v[i] >= a[j].first)
				{
					v[i] -= a[j].first;
					buy[a[j].second]++;
				}
			}
		}
		if (i != n - 1)
			v[i + 1] += v[i], v[i] = 0;
	}

	cout << buy[0];
	for (int i = 1; i < 5; i++)
		cout << " " << buy[i];
	cout << endl << v[n - 1];
}


/*
	███╗   ███╗ █████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗██████╗ ███████╗ █████╗ ███╗   ███╗██████╗ ██╗   ██╗
	████╗ ████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║   ██║██╔══██╗╚════██║██╔══██╗████╗ ████║██╔══██╗╚██╗ ██╔╝
	██╔████╔██║███████║    ██╔╝██╔████╔██║██║   ██║██║   ██║██║  ██║    ██╔╝███████║██╔████╔██║██║  ██║ ╚████╔╝
	██║╚██╔╝██║██╔══██║   ██╔╝ ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║   ██╔╝ ██╔══██║██║╚██╔╝██║██║  ██║  ╚██╔╝
	██║ ╚═╝ ██║██║  ██║   ██║  ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║  ██║  ██║██║ ╚═╝ ██║██████╔╝   ██║
	╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝  ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝    ╚═╝

			“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define SZ(v) ((int)((v).size()))
#define clr(arr,x) memset(arr,x,sizeof arr)
#define endl "\n"
#define un_map unordered_map
#define wait system("pause>nul");
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scll(x)	scanf("%I64d", &x)
#define scll2(x,y) scanf("%I64d %I64d", &x, &y)
#define scll3(x,y,z) scanf("%I64d %I64d %I64d", &x, &y, &z)
#define scans(s) scanf("%[^\n]%*c", &s)
#define prs(s) printf("%s", s.c_str()); //print string
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
const double PI = acos(-1.0);
void Open() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	Ma7moud_7amdy;
	Open_Sesame;
	int n;
//	cin >> n;
	scanf("%d", &n);
	vector<int>v(n);
	for (int& i : v)
		scanf("%d", &i);
		//cin >> i;
	vector<pair<int, int>>a(5);
	for (int i = 0; i < 5; i++)
	{
	//	cin >> a[i].first;
		scanf("%d", &a[i].first);
		a[i].second = i ;
	}
	sort(allr(a));
	vector<int>buy(5);
	for (int i = 0; i < n; i++)
	{
		while (v[i] >= a[4].first)
		{
			for (int j = 0; j < 5; j++)
			{
				if (v[i] >= a[j].first)
				{
					buy[a[j].second] += (v[i] / a[j].first);
					v[i] = v[i] % a[j].first;
				}
			}
		}
		if (i != n - 1)
			v[i + 1] += v[i], v[i] = 0;
	}

	//cout << buy[0];
	printf("%d", buy[0]);
	for (int i = 1; i < 5; i++)
		printf(" %d", buy[i]);
	//	cout << " " << buy[i];
	//cout << endl << v[n - 1];
	printf("\n%d", v[n - 1]);
}


/*
	███╗   ███╗ █████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗██████╗ ███████╗ █████╗ ███╗   ███╗██████╗ ██╗   ██╗
	████╗ ████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║   ██║██╔══██╗╚════██║██╔══██╗████╗ ████║██╔══██╗╚██╗ ██╔╝
	██╔████╔██║███████║    ██╔╝██╔████╔██║██║   ██║██║   ██║██║  ██║    ██╔╝███████║██╔████╔██║██║  ██║ ╚████╔╝
	██║╚██╔╝██║██╔══██║   ██╔╝ ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║   ██╔╝ ██╔══██║██║╚██╔╝██║██║  ██║  ╚██╔╝
	██║ ╚═╝ ██║██║  ██║   ██║  ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║  ██║  ██║██║ ╚═╝ ██║██████╔╝   ██║
	╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝  ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝    ╚═╝

			“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define SZ(v) ((int)((v).size()))
#define clr(arr,x) memset(arr,x,sizeof arr)
#define endl "\n"
#define un_map unordered_map
#define wait system("pause>nul");
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scll(x)	scanf("%I64d", &x)
#define scll2(x,y) scanf("%I64d %I64d", &x, &y)
#define scll3(x,y,z) scanf("%I64d %I64d %I64d", &x, &y, &z)
#define scans(s) scanf("%[^\n]%*c", &s)
#define prs(s) printf("%s", s.c_str()); //print string
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
const double PI = acos(-1.0);
void Open() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	Ma7moud_7amdy;
	Open_Sesame;
	int n;
//	cin >> n;
	scanf("%d", &n);
	vector<int>v(n);
	for (int& i : v)
		scanf("%d", &i);
		//cin >> i;
	vector<pair<int, int>>a(5);
	for (int i = 0; i < 5; i++)
	{
	//	cin >> a[i].first;
		scanf("%d", &a[i].first);
		a[i].second = i ;
	}
	sort(allr(a));
	vector<ll>buy(5);
	for (int i = 0; i < n; i++)
	{
		while (v[i] >= a[4].first)
		{
			for (int j = 0; j < 5; j++)
			{
				if (v[i] >= a[j].first)
				{
					buy[a[j].second] += (v[i] / a[j].first);
					v[i] = v[i] % a[j].first;
				}
			}
		}
		if (i != n - 1)
			v[i + 1] += v[i], v[i] = 0;
	}

	//cout << buy[0];
	printf("%d", buy[0]);
	for (int i = 1; i < 5; i++)
		printf(" %d", buy[i]);
	//	cout << " " << buy[i];
	//cout << endl << v[n - 1];
	printf("\n%d", v[n - 1]);
}


/*
	███╗   ███╗ █████╗ ███████╗███╗   ███╗ ██████╗ ██╗   ██╗██████╗ ███████╗ █████╗ ███╗   ███╗██████╗ ██╗   ██╗
	████╗ ████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║   ██║██╔══██╗╚════██║██╔══██╗████╗ ████║██╔══██╗╚██╗ ██╔╝
	██╔████╔██║███████║    ██╔╝██╔████╔██║██║   ██║██║   ██║██║  ██║    ██╔╝███████║██╔████╔██║██║  ██║ ╚████╔╝
	██║╚██╔╝██║██╔══██║   ██╔╝ ██║╚██╔╝██║██║   ██║██║   ██║██║  ██║   ██╔╝ ██╔══██║██║╚██╔╝██║██║  ██║  ╚██╔╝
	██║ ╚═╝ ██║██║  ██║   ██║  ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║  ██║  ██║██║ ╚═╝ ██║██████╔╝   ██║
	╚═╝     ╚═╝╚═╝  ╚═╝   ╚═╝  ╚═╝     ╚═╝ ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝    ╚═╝

			“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define SZ(v) ((int)((v).size()))
#define clr(arr,x) memset(arr,x,sizeof arr)
#define endl "\n"
#define un_map unordered_map
#define wait system("pause>nul");
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scll(x)	scanf("%I64d", &x)
#define scll2(x,y) scanf("%I64d %I64d", &x, &y)
#define scll3(x,y,z) scanf("%I64d %I64d %I64d", &x, &y, &z)
#define scans(s) scanf("%[^\n]%*c", &s)
#define prs(s) printf("%s", s.c_str()); //print string
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
const double PI = acos(-1.0);
void Open() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	Ma7moud_7amdy;
	Open_Sesame;
	int n;
//	cin >> n;
	scanf("%d", &n);
	vector<int>v(n);
	for (int& i : v)
		scanf("%d", &i);
		//cin >> i;
	vector<pair<int, int>>a(5);
	for (int i = 0; i < 5; i++)
	{
	//	cin >> a[i].first;
		scanf("%d", &a[i].first);
		a[i].second = i ;
	}
	sort(allr(a));
	vector<ll>buy(5);
	for (int i = 0; i < n; i++)
	{
		while (v[i] >= a[4].first)
		{
			for (int j = 0; j < 5; j++)
			{
				if (v[i] >= a[j].first)
				{
					buy[a[j].second] += (v[i] / a[j].first);
					v[i] = v[i] % a[j].first;
				}
			}
		}
		if (i != n - 1)
			v[i + 1] += v[i], v[i] = 0;
	}

	//cout << buy[0];
	printf("%d", buy[0]);
	for (int i = 1; i < 5; i++)
		printf(" %I64d", buy[i]);
	//	cout << " " << buy[i];
	//cout << endl << v[n - 1];
	printf("\n%d", v[n - 1]);
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    ll n;
    cin>>n;
    vector<ll>a(n);
    ll priz[5]={},ans[5]={};
    loop(i,0,n) cin>>a[i];
    loop(i,0,5) cin>>priz[i];

    ll sum = 0;
    loop(i,0,n)
    {
        sum += a[i];
        for(int j=4;j>=0;j--)
        {
            ll xx = sum/priz[j];
            sum -= xx*priz[j];
            ans[j] += xx;
        }
    }

    loop(j,0,5)
        cout<<ans[j],sp;
    nl;
    cout<<sum,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    ll n;
    cin>>n;
    vector<int>a(n);
    int priz[5]={},ans[5]={};
    loop(i,0,n) cin>>a[i];
    loop(i,0,5) cin>>priz[i];

    ll sum = 0;
    loop(i,0,n)
    {
        sum += a[i];
        for(int j=4;j>=0;j--)
        {
            int xx = sum/priz[j];
            sum -= xx*priz[j];
            ans[j] += xx;
        }
    }

    loop(j,0,5)
        cout<<ans[j],sp;
    nl;
    cout<<sum,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    int n;
    cin>>n;
    vector<ll>p(n);
    for(int i=0;i<n;i++) cin>>p[i];

    ll buy[5], fr[5]={};
    for(int i=0;i<5;i++) cin>>buy[i];

    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        sum += p[i];
        for(int j=4;j>=0;j--)
        {
            ll num = sum/buy[j];
            fr[j] += num;
            sum -= num*buy[j];
        }
    }

    for(int i=0;i<5;i++)
        cout<<fr[i]<<" ";
    nl;
    cout<<sum,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    int n;
    cin>>n;
    vector<ll>p(n);
    for(int i=0;i<n;i++) cin>>p[i];

    int buy[5], fr[5]={};
    for(int i=0;i<5;i++) cin>>buy[i];

    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        sum += p[i];
        for(int j=4;j>=0;j--)
        {
            ll num = sum/buy[j];
            fr[j] += num;
            sum -= num*buy[j];
        }
    }

    for(int i=0;i<5;i++)
        cout<<fr[i]<<" ";
    nl;
    cout<<sum,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	int count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	int count[5] = { 0 };
	long long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	long long count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			int fact = sum / price[i];
			sum -= price[i]*fact;
			count[i] += fact;

		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	int count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i];
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	int count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i];
	cout <<endl<<sum;
	system("pause");

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long long price[5];
	int count[5] = { 0 };
	long long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	long count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	long long count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			while(sum >= price[j])
			{
				sum -= price[j];
				count[j]++;
			}
		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	long price[5];
	long long count[5] = { 0 };
	long temp,sum=0;
	vector<long> input;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		input.push_back(temp);
	}

	for (int i = 0; i < 5; i++)
		cin >> price[i];
	for(int i=0;i<n;i++)
	{
		sum += input[i];

		for (int j = 4; j >= 0; j--)
		{
			int fact = sum / price[j];
			sum -= price[j]*fact;
			count[j]+= fact;

		}

	}

	for (int i = 0; i < 5; i++)
		cout << count[i]<<" ";
	cout <<endl<<sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mxn 100005
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
int main(){
	int n; cin>>n;
	ll arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	ll ar[5],an[5];
	for(int i=0; i<5; i++){
		cin>>ar[i];
		an[i] = 0;
	}
	ll sum = 0;
    for(int i=0; i<n; i++){
    	sum += arr[i];
        while(true){
            ll count = 0;
            an[4] += sum/ar[4];
            sum -= ar[4]*(sum/ar[4]);
    	    for(int i=4; i>=0; i--){
                count++;
                 if(sum >= ar[i]){
                  	sum = sum - ar[i];
                	an[i]++;
                	break;
                }
    	    }
            if(count == 5) break;
        }
    }
    for(int i=0; i<5; i++){
    	cout<<an[i]<<" ";
    }
    cout<<endl;
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mxn 100005
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
int main(){
	int n; cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int ar[5],an[5];
	for(int i=0; i<5; i++){
		cin>>ar[i];
		an[i] = 0;
	}
	int sum = 0;
    for(int i=0; i<n; i++){
    	sum += arr[i];
        while(true){
            int count = 0;
            an[4] += sum/ar[4];
            sum -= ar[4]*(sum/ar[4]);
    	    for(int i=4; i>=0; i--){
                count++;
                 if(sum >= ar[i]){
                  	sum = sum - ar[i];
                	an[i]++;
                	break;
                }
    	    }
            if(count == 5) break;
        }
    }
    for(int i=0; i<5; i++){
    	cout<<an[i]<<" ";
    }
    cout<<endl;
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mxn 100005
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
int main(){
	int n; cin>>n;
	ll arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	ll ar[5],an[5];
	for(int i=0; i<5; i++){
		cin>>ar[i];
		an[i] = 0;
	}
	ll sum = 0;
    for(int i=0; i<n; i++){
    	    sum += arr[i];
    	    for(int i=4; i>=0; i--){
                 if(sum >= ar[i]){
                 	an[i] += sum/ar[i];
                  	sum = sum - ar[i]*(sum/ar[i]);
                }
    	    }
    }
    for(int i=0; i<5; i++){
    	cout<<an[i]<<" ";
    }
    cout<<endl;
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int a,b,c,d,e,n;
	cin>>n;
	long int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cin>>a>>b>>c>>d>>e;
	long int A=0,B=0,C=0,D=0,E=0,sum=0;

	for(int i=0;i<n;i++)
	{

		sum=sum+arr[i];
		while(sum>=a)
		{

			if(sum>e)
				{
					E+=sum/e;
					sum=sum%e;
				}

				if(sum>d)
				{
					D+=sum/d;
					sum=sum%d;
				}

				if(sum>c)
				{
					C+=sum/c;
					sum=sum%c;
				}

				if(sum>b)
				{
					B+=sum/b;
					sum=sum%b;
				}

				if(sum>a)
				{
					A+=sum/a;
					sum=sum%a;
				}

		}
	}

	cout<<A<<' '<<B<<' '<<C<<' '<<D<<' '<<E<<endl;
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long	long int a,b,c,d,e,n;
	cin>>n;
	long long int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cin>>a>>b>>c>>d>>e;
	long long  int A=0,B=0,C=0,D=0,E=0,sum=0;

	for(long int i=0;i<n;i++)
	{

		sum=sum+arr[i];

			if(sum>=e)
				{
					E+=sum/e;
					sum=sum%e;
				}

				if(sum>=d)
				{
					D+=sum/d;
					sum=sum%d;
				}

				if(sum>=c)
				{
					C+=sum/c;
					sum=sum%c;
				}

				if(sum>=b)
				{
					B+=sum/b;
					sum=sum%b;
				}

				if(sum>=a)
				{
					A+=sum/a;
					sum=sum%a;
				}

	}

	cout<<A<<' '<<B<<' '<<C<<' '<<D<<' '<<E<<endl;
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int a,b,c,d,e,n;
	cin>>n;
	long int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cin>>a>>b>>c>>d>>e;
	long int A=0,B=0,C=0,D=0,E=0,sum=0;

	for(int i=0;i<n;i++)
	{

		sum=sum+arr[i];

			if(sum>e)
				{
					E+=sum/e;
					sum=sum%e;
				}

				if(sum>d)
				{
					D+=sum/d;
					sum=sum%d;
				}

				if(sum>c)
				{
					C+=sum/c;
					sum=sum%c;
				}

				if(sum>b)
				{
					B+=sum/b;
					sum=sum%b;
				}

				if(sum>a)
				{
					A+=sum/a;
					sum=sum%a;
				}

	}

	cout<<A<<' '<<B<<' '<<C<<' '<<D<<' '<<E<<endl;
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int a,b,c,d,e,n;
	cin>>n;
	long int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cin>>a>>b>>c>>d>>e;
	long int A=0,B=0,C=0,D=0,E=0,sum=0;

	for(int i=0;i<n;i++)
	{

		sum=sum+arr[i];

			if(sum>=e)
				{
					E+=sum/e;
					sum=sum%e;
				}

				if(sum>=d)
				{
					D+=sum/d;
					sum=sum%d;
				}

				if(sum>=c)
				{
					C+=sum/c;
					sum=sum%c;
				}

				if(sum>=b)
				{
					B+=sum/b;
					sum=sum%b;
				}

				if(sum>=a)
				{
					A+=sum/a;
					sum=sum%a;
				}

	}

	cout<<A<<' '<<B<<' '<<C<<' '<<D<<' '<<E<<endl;
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
    cout << "[";
    for(auto &i: v) cout << i << ", ";
    cout << "]" << endl;
    return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
    os << "{" << p.first << ", " << p.second << "} ";
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int ans[5] = {0};
    int prices[5];
    for (int i = 0; i < 5; ++i)
        cin >> prices[i];
    int min_price = *min_element(prices, prices + n);
    int in_hand = 0;
    auto buy = [&]() {
        while (in_hand >= min_price) {
            int cur_max = 0;
            int idx = -1;
            for (int i = 0; i < 5; ++i) {
                if (prices[i] <= in_hand and prices[i] > cur_max) {
                    cur_max = prices[i];
                    idx = i;
                }
            }
            int can_buy = in_hand / cur_max;
            in_hand -= can_buy * cur_max;
            ans[idx] += can_buy;
        }
    };
    for (int i = 0; i < n; ++i) {
        in_hand += a[i];
        buy();
    }
    for (int i = 0; i < 5; ++i) cout << ans[i] << " ";
    cout << endl;
    cout << in_hand << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
    cout << "[";
    for(auto &i: v) cout << i << ", ";
    cout << "]" << endl;
    return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
    os << "{" << p.first << ", " << p.second << "} ";
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int ans[5] = {0};
    int prices[5];
    for (int i = 0; i < 5; ++i)
        cin >> prices[i];
    int min_price = *min_element(prices, prices + 5);
    int in_hand = 0;
    auto buy = [&]() {
        while (in_hand >= min_price) {
            int cur_max = 0;
            int idx = -1;
            for (int i = 0; i < 5; ++i) {
                if (prices[i] <= in_hand and prices[i] > cur_max) {
                    cur_max = prices[i];
                    idx = i;
                }
            }
            int can_buy = in_hand / cur_max;
            in_hand -= can_buy * cur_max;
            ans[idx] += can_buy;
        }
    };
    for (int i = 0; i < n; ++i) {
        in_hand += a[i];
        buy();
    }
    for (int i = 0; i < 5; ++i) cout << ans[i] << " ";
    cout << endl;
    cout << in_hand << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
    cout << "[";
    for(auto &i: v) cout << i << ", ";
    cout << "]" << endl;
    return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
    os << "{" << p.first << ", " << p.second << "} ";
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll ans[5] = {0};
    int prices[5];
    for (int i = 0; i < 5; ++i)
        cin >> prices[i];
    int min_price = *min_element(prices, prices + 5);
    int in_hand = 0;
    auto buy = [&]() {
        while (in_hand >= min_price) {
            int cur_max = 0;
            int idx = -1;
            for (int i = 0; i < 5; ++i) {
                if (prices[i] <= in_hand and prices[i] > cur_max) {
                    cur_max = prices[i];
                    idx = i;
                }
            }
            int can_buy = in_hand / cur_max;
            in_hand -= can_buy * cur_max;
            ans[idx] += can_buy;
        }
    };
    for (int i = 0; i < n; ++i) {
        in_hand += a[i];
        buy();
    }
    for (int i = 0; i < 5; ++i) cout << ans[i] << " ";
    cout << endl;
    cout << in_hand << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
    cout << "[";
    for(auto &i: v) cout << i << ", ";
    cout << "]" << endl;
    return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
    os << "{" << p.first << ", " << p.second << "} ";
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int ans[5] = {0};
    int prices[5];
    for (int i = 0; i < 5; ++i)
        cin >> prices[i];
    int min_price = *min_element(prices, prices + n);
    int in_hand = 0;
    auto buy = [&]() {
        while (in_hand >= min_price) {
            int cur_max = 0;
            int idx = -1;
            for (int i = 0; i < 5; ++i) {
                if (prices[i] <= in_hand and prices[i] > cur_max) {
                    cur_max = prices[i];
                    idx = i;
                }
            }
            in_hand -= cur_max;
            ans[idx]++;
        }
    };
    for (int i = 0; i < n; ++i) {
        in_hand += a[i];
        buy();
    }
    for (int i = 0; i < 5; ++i) cout << ans[i] << " ";
    cout << endl;
    cout << in_hand << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;

using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;

const int NN = 1005;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int n, k, m, s, x, a, b, c, d, e, q;
ll answww[NN], in[NN], aa[5];
#define MX(a,b)a>b?a:b
ll cur;
int main(){
	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &in[i]);
	scanf("%I64d %I64d %I64d %I64d %I64d", &aa[0], &aa[1], &aa[2], &aa[3], &aa[4]);
	for (int i = 0; i < n; i++){
		cur += in[i];
		for (int j = 4; j >= 0; j--){
			answww[j] += (cur / aa[j]);
			cur %= aa[j];
		}

	}
	for (int i = 0; i < 5; i++){
		printf("%I64d ", answww[i]);
	}
	printf("\n");
	printf("%I64d\n", cur);
	exit;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;

using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;

const int NN = 1005;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int n, k, m, s, x, a, b, c, d, e, q;
int answww[NN], in[NN], aa[5];
#define MX(a,b)a>b?a:b

int main(){
	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &in[i]);
	scanf("%d %d %d %d %d", &aa[0], &aa[1], &aa[2], &aa[3], &aa[4]);
	sort(aa, aa + 5);
	for (int i = 0; i < n; i++){
		for (int j = 4; j >= 0; j--){
			if (in[i] >= aa[j]){
				answww[j] += 1;
				in[i] -= aa[j];
				in[i + 1] += in[i];
			}
		}
	}
	int rem = in[n - 1];
	for (int i = 0; i < 5; i++){
		printf("%d ", answww[i]);
	}
	printf("\n");
	printf("%d", &rem);
	exit;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;

using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;

const int NN = 1005;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int n, k, m, s, x, a, b, c, d, e, q;
int answww[NN], in[NN], aa[5];
#define MX(a,b)a>b?a:b
int cur;
int main(){
	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &in[i]);
	scanf("%d %d %d %d %d", &aa[0], &aa[1], &aa[2], &aa[3], &aa[4]);
	for (int i = 0; i < n; i++){
		cur += in[i];
		for (int j = 4; j >= 0; j--){
			answww[j] += cur / aa[j];
			cur %= aa[j];
		}

	}
	for (int i = 0; i < 5; i++){
		printf("%d ", answww[i]);
	}
	printf("\n");
	printf("%d", cur);
	exit;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;

using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;

const int NN = 1005;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int n, k, m, s, x, a, b, c, d, e, q;
int answww[NN], in[NN], aa[5];
#define MX(a,b)a>b?a:b

int main(){
	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &in[i]);
	scanf("%d %d %d %d %d", &aa[0], &aa[1], &aa[2], &aa[3], &aa[4]);
	sort(aa, aa + 5);
	for (int i = 0; i < n; i++){
		for (int j = 4; j >= 0; j--){
			if (in[i] >= aa[j]){
				answww[j] += 1;
				in[i] -= aa[j];
				in[i + 1] += in[i];
			}
		}
	}
	int rem = in[n - 1];
	for (int i = 0; i < 5; i++){
		printf("%d ", answww[i]);
	}
	printf("\n");
	printf("%d", rem);
	exit;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;

using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;

const int NN = 1005;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int n, k, m, s, x, a, b, c, d, e, q;
ll answww[NN], in[NN], aa[5];
#define MX(a,b)a>b?a:b
ll cur;
int main(){
	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &in[i]);
	scanf("%I64d %I64d %I64d %I64d %I64d", &aa[0], &aa[1], &aa[2], &aa[3], &aa[4]);
	for (int i = 0; i < n; i++){
		cur += in[i];
		for (int j = 4; j >= 0; j--){
			answww[j] += cur / aa[j];
			cur %= aa[j];
		}

	}
	for (int i = 0; i < 5; i++){
		printf("%d ", answww[i]);
	}
	printf("\n");
	printf("%d", cur);
	exit;

}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define PB push_back
#define MP make_pair
const ll mod = (int)1e9 + 7;

int fin[5];
int cost[5];
int arr[100];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG_
		//freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}

	for(int i=0;i<5;i++){
		cin >> cost[i];
	}
	ll curr = 0;
	for(int i=0;i<n;i++){
		curr+=arr[i];
		for(int j=4;j>=0;j--){
			int a = curr/cost[j];
			curr-=cost[j]*a;
			fin[j]+=a;
		}
	}

	for (int i = 0; i < 5; ++i)
	{
		cout<<fin[i]<<" ";
	}
	cout<<"\n";
	cout<<curr<<"\n";
	return 0;

}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define PB push_back
#define MP make_pair
const ll mod = (int)1e9 + 7;

ll fin[5];
ll cost[5];
ll arr[100];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG_
		//freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	ll n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}

	for(int i=0;i<5;i++){
		cin >> cost[i];
	}
	ll curr = 0;
	for(int i=0;i<n;i++){
		curr+=arr[i];
		for(int j=4;j>=0;j--){
			int a = curr/cost[j];
			curr-=cost[j]*a;
			fin[j]+=a;
		}
	}

	for (int i = 0; i < 5; ++i)
	{
		cout<<fin[i]<<" ";
	}
	cout<<"\n";
	cout<<curr<<"\n";
	return 0;

}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define PB push_back
#define MP make_pair
const ll mod = (int)1e9 + 7;

int fin[5];
int cost[5];
int arr[100];

int find(ll curr){
	ll mi = mod;
	ll ind = -1;
	for(int i=0;i<5;i++){
	if(cost[i] <= curr){
		if(curr-cost[i] < mi){
			mi = curr-cost[i];
			ind = i;
		}
	}
	}
	return ind;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG_
		//freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}

	for(int i=0;i<5;i++){
		cin >> cost[i];
	}
	ll curr = 0;
	for(int i=0;i<n;i++){
		curr+=arr[i];
		while(find(curr) != -1){
			int x = find(curr);
			curr-=cost[x];
			fin[x]++;
		}
	}

	for (int i = 0; i < 5; ++i)
	{
		cout<<fin[i]<<" ";
	}
	cout<<"\n";
	cout<<curr<<"\n";
	return 0;

}