#include <bits/stdc++.h>
using namespace std;
long long n, m, t, res[5], x, y, c, d, a[51];
bool f;
string s;
vector<pair<long long, long long> > item;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  for (long long i = 0; i < 5; ++i) {
    cin >> x;
    item.push_back({x, i});
  }
  sort(item.begin(), item.end());
  for (long long i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    while (a[i] >= item[0].first) {
      x = 0;
      while (x < 5 && item[x].first <= a[i]) ++x;
      y = a[i] / item[x - 1].first;
      a[i] -= (y * item[x - 1].first);
      res[item[x - 1].second] += y;
    }
  }
  for (long long i = 0; i < 5; ++i) cout << res[i] << " ";
  cout << endl;
  cout << a[n] << endl;
  return 0;
}
