#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[50], b[5], d = 0, c[5] = {0}, num, f = 1, s;
  cin >> num;
  for (int t = 0; t < num; t++) cin >> a[t];
  for (int q = 0; q < 5; q++) cin >> b[q];
  for (int i = 0; i < num; i++) {
    a[i] += d;
    f = 1;
    for (int j = 4; j > -1; j--) {
      if (a[i] >= b[j]) {
        s = (a[i] / b[j]);
        c[j] += s;
        d = a[i] % b[j];
        a[i] -= (b[j] * s);
        f = 0;
      }
    }
    if (f) d = a[i];
  }
  cout << c[0];
  for (int x = 1; x < 5; x++) cout << " " << c[x];
  cout << endl;
  cout << d;
  return 0;
}
