#include <bits/stdc++.h>
struct compare {
  bool operator()(const int& l, const int& r) { return l > r; }
};
using namespace std;
priority_queue<int, vector<int>, compare> pq;
long long ans[5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long arr[n], c[5];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < 5; i++) cin >> c[i];
  long long tot = 0;
  for (int i = 0; i < n; i++) {
    tot += arr[i];
    if (tot < c[0]) continue;
    int itr = 0;
    while (itr < 5 && c[itr] <= tot) itr++;
    itr--;
    for (; itr >= 0; itr--) {
      ans[itr] += tot / c[itr];
      tot -= (tot / c[itr]) * c[itr];
    }
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << "\n";
  cout << tot << "\n";
}
