#include <bits/stdc++.h>
using namespace std;
long long total[51];
long long prizes[5];
long long bars[51];
int main() {
  int n;
  while (cin >> n) {
    for (int i = (0); i < (n); ++i) cin >> bars[i];
    for (int i = (0); i < (5); ++i) cin >> prizes[i];
    memset(total, 0, sizeof total);
    long long acc = 0;
    for (int i = (0); i < (n); ++i) {
      acc += bars[i];
      for (int j = 4; j >= 0; --j) {
        long long dv = acc / prizes[j];
        total[j] += dv;
        acc -= prizes[j] * dv;
      }
    }
    for (int i = (0); i < (5); ++i) {
      if (i) putchar(' ');
      cout << total[i];
    }
    cout << endl;
    cout << acc << endl;
  }
  return 0;
}
