#include <bits/stdc++.h>
using namespace std;
int fx[] = {0, 0, 1, -1, -1, 1, -1, 1};
int fy[] = {1, -1, 0, 0, -1, 1, 1, -1};
vector<pair<long long, long long> > p;
long long ans[10];
int main() {
  long long n, arr[54], a;
  scanf("%lld%*c", &n);
  for (long long i = 0; i < n; i++) scanf("%lld%*c", &arr[i]);
  for (long long i = 0; i < 5; i++) {
    scanf("%lld%*c", &a);
    p.push_back({a, i});
  }
  sort(p.begin(), p.end(), greater<pair<int, int> >());
  long long val = 0;
  for (long long i = 0; i < n; i++) {
    val += arr[i];
    for (long long j = 0; j < 5; j++) {
      if (val >= p[j].first) {
        ans[p[j].second] += (val / p[j].first);
        val = val % p[j].first;
      }
    }
  }
  for (long long i = 0; i < 5; i++) printf("%lld ", ans[i]);
  printf("\n%lld\n", val);
}
