#include <bits/stdc++.h>
using namespace std;
int n, cur;
int main() {
  cin >> n;
  vector<long long> v(n);
  vector<long long> p(5);
  for (long long i = 0; i <= n - 1; i++) cin >> v[i];
  for (long long i = 0; i <= 4; i++) cin >> p[i];
  vector<long long> ans(5, 0);
  sort(p.begin(), p.end());
  cur = 0;
  for (int i = 0; i < n; i++) {
    cur += v[i];
    while (cur >= p[0]) {
      int id = lower_bound(p.begin(), p.end(), cur) - p.begin();
      if (p[id] > cur) id--;
      ans[id] += cur / p[id];
      cur %= p[id];
    }
  }
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
  cout << cur << endl;
  return 0;
}
