#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    long long v[5], c[5], A[n], s = 0, x;
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < 5; i++) {
      cin >> v[i];
      c[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      s += A[i];
      for (int i = 4; i >= 0; i--) {
        c[i] += s / v[i];
        s %= v[i];
      }
    }
    for (int i = 0; i < 5; i++) cout << c[i] << " ";
    cout << "\n";
    cout << s << endl;
  }
  return 0;
}
