#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p[5];
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = 4; i >= 0; --i) cin >> p[i];
  int64_t res[] = {0, 0, 0, 0, 0};
  int64_t sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += v[i];
    for (int j = 0; j < 5; ++j) {
      res[j] += sum / p[j];
      sum %= p[j];
    }
  }
  for (int i = 4; i >= 0; --i) {
    if (i < 4) cout << ' ';
    cout << res[i];
  }
  cout << endl << sum << endl;
  return 0;
}
