#include <bits/stdc++.h>
int main() {
  int n, v[64], x[5];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
  for (int i = 0; i < 5; ++i) scanf("%d", &x[i]);
  long long h = 0, f[5] = {0};
  for (int i = 0; i < n; ++i) {
    h += v[i];
    for (int j = 4; j >= 0; --j) {
      f[j] += h / x[j];
      h = h % x[j];
    }
  }
  printf("%lld", f[0]);
  for (int i = 1; i < 5; ++i) printf(" %lld", f[i]);
  printf("\n%lld", h);
  return 0;
}
