#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 100500;
const int maxn = 100500;
long long cur = 0;
vector<pair<long long, int> > a;
long long p[maxn];
long long res[10];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++) cin >> p[i];
  a.resize(5);
  for (int i = 0; i < (int)(5); i++) cin >> a[i].first, a[i].second = i;
  sort(a.begin(), a.end(), greater<pair<long long, int> >());
  for (int i = 0; i < (int)(n); i++) {
    cur += p[i];
    for (int j = 0; j < (int)(5); j++) {
      res[a[j].second] += cur / a[j].first;
      cur %= a[j].first;
    }
  }
  for (int i = 0; i < (int)(5); i++) cout << res[i] << " ";
  cout << endl << cur << endl;
  return 0;
}
