#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<long long int> cost(5);
  for (int i = 0; i < 5; ++i) cin >> cost[i];
  long long int second = 0;
  vector<long long int> ans(5, 0);
  for (int i = 0; i < n; ++i) {
    second += a[i];
    for (int j = 4; j >= 0; --j) {
      if (second >= cost[j]) {
        long long int quantity = second / cost[j];
        ans[j] += quantity;
        second -= cost[j] * quantity;
      }
    }
  }
  for (int i = 0; i < 5; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
  cout << second << endl;
  return 0;
}
