#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  vector<long long int> cost(5), arr(5), p(n);
  for (long long int i = 0; i < 5; i++) arr[i] = 0;
  for (long long int i = 0; i < n; i++) cin >> p[i];
  for (long long int i = 0; i < 5; i++) cin >> cost[i];
  long long int total = 0;
  for (long long int i = 0; i < n; i++) {
    total += p[i];
    while (total >= cost[0]) {
      auto l = upper_bound(cost.begin(), cost.end(), total);
      long long int ind = l - cost.begin() - 1;
      arr[ind] += (total / cost[ind]);
      total -= (cost[ind] * (total / cost[ind]));
    }
  }
  for (long long int i = 0; i < 5; i++) cout << arr[i] << " ";
  cout << "\n" << total << "\n";
  return 0;
}
