#include <bits/stdc++.h>
using namespace std;
long long arr[5], brr[5];
long long func(long long taka) {
  long long i, n;
  n = 4LL;
  for (i = n; i >= 0; i--) {
    brr[i] += (taka / arr[i]);
    taka %= arr[i];
  }
  return taka;
}
int main() {
  long long i, j, k, l, n, m;
  scanf("%lld", &n);
  long long ara[n];
  memset(brr, 0, sizeof(brr));
  for (i = 0; i < n; i++) scanf("%lld", &ara[i]);
  for (i = 0; i <= 4; i++) scanf("%lld", &arr[i]);
  for (i = 0, m = 0; i < n; i++) {
    m = func(ara[i] + m);
  }
  for (i = 0; i <= 4; i++) {
    printf("%lld", brr[i]);
    printf(" ");
  }
  printf("\n");
  printf("%lld", m);
  printf("\n");
}
