#include <bits/stdc++.h>
long long in[50];
int main() {
  int c[5];
  int n;
  long long ans[5] = {0};
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%I64d", &in[i]);
  for (int i = 0; i < 5; ++i) scanf("%d", &c[i]);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += in[i];
    for (int p = 4; p >= 0; --p) {
      ans[p] += sum / c[p];
      sum %= c[p];
    }
  }
  for (int i = 0; i < 5; ++i) printf("%I64d%c", ans[i], i == 4 ? '\n' : ' ');
  printf("%I64d\n", sum);
  return 0;
}
