#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long bars[51];
  long long i, leftpoints = 0, curpoints = 0, maxprice = 0, priceno, j;
  for (i = 0; i < n; i++) {
    cin >> bars[i];
  }
  long long prizescost[5];
  for (i = 0; i < 5; i++) {
    cin >> prizescost[i];
  }
  sort(prizescost, prizescost + 5);
  int count;
  long long totalprizes[5] = {0};
  for (i = 0; i < n; i++) {
    curpoints = leftpoints + bars[i];
    leftpoints = curpoints;
    count = 1;
    while (count != 0) {
      count = 0;
      for (j = 0; j < 5; j++) {
        if (prizescost[j] <= leftpoints) {
          maxprice = prizescost[j];
          priceno = j;
          count++;
        }
      }
      if (count != 0) {
        totalprizes[priceno] += (leftpoints / maxprice);
        leftpoints -= maxprice * (leftpoints / maxprice);
      }
    }
  }
  for (i = 0; i < 5; i++) {
    cout << totalprizes[i] << " ";
  }
  cout << endl;
  cout << leftpoints;
}
